:root {
  --ink: #26342e;
  --muted: #748078;
  --paper: #f5f3ec;
  --panel: #fffefa;
  --line: #d8d8cc;
  --green: #314d40;
  --green-soft: #e6ece6;
  --accent: #b58a46;
  --red: #a94f47;
  --shadow: 0 14px 45px rgba(29, 42, 34, .16);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(181, 138, 70, .35); outline-offset: 2px; }
[hidden] { display: none !important; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.app-header { position: fixed; inset: 0 0 auto; z-index: 40; background: rgba(255, 254, 250, .97); border-bottom: 1px solid var(--line); box-shadow: 0 2px 12px rgba(38, 52, 46, .05); }
.main-bar { min-height: 72px; display: flex; align-items: center; gap: 24px; padding: 10px 22px; }
.brand { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: var(--green); background: var(--green-soft); }
.brand-mark svg { width: 21px; height: 21px; stroke-width: 1.3; }
.brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 20px; font-weight: 500; letter-spacing: .01em; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.search-wrap { position: relative; width: min(520px, 45vw); margin: 0 auto; }
.search-wrap input { width: 100%; height: 44px; padding: 0 42px; border: 1px solid #d3d6cc; border-radius: 10px; color: var(--ink); background: #f8f8f3; transition: border-color .2s, background .2s; }
.search-wrap input:focus { border-color: #879b8d; background: #fff; outline: 3px solid rgba(49, 77, 64, .08); }
.search-wrap input::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: 14px; top: 12px; color: #6e7a72; pointer-events: none; }
.clear-search { position: absolute; right: 6px; top: 5px; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.clear-search:hover { background: #e8ebe5; }
.clear-search svg { width: 17px; height: 17px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 14px; border: 0; border-radius: 8px; cursor: pointer; font-weight: 600; transition: background .15s, transform .15s; }
.button:active { transform: translateY(1px); }
.button-header { color: #fff; background: var(--green); }
.button-header:hover, .button-primary:hover { background: #233c30; }
.button-primary { width: 100%; color: #fff; background: var(--green); }
.button-secondary { border: 1px solid var(--line); background: #fff; }
.button-secondary:hover { background: #f2f3ee; }
.button-danger { color: #fff; background: var(--red); }
.button-save { color: #fff; background: var(--green); }
.button:disabled { opacity: .5; cursor: wait; }
.editor-tools { min-height: 48px; display: flex; align-items: center; gap: 6px; padding: 6px 18px; border-top: 1px solid #e4e4dc; background: #f3f4ef; overflow-x: auto; }
.mode-label { margin-right: 8px; color: var(--green); font-size: 12px; font-weight: 700; white-space: nowrap; }
.tool-button { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 9px; border: 1px solid transparent; border-radius: 7px; background: transparent; cursor: pointer; white-space: nowrap; font-size: 12px; }
.tool-button:hover { border-color: #d2d8d1; background: #fff; }
.tool-button svg { width: 16px; height: 16px; }
.tool-separator { width: 1px; height: 24px; margin: 0 4px; background: #d3d7d1; }
.tool-spacer { flex: 1; min-width: 10px; }
.save-state { color: var(--muted); font-size: 11px; white-space: nowrap; }
.save-state.dirty { color: #946c28; }
#viewport { position: fixed; inset: 72px 0 0; overflow: hidden; cursor: grab; touch-action: none; background-color: #e9e9df; background-image: radial-gradient(circle, rgba(83, 99, 86, .17) 1px, transparent 1px); background-size: 26px 26px; }
body.editing #viewport { top: 120px; }
#viewport.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.element { position: absolute; user-select: none; -webkit-user-select: none; transform-origin: center; }
.plot-card { display: flex; flex-direction: column; overflow: visible; padding: 0; border: 1.5px solid #b8bcb2; border-radius: 9px; background: var(--panel); box-shadow: 0 3px 8px rgba(41, 53, 44, .12); cursor: pointer; transition: opacity .2s, box-shadow .2s; }
.plot-card:hover { box-shadow: 0 6px 18px rgba(41, 53, 44, .2); }
.plot-card.is-red { border: 3px solid #e43528; background: #fff0ec; box-shadow: 0 3px 10px rgba(188, 43, 31, .2); }
.plot-card.search-hit { z-index: 8; box-shadow: 0 0 0 5px #d5aa5d, 0 9px 28px rgba(71, 54, 23, .32); }
.element.dimmed { opacity: .25; }
.plot-head { flex: 0 0 36px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 7px 4px 11px; border-bottom: 1px solid #e0e1d9; }
.plot-number { color: #53645a; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.is-red .plot-number { color: #d52b1f; }
.is-red .empty-plot { color: #d52b1f; }
.photo-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 34px; height: 27px; padding: 2px 6px; border: 0; border-radius: 6px; color: #536a5b; background: #edf0e9; cursor: pointer; }
.photo-button:hover { background: #dfe6dc; }
.photo-button.empty { opacity: .42; cursor: default; }
.photo-button svg { width: 16px; height: 16px; }
.photo-button span { font-size: 10px; font-weight: 700; }
.people-mini { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 3px; padding: 6px 8px 8px; }
.person-mini { display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 50px; }
.portrait-thumb { width: 38px; height: 46px; overflow: hidden; display: grid; place-items: center; border: 1px solid #dedfd7; border-radius: 4px; color: #a4aaa1; background: #f0f1ec; cursor: pointer; }
.portrait-thumb.empty { cursor: default; }
.portrait-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.portrait-thumb svg { width: 18px; height: 18px; opacity: .55; }
.person-text { min-width: 0; }
.person-name { font-family: Georgia, "Times New Roman", serif; font-size: 13px; line-height: 1.17; overflow-wrap: anywhere; }
.person-years { margin-top: 3px; color: #6d756f; font-size: 11px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.empty-plot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #909a91; }
.empty-plot svg { width: 45px; height: 45px; stroke-width: 1; }
.empty-plot span { font-size: 12px; }
.decor { display: flex; align-items: center; justify-content: center; text-align: center; font-size: 16px; }
.road { border: 2px dashed #a8aa9f; border-radius: 4px; color: #777c72; background: repeating-linear-gradient(135deg, #d9d9cf 0, #d9d9cf 16px, #cdcec3 16px, #cdcec3 32px); font-style: italic; }
.bush { border: 3px dashed #79906f; border-radius: 50%; color: #536b48; background: rgba(114, 146, 94, .22); }
.building { border: 2px solid #59665f; border-radius: 4px; color: #fff; background: #75827a; }
.element.selected { outline: 3px solid #b1813c; outline-offset: 3px; z-index: 12; }
.handle { position: absolute; z-index: 20; width: 12px; height: 12px; border: 2px solid #fff; border-radius: 50%; background: #a47735; box-shadow: 0 1px 3px #555; transform: scale(var(--iz, 1)); }
.element > .handle, .element > .rotate-handle { display: none; }
.element.show-handles > .handle, .element.show-handles > .rotate-handle { display: block; }
.handle-nw { left: -7px; top: -7px; cursor: nwse-resize; }.handle-n { left: calc(50% - 6px); top: -7px; cursor: ns-resize; }.handle-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.handle-e { right: -7px; top: calc(50% - 6px); cursor: ew-resize; }.handle-se { right: -7px; bottom: -7px; cursor: nwse-resize; }.handle-s { left: calc(50% - 6px); bottom: -7px; cursor: ns-resize; }
.handle-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }.handle-w { left: -7px; top: calc(50% - 6px); cursor: ew-resize; }
.rotate-handle { position: absolute; left: calc(50% - 7px); top: -32px; z-index: 20; width: 14px; height: 14px; border: 2px solid #fff; border-radius: 50%; background: var(--green); cursor: grab; transform: scale(var(--iz, 1)); }
.rotate-handle::after { content: ""; position: absolute; left: 5px; top: 12px; width: 2px; height: 16px; background: var(--green); }
.group-box { position: absolute; z-index: 18; border: 2px dashed #a47735; pointer-events: none; }
.group-box .handle, .group-box .rotate-handle { pointer-events: auto; }
#links { position: absolute; inset: 0; overflow: visible; pointer-events: none; z-index: 2; }
.link-visible { stroke: #6b766d; pointer-events: none; }
.link-visible.selected { stroke: var(--red); }
.link-hit { stroke: transparent; pointer-events: stroke; cursor: pointer; }
#marquee { position: fixed; z-index: 30; border: 2px dashed #a47735; background: rgba(181, 138, 70, .12); pointer-events: none; }
.search-panel { position: fixed; z-index: 35; top: 88px; right: 16px; bottom: 82px; width: min(390px, calc(100vw - 32px)); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
body.editing .search-panel { top: 136px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 17px 16px 13px 20px; border-bottom: 1px solid #e6e6df; }
.panel-heading strong { display: block; font-family: Georgia, serif; font-size: 19px; font-weight: 500; }
.panel-heading span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.icon-button:hover { background: rgba(100, 112, 103, .1); }
.search-results { overflow-y: auto; padding: 8px; }
.search-result { width: 100%; display: grid; grid-template-columns: 58px minmax(0, 1fr) 44px; align-items: center; gap: 12px; padding: 10px; border: 0; border-radius: 9px; text-align: left; background: transparent; cursor: pointer; }
.search-result:hover { background: #edf0e9; }
.search-result-photo { width: 58px; height: 66px; display: grid; place-items: center; overflow: hidden; border: 1px solid #e0e1d9; border-radius: 6px; color: #929c93; background: #f1f2ed; }
.search-result-photo img { width: 100%; height: 100%; object-fit: cover; }
.search-result-name { display: block; font-family: Georgia, serif; font-size: 15px; line-height: 1.25; }
.search-result-years { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.search-result-number { color: #596b5e; font-size: 12px; font-weight: 700; text-align: right; }
.empty-results { padding: 34px 20px; color: var(--muted); text-align: center; }
.map-hint { position: fixed; left: 18px; bottom: 18px; z-index: 20; max-width: calc(100vw - 250px); padding: 8px 12px; border: 1px solid rgba(255, 255, 255, .25); border-radius: 8px; color: #f5f6f2; background: rgba(38, 52, 46, .82); font-size: 11px; pointer-events: none; }
.zoom-controls { position: fixed; right: 18px; bottom: 18px; z-index: 20; display: flex; align-items: center; padding: 4px; border: 1px solid #d1d4ca; border-radius: 10px; background: var(--panel); box-shadow: 0 4px 15px rgba(38, 52, 46, .12); }
.zoom-fit { height: 36px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 0; border-inline: 1px solid #e1e2da; background: transparent; cursor: pointer; font-size: 11px; }
.zoom-fit svg { width: 16px; height: 16px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 24px; background: rgba(24, 34, 29, .58); backdrop-filter: blur(3px); }
.plot-dialog { position: relative; width: min(760px, 100%); max-height: calc(100vh - 48px); overflow-y: auto; border-radius: 16px; background: var(--panel); box-shadow: 0 25px 80px rgba(0, 0, 0, .3); }
.modal-close { position: absolute; top: 12px; right: 12px; z-index: 3; background: rgba(255, 255, 255, .85); }
.dialog-header { padding: 27px 64px 20px 30px; border-bottom: 1px solid #e1e2da; }
.dialog-eyebrow { color: #697b6f; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.dialog-header h2 { margin: 4px 0 0; font-family: Georgia, serif; font-size: 28px; font-weight: 500; line-height: 1.2; }
.dialog-body { padding: 24px 30px 30px; }
.dialog-section + .dialog-section { margin-top: 25px; padding-top: 22px; border-top: 1px solid #e3e4dc; }
.dialog-section h3 { margin: 0 0 13px; color: #657269; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }
.dialog-person { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; padding: 14px 0; }
.dialog-person + .dialog-person { border-top: 1px solid #ecece6; }
.dialog-person-name { font-family: Georgia, serif; font-size: 20px; }
.dialog-person-years { margin-top: 4px; color: var(--muted); }
.portrait-gallery { display: flex; gap: 8px; }
.portrait-gallery .gallery-thumb { width: 72px; height: 88px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery-thumb { position: relative; height: 130px; overflow: hidden; padding: 0; border: 1px solid #dcded5; border-radius: 7px; background: #eff0eb; cursor: pointer; }
.gallery-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform .2s; }
.gallery-thumb:hover img { transform: scale(1.03); }
.empty-gallery { padding: 16px; border: 1px dashed #d7d9d0; border-radius: 8px; color: #8a928b; background: #f7f7f2; font-size: 12px; text-align: center; }
.note-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 26px; }
.edit-grid { display: grid; gap: 14px; }
.edit-grid label, .auth-dialog label { display: grid; gap: 6px; color: #606e65; font-size: 12px; font-weight: 600; }
.edit-grid input, .edit-grid textarea, .auth-dialog input { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid #ccd1c8; border-radius: 7px; color: var(--ink); background: #fff; font-weight: 400; }
.edit-grid textarea { min-height: 100px; resize: vertical; }
.edit-person { padding: 15px; border: 1px solid #dfe2d9; border-radius: 10px; background: #f8f8f4; }
.edit-person + .edit-person { margin-top: 12px; }
.edit-person-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.edit-person-head strong { font-size: 13px; }
.edit-person-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(140px, 1fr); gap: 10px; }
.small-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 6px 10px; border: 1px solid #cfd4cb; border-radius: 7px; background: #fff; cursor: pointer; font-size: 12px; }
.small-button:hover { background: #ecefe9; }
.small-button.danger { color: var(--red); }
.small-button svg { width: 15px; height: 15px; }
.upload-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.upload-row input[type="file"] { display: none; }
.edit-photo-list { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-photo { position: relative; width: 92px; }
.edit-photo .gallery-thumb { width: 92px; height: 82px; }
.remove-photo { position: absolute; right: -5px; top: -5px; width: 23px; height: 23px; display: grid; place-items: center; padding: 0; border: 2px solid #fff; border-radius: 50%; color: #fff; background: var(--red); cursor: pointer; }
.remove-photo svg { width: 12px; height: 12px; }
.checkbox-label { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px !important; }
.checkbox-label input { width: 18px; min-height: 18px; }
.auth-dialog { position: relative; width: min(410px, 100%); padding: 32px; border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
.auth-mark { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 50%; color: var(--green); background: var(--green-soft); }
.auth-dialog h2 { margin: 18px 0 8px; font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.auth-dialog p { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.auth-dialog form { display: grid; gap: 15px; }
.form-error { min-height: 18px; color: var(--red); font-size: 12px; }
.lightbox { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 50px 75px; background: rgba(12, 17, 14, .94); }
.lightbox figure { max-width: 100%; max-height: 100%; margin: 0; text-align: center; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 130px); display: block; object-fit: contain; box-shadow: 0 10px 45px #000; }
.lightbox figcaption { margin-top: 13px; color: #d8ddd8; font-size: 12px; }
.lightbox .icon-button { position: absolute; color: #fff; background: rgba(255, 255, 255, .1); }
.lightbox .icon-button:hover { background: rgba(255, 255, 255, .2); }
.lightbox-close { top: 18px; right: 18px; }
.lightbox-prev, .lightbox-next { top: 50%; width: 46px; height: 60px; transform: translateY(-50%); }
.lightbox-prev { left: 16px; }.lightbox-next { right: 16px; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 110; max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 9px; color: #fff; background: #2d4236; box-shadow: var(--shadow); transform: translateX(-50%); font-size: 13px; }
.toast.error { background: #8e433d; }
@media (max-width: 760px) {
  .main-bar { min-height: 116px; flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; }
  .brand { flex: 1; }
  .brand-mark { width: 34px; height: 34px; }
  .brand strong { font-size: 17px; }
  .brand small { display: none; }
  .button-header { min-height: 34px; padding: 6px 10px; font-size: 12px; }
  .search-wrap { order: 3; width: 100%; }
  .search-wrap input { height: 40px; }
  .search-icon { top: 10px; }
  #viewport { top: 116px; }
  body.editing #viewport { top: 164px; }
  .editor-tools { min-height: 48px; padding-inline: 10px; }
  .mode-label, .save-state, #exportButton { display: none; }
  body.editing .search-panel { top: 174px; }
  .search-panel { top: 126px; right: 10px; bottom: 76px; width: calc(100vw - 20px); }
  .map-hint { display: none; }
  .zoom-controls { right: 10px; bottom: 10px; }
  .modal-backdrop { padding: 10px; }
  .plot-dialog { max-height: calc(100vh - 20px); border-radius: 12px; }
  .dialog-header { padding: 22px 50px 16px 20px; }
  .dialog-header h2 { font-size: 23px; }
  .dialog-body { padding: 18px 20px 24px; }
  .dialog-person { grid-template-columns: 1fr; gap: 10px; }
  .edit-person-row { grid-template-columns: 1fr; }
  .lightbox { padding: 50px 12px 70px; }
  .lightbox-prev, .lightbox-next { top: auto; bottom: 12px; transform: none; }
  .lightbox-prev { left: calc(50% - 56px); }.lightbox-next { right: calc(50% - 56px); }
}
