/* The map is the application surface. Navigation occupies one compact dock. */
html,body{height:100%;overflow:hidden}body.map-mode,body.sheet-mode{height:100dvh;background:var(--sea)}
body #app{position:fixed;inset:0;display:block;padding:0;overflow:hidden;width:100%;height:100dvh}
#app>#map-view{position:absolute;inset:0;display:block;height:100%;min-height:0}
#app>#map-view[hidden],#app>#spreadsheet-view[hidden]{display:none!important}
#map-view>.map-and-detail{position:absolute;inset:0;display:block;height:100%;min-height:0;border:0;border-radius:0}
#atlas{display:block;width:100%;height:100%;min-height:0;max-height:none}
#map-dock{position:absolute;left:max(18px,env(safe-area-inset-left));bottom:calc(12px + env(safe-area-inset-bottom));z-index:6;display:grid;justify-items:start;gap:14px;width:310px;max-width:calc(100% - 36px);pointer-events:none}
.map-dock-controls{display:flex;align-items:center;gap:3px;padding:4px;border:1px solid #b8c4ad;background:#faf8eff2;border-radius:7px;pointer-events:auto}
#map-dock>#group-actions{position:static;min-width:0;max-width:none;width:100%;pointer-events:auto}
.icon-button{display:grid;place-items:center;width:44px;min-width:44px;height:44px;min-height:44px;padding:9px;border:0;background:transparent;color:#334e41;border-radius:5px;font-size:23px}
.icon-button svg{width:23px;height:23px;stroke:currentColor;stroke-width:1.5;fill:none;stroke-linejoin:round;stroke-linecap:round}
#toggle-sound .sound-off,#toggle-sound[aria-pressed="true"] .sound-waves{display:none}
#toggle-sound[aria-pressed="true"] .sound-off{display:block}
#toggle-sound[aria-pressed="true"]{color:#84907b}
.view-toggle{background:#dce5d4}.icon-button:disabled{opacity:.28;cursor:default}
#map-history{position:absolute;top:max(14px,env(safe-area-inset-top));right:max(14px,env(safe-area-inset-right));z-index:6;display:flex;gap:4px}
#map-history button{width:48px;min-width:48px;height:48px;min-height:48px;margin:0;padding:7px;border:0;background:transparent;box-shadow:none;color:#334c40;opacity:.23;transition:opacity .18s ease;touch-action:manipulation}
#map-history button svg{width:34px;height:34px;stroke-width:1.4}
#map-history button:disabled{opacity:.09}
#map-history button:not(:disabled):hover,#map-history button:focus-visible{opacity:.72;background:transparent}
#map-history button:focus-visible{outline:1px solid #334c40;outline-offset:-4px}
#map-mode-hint{top:max(16px,env(safe-area-inset-top));max-width:calc(100% - 340px)}
.zoom-controls{top:max(14px,env(safe-area-inset-top));left:max(14px,env(safe-area-inset-left))}
#group-actions{bottom:calc(82px + env(safe-area-inset-bottom))}#toast{bottom:calc(84px + env(safe-area-inset-bottom))}
#map-view .dragon-marginalia{bottom:16px}
/* A working ledger: sticky coordinates, quiet grid lines, one active cell. */
#app>#spreadsheet-view{position:absolute;inset:0;display:flex;flex-direction:column;background:#fafbf7;color:#304137;font:13px 'DM Sans',sans-serif;min-width:0}
.sheet-formula{display:flex;align-items:center;gap:0;min-height:45px;padding:4px 8px;background:#edf1e7;border-bottom:1px solid #bcc9b1;flex:none}
.cell-address{width:62px;flex:none;text-align:center;font-size:12px;color:#64725e}
.formula-value{flex:1;min-width:0;height:32px;padding:5px 10px;border:1px solid #d0d8c8;background:#fffefa;font-size:13px;border-radius:3px;color:#304137}
.sheet-copy{min-height:34px;margin-left:8px;padding:4px 12px;font-size:12px;background:transparent;border:0;white-space:nowrap}
.sheet-scroll{flex:1;min-height:0;overflow:auto;position:relative;outline:none;background:#fffefa;overscroll-behavior:contain;scrollbar-color:#c2cdb7 #eff2e9}
.sheet-scroll table{table-layout:fixed;border-collapse:separate;border-spacing:0;width:max-content;min-width:100%;font-size:13px}
.sheet-scroll th,.sheet-scroll td{height:34px;min-height:34px;padding:0 9px;border:0;border-right:1px solid #e0e5d9;border-bottom:1px solid #e0e5d9;text-align:left;white-space:nowrap;overflow:hidden;box-sizing:border-box;font-weight:400}
.sheet-scroll thead{position:sticky;top:0;z-index:4}.sheet-scroll thead th{background:#eef2e8;color:#687660;font-size:11px;text-align:center}
.sheet-scroll .sheet-letters th{height:26px;min-height:26px}.sheet-scroll .sheet-headings th{height:36px;min-height:36px;font-size:12px;font-weight:600;color:#3b5143;text-align:left;background:#e5ecdd;border-bottom-color:#bcc9b1}
.sheet-scroll tbody th{position:sticky;left:0;z-index:2;background:#f1f4ec;color:#829075;text-align:center;font-size:11px;cursor:pointer}
.sheet-scroll thead th:first-child{position:sticky;left:0;z-index:5}
.sheet-scroll td{position:relative;cursor:cell;user-select:none;background:#fffefa}
.sheet-scroll td>span{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;line-height:33px;height:33px}
.sheet-scroll .number-cell{text-align:right;font-variant-numeric:tabular-nums}
.sheet-scroll td.cell-selected{background:#e8efdf}.sheet-scroll td.cell-active{box-shadow:inset 0 0 0 2px #557745;z-index:1;background:#f8fbf1}
.sheet-scroll .sheet-spacer td{padding:0;border:0;background:#fffefa}
.cell-editor{position:absolute;inset:0;z-index:3;resize:none;width:100%;height:100%;margin:0;padding:7px 8px;line-height:19px;border:2px solid #557745;border-radius:0;outline:0!important;background:white;color:#263e35;font:13px 'DM Sans',sans-serif;box-shadow:none}
.sheet-bottom{display:flex;align-items:center;gap:8px;min-height:58px;padding:5px 12px calc(5px + env(safe-area-inset-bottom));background:#edf1e7;border-top:1px solid #bdcab2;flex:none}
.return-map{background:#d9e4d0}.sheet-tabs{display:flex;align-self:stretch;align-items:stretch;overflow-x:auto;min-width:0}
.sheet-tabs button{padding:6px 16px;border:0;border-bottom:3px solid transparent;border-radius:0;background:none;white-space:nowrap;font-size:13px;color:#66785c}
.sheet-tabs [aria-selected=true]{background:#fffefa;border-bottom-color:#527040;color:#2d4930;font-weight:600}
.sheet-row-actions{display:flex;gap:4px;white-space:nowrap}.sheet-row-actions button,.sheet-bottom [data-sheet-history]{font-size:12px;min-height:36px;border:0;background:transparent;padding:5px 8px}.sheet-bottom [data-sheet-history]{font-size:20px}
.sheet-status{margin-left:auto;font-size:11px;color:#708065;white-space:nowrap}
.sheet-error{background:#f2e2d8;color:#864c36;padding:9px 16px;border-bottom:1px solid #d4b6a4;flex:none}.sheet-error[hidden]{display:none}
@media(max-width:900px){.sheet-status{display:none}.sheet-tabs button{padding:7px 12px}}
@media(max-width:600px){#map-dock{left:14px;right:auto;bottom:calc(8px + env(safe-area-inset-bottom));width:282px;max-width:calc(100% - 28px);gap:12px}.icon-button{width:40px;min-width:40px;height:44px;padding:9px}.zoom-controls{top:max(10px,env(safe-area-inset-top));left:10px}#map-mode-hint{top:64px;max-width:calc(100% - 20px);width:max-content;min-width:0}#map-view .dragon-marginalia{bottom:calc(78px + env(safe-area-inset-bottom))}.sheet-bottom{gap:3px;padding:4px 6px calc(4px + env(safe-area-inset-bottom));flex-wrap:wrap}.sheet-tabs{flex:1}.sheet-tabs button{font-size:12px;padding:8px 11px;min-height:44px}.sheet-row-actions{padding-left:46px;flex:1}.sheet-formula{padding:5px 4px}.formula-value,.cell-editor{font-size:16px}.sheet-copy{padding:5px;font-size:11px;margin-left:3px}.cell-address{width:42px}}

@media(max-width:600px){.sheet-bottom{display:grid;grid-template-columns:44px minmax(0,1fr) 36px 36px}.sheet-bottom>.return-map{grid-column:1;grid-row:1}.sheet-tabs{grid-column:2 / 5;grid-row:1}.sheet-tabs button{padding:8px}.sheet-row-actions{grid-column:2;grid-row:2;padding-left:0}.sheet-bottom [data-sheet-history]{grid-row:2}.sheet-bottom .sheet-status{display:none}#map-dock .map-dock-controls>.icon-button{width:44px;min-width:44px}}

@media(max-width:600px){.sheet-bottom [data-sheet-history="undo"]{grid-column:3}.sheet-bottom [data-sheet-history="redo"]{grid-column:4}}

.sheet-scroll .mapdata-cell{color:#819077;font-size:11px}.sheet-scroll .mapdata-cell.cell-active{color:#405936}

.sheet-file-actions{display:flex;flex-wrap:wrap;align-items:center;gap:3px;flex:none;margin-left:6px}
.sheet-file-actions button{min-height:36px;padding:6px 10px;white-space:nowrap;font-size:12px;background:transparent;border:1px solid transparent}
.sheet-file-actions .sheet-copy{margin-left:0}
.sheet-file-actions .sheet-import{border-color:#b8c6ad;background:#fafbf7}
.sheet-file-actions button:disabled{opacity:.5}
.sheet-drop-hint{position:absolute;inset:10px;z-index:30;display:grid;place-items:center;pointer-events:none;border:2px dashed #5b7d4b;border-radius:10px;background:#eef4e6ed;color:#304b30;font-size:20px;font-weight:600;text-align:center;padding:24px}
.sheet-drop-hint[hidden]{display:none}
@media(max-width:650px){.sheet-formula{display:grid;grid-template-columns:42px minmax(0,1fr);gap:4px;padding:5px 6px}.sheet-formula .cell-address{width:42px}.sheet-file-actions{grid-column:1/-1;margin:0;justify-content:flex-end}.sheet-file-actions button{min-height:44px;padding:6px 9px}}

/* Engraved marginalia belongs to the ocean, beneath every interactive layer. */
#ocean-ships{pointer-events:none;user-select:none}#ocean-ships .ocean-ship{pointer-events:all;cursor:grab;touch-action:none}#ocean-ships .ocean-ship *{pointer-events:none}#ocean-ships .ship-hit-area{pointer-events:all}.ocean-ship.is-dragging{opacity:.5;cursor:grabbing}.ocean-ship:focus-visible{outline:none;opacity:.5}.ocean-ship:focus-visible .ship-hit-area{stroke:#667a50;stroke-width:2;stroke-dasharray:3 5}body.dragging-ship{cursor:grabbing;user-select:none}
.ocean-ship{opacity:.2}
.ocean-ship.is-sailing{will-change:transform}

/* A small campaign scroll: the troop key is also the reserve's playing area. */
.reserve-play-area{--scroll-edge:#c0ac82;position:relative;width:100%;padding:12px 14px 10px;color:#3f4939;background:linear-gradient(90deg,#e4d9bc 0%,#f5edda 7%,#f7f0df 50%,#f0e6cf 93%,#dbcbab 100%);border:1px solid var(--scroll-edge);border-radius:3px;box-shadow:0 5px 12px #3f493921,inset 0 0 0 4px #fff8e530;pointer-events:auto;isolation:isolate;transition:box-shadow .15s ease,border-color .15s ease}
.reserve-play-area::before,.reserve-play-area::after{content:'';position:absolute;left:-7px;right:-7px;height:12px;border:1px solid #b5a079;border-radius:50% / 35%;background:linear-gradient(#dac9a5,#f8f0dc 37%,#eee1c3 64%,#bba27b);box-shadow:0 2px 3px #493e2d20;pointer-events:none}
.reserve-play-area::before{top:-6px}.reserve-play-area::after{bottom:-6px;transform:rotate(180deg)}
#reserve .reserve-heading{display:flex;flex-direction:row;align-items:center;justify-content:space-between;gap:8px;margin:0 0 7px;padding:0 0 5px;border-bottom:1px solid #b9a78666}
#reserve h2{font:25px/1.1 'Libre Caslon Display',Georgia,serif;font-weight:400;margin:0;color:#4e503c}
#reserve .reserve-roster{border:0;background:none;padding:4px 0 4px 8px;font-size:11px;min-height:32px;color:#62634c;white-space:nowrap}
.reserve-roster span{font-size:20px;vertical-align:-1px;margin-left:3px}
.reserve-ranks{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0}
.reserve-rank{display:flex;flex-direction:column;align-items:center;min-width:0}
.reserve-rank+.reserve-rank{border-left:1px solid #b9a78645}
#reserve h3{font:500 12px/1.4 'DM Sans',sans-serif;margin:0 0 1px;color:#555b45}
#reserve .reserve-soldier,#reserve .reserve-legend-icon{display:flex;align-items:center;justify-content:center;flex:none;width:48px;min-width:48px;height:68px;min-height:68px;padding:0;margin:0;border:0;background:none;touch-action:none;border-radius:4px}
#reserve .soldier-avatar{width:36px;height:66px;pointer-events:none;filter:drop-shadow(0 1px 1px #493e2d22)}
.reserve-legend-icon{opacity:.5}
.reserve-total{font-size:10px;line-height:19px;color:#686b55;font-variant-numeric:tabular-nums}
.reserve-total strong{font-size:18px;font-weight:500;color:#414c3b}
#reserve .reserve-available{border:0;background:none;border-radius:3px;padding:4px 2px;min-height:28px;font-size:10px;color:#606a52;white-space:nowrap;text-decoration:underline;text-decoration-color:#b1ac91;text-underline-offset:3px}
#reserve .reserve-hint{font:italic 12px/1.4 Georgia,serif;text-align:center;color:#7e785e;margin:4px 0 0;padding-top:6px;border-top:1px solid #b9a78666}
.reserve-hint span+span{display:none}
#reserve.drop-hover{border-color:#667a50;outline:2px solid #667a5080;outline-offset:5px;box-shadow:0 5px 18px #3f493938,inset 0 0 0 3px #83916540;filter:none;background:linear-gradient(90deg,#d8d2ae,#f1eed4 10%,#eeebcc 90%,#c8c5a0)!important}
#reserve.drop-hover .reserve-hint{color:#405737}
#reserve.drop-hover .reserve-hint span:first-child{display:none}
#reserve.drop-hover .reserve-hint span+span{display:inline}
#reserve button:focus-visible{outline:2px solid #63784c;outline-offset:1px}
.country-people-list .reserve-soldier{display:flex;align-items:center;justify-content:center;min-width:44px;min-height:52px;padding:0!important;border:0}
.country-people-list .reserve-soldier .soldier-avatar{width:27px;height:48px}
.reserve-empty{font-size:13px;line-height:1.6;color:#68745d}
@media(max-width:600px){.reserve-play-area{padding:10px 10px 8px}#reserve h2{font-size:23px}#reserve .reserve-roster{font-size:10px;min-height:32px}#reserve .reserve-available{min-height:32px}#reserve .reserve-hint{font-size:11px;margin-top:2px}}
@media(max-height:530px){#map-dock{gap:10px}.reserve-play-area{padding-top:8px;padding-bottom:7px}#reserve .reserve-heading{margin-bottom:4px}#reserve .reserve-rank{display:grid;grid-template-columns:40px 1fr;grid-template-rows:20px 24px 28px;text-align:center;column-gap:2px;padding:0 4px}#reserve .reserve-rank h3{grid-column:2;grid-row:1;font-size:11px}#reserve .reserve-soldier,#reserve .reserve-legend-icon{grid-column:1;grid-row:1/4;width:40px;min-width:40px}#reserve .reserve-total{grid-column:2;grid-row:2}#reserve .reserve-total span{display:none}#reserve .reserve-available{grid-column:2;grid-row:3;font-size:9px;white-space:normal;line-height:1.1}#reserve .reserve-hint{font-size:10px}}
@media(prefers-reduced-motion:reduce){.reserve-play-area{transition:none}}

/* Tap the scroll's heading or parchment to roll it away. It remains a drop zone. */
#reserve #toggle-reserve{display:flex;align-items:center;gap:10px;width:100%;min-height:44px;padding:0;border:0;background:none;text-align:left;color:#4e503c;cursor:pointer}
#reserve #reserve-title{font:25px/1.1 'Libre Caslon Display',Georgia,serif;flex:1}
#reserve .reserve-summary{font:11px 'DM Sans',sans-serif;white-space:nowrap;color:#62634c}
#toggle-reserve svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.5;transition:transform .18s ease}
#toggle-reserve[aria-expanded=false] svg{transform:rotate(180deg)}
#reserve-contents[hidden]{display:none!important}
#reserve.is-collapsed{padding-top:4px;padding-bottom:4px}
#reserve.is-collapsed .reserve-heading{border:0;padding:0;margin:0}
#reserve .reserve-roster{display:block;margin:0 auto}
#map-dock.reserve-collapsed{width:250px}
@media(max-width:600px){#map-dock.reserve-collapsed{width:230px}#reserve #reserve-title{font-size:23px}}
@media(prefers-reduced-motion:reduce){#toggle-reserve svg{transition:none}}

#app>.sheet-drop-hint{position:fixed;inset:12px;z-index:1002}

/* Same-column completions stay beside the cell without covering neighboring controls. */
.sheet-autocomplete{position:fixed;z-index:80;max-height:300px;padding:4px;background:#fffdf6;border:1px solid #b7c3aa;border-radius:5px;box-shadow:0 6px 22px #263e3524;color:#263e35;font:13px 'DM Sans',sans-serif}
.sheet-autocomplete[hidden]{display:none}
.sheet-suggestion-options{max-height:250px;overflow:auto}
.sheet-autocomplete [role=option]{padding:9px 10px;border-radius:3px;cursor:pointer;white-space:pre-wrap;overflow-wrap:anywhere}
.sheet-autocomplete [role=option][aria-selected=true],.sheet-autocomplete [role=option]:hover{background:#e4ebdc}
.sheet-autocomplete small{display:block;padding:6px 10px 3px;color:#697864;font-size:10px}
@media(max-width:600px){.sheet-autocomplete [role=option]{min-height:44px;font-size:16px}}

/* The looking glass lives on the map; the list folds away after focusing a match. */
.map-search{position:absolute;left:max(14px,env(safe-area-inset-left));top:72px;z-index:12;max-width:calc(100% - 28px)}
.map-search-toggle{width:44px;height:44px;background:#faf8efed;color:#65755b;border:1px solid #bcc8b2;box-shadow:0 2px 10px #263e3509}
.map-search svg{width:21px;height:21px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;flex-shrink:0}
.map-search.is-open>.map-search-toggle{display:none}
#map-search-panel{width:340px;max-width:calc(100vw - 28px);background:#faf8effa;border:1px solid #b6c2ab;border-radius:7px;box-shadow:0 9px 28px #263e3526;overflow:hidden}
#map-search-panel[hidden]{display:none}
.map-search-field{display:flex;align-items:center;gap:9px;padding:6px 6px 6px 12px;color:#65755b}
#map-search-input{width:100%;min-width:0;margin:0;padding:8px 0;border:0;background:transparent;outline:none;box-shadow:none;font:14px 'DM Sans',sans-serif;color:#263e35}
.map-search-close{flex-shrink:0;width:36px;min-width:36px;height:36px;min-height:36px;padding:0;border:0;background:transparent;color:#65755b;font:23px sans-serif}
#map-search-results{max-height:min(340px,calc(100dvh - 235px));overflow:auto;overscroll-behavior:contain}
#map-search-results [role=option]{padding:10px 13px;border-top:1px solid #e0e5d7;cursor:pointer;display:grid;grid-template-columns:1fr auto;gap:3px 12px}
#map-search-results [role=option][aria-selected=true],#map-search-results [role=option]:hover{background:#e3ebda}
#map-search-results strong{font-size:14px;font-weight:600;grid-row:1;overflow-wrap:anywhere}
#map-search-results small{font-size:11px;color:#67775c;grid-column:1/-1}
.map-match-type{grid-column:2;grid-row:1;font-size:10px;color:#7b876e;align-self:center}
.map-search-status{margin:0;padding:9px 13px;font-size:11px;color:#74806c;border-top:1px solid #e0e5d7}
.map-search-reserve{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);z-index:13;width:260px;max-width:calc(100% - 28px);text-align:center;background:#f7f0df;border:1px solid #b9aa88;box-shadow:0 8px 28px #263e3522;border-radius:7px;padding:20px;color:#3f4939}
.map-search-reserve[hidden]{display:none}
.map-search-reserve>.map-search-close{position:absolute;right:4px;top:4px}
.map-search-reserve .map-search-reserve-tag{display:block;font:italic 18px 'Libre Caslon Display',Georgia,serif;margin-bottom:7px}
.map-search-reserve .reserve-soldier{display:flex;justify-content:center;margin:0 auto 10px;padding:0;width:58px;height:88px;background:none;border:0}
.map-search-reserve .soldier-avatar{width:42px;height:76px}
.map-search-reserve strong{display:block;font-size:17px;overflow-wrap:anywhere}
.map-search-reserve p{font-size:12px;margin:5px 0 13px}.map-search-reserve>small{font-size:11px;color:#7a7b62}
.map-search-found .territory,.territory.map-search-found{animation:search-country-pulse 1.2s ease-in-out 2}
@keyframes search-country-pulse{0%,100%{stroke:#637653;stroke-width:2}50%{stroke:#425d35;stroke-width:5}}
@media(max-width:600px){.map-search{top:64px;left:10px;max-width:calc(100% - 20px)}#map-search-panel{width:350px;max-width:calc(100vw - 20px)}#map-search-input{font-size:16px}.map-search-close{width:44px;min-width:44px;height:44px}#map-search-results [role=option]{padding:12px}}
@media(prefers-reduced-motion:reduce){.map-search-found .territory,.territory.map-search-found{animation:none;stroke:#425d35;stroke-width:3}}
.sheet-new-picker{position:relative}
.sheet-new-options{position:absolute;top:calc(100% + 6px);left:0;z-index:30;min-width:130px;padding:5px;background:#faf9f2;border:1px solid #c5cebb;border-radius:7px;box-shadow:0 5px 18px #263d3426}
.sheet-new-options:not([hidden]){display:grid;gap:4px}
.sheet-new-options button{text-align:left;min-height:44px;width:100%}
#map-lock{display:flex;align-items:center;justify-content:center;min-width:44px;min-height:36px}
#map-lock[aria-pressed="true"]{background:#dbe3d4;color:#294436}
.map-locked #atlas .territory{cursor:grab}
.map-locked #atlas.panning .territory{cursor:grabbing}

/* Column controls remain visible while scrolling the sheet. */
.sheet-scroll .sheet-headings th{padding:0}
.sheet-headings button{width:100%;height:36px;border:0;border-radius:0;background:transparent;text-align:left;padding:0 8px;font:inherit;white-space:nowrap}
.sheet-headings button span{float:right;opacity:.6;margin-left:6px}
.sheet-headings th[aria-sort=ascending],.sheet-headings th[aria-sort=descending]{background:#ccd9c4}
.sheet-scroll .sheet-filters th{height:34px;padding:3px 4px;background:#eef2e8}
.sheet-filters input{display:block;width:100%;min-width:0;height:26px;padding:3px 6px;border:1px solid #ccd4c4;border-radius:3px;background:#fafbf6;font-size:12px}
.sheet-filters input:not(:placeholder-shown){border-color:#718566;background:#fff}
.sheet-filters button{border:0;background:transparent;padding:0;width:100%;height:26px}

.map-compass{position:absolute;top:76px;right:max(24px,env(safe-area-inset-right));width:100px;height:117px;color:#626f57;opacity:.24;pointer-events:none;z-index:3}
@media(max-width:600px){.map-compass{width:70px;height:82px;right:20px;top:74px}}
