/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #fff;
    overscroll-behavior: none;
}

/* ── Map viewport (fixed, clips zoomed content) ─────────────────────────────── */
#map-viewport {
    position: fixed;
    inset: 0;
    overflow: hidden;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Map container (receives zoom transform) ─────────────────────────────────── */
#map-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    will-change: transform;
}

#map-container svg {
    width: 100%;
    height: 100%;
}

/* ── Back to main menu (bottom left) ────────────────────────────────────────── */
#back-to-menu {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 10;
    padding: 7px 14px;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 13px;
    color: #333;
    background: #fff;
    border: 1px solid #888;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    text-decoration: none;
    letter-spacing: 0.5px;
    display: inline-block;
}
#back-to-menu:hover  { background: #f0f0f0; }
#back-to-menu:active { background: #e0e0e0; }

/* ── Dev notice (bottom center) ─────────────────────────────────────────────── */
#dev-notice {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    color: #ffffff;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 24px;
    font-style: italic;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.7);
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 0.3px;
    opacity: 0.75;
}

/* ── Game canvas (hidden until needed) ─────────────────────────────────────── */
#gameCanvas {
    display: none;
    position: fixed;
    inset: 0;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Bottom-right button row (Legend + Settings) ─────────────────────────────── */
#bottom-buttons {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10;
    display: flex;
    gap: 6px;
    align-items: center;
}

#bottom-buttons button {
    padding: 7px 14px;
    font-family: Georgia, serif;
    font-size: 13px;
    color: #333;
    background: #fff;
    border: 1px solid #888;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
    letter-spacing: 0.5px;
}
#bottom-buttons button:hover  { background: #f0f0f0; }
#bottom-buttons button:active { background: #e0e0e0; }
#bottom-buttons button.btn-active {
    background: #e8f0d8;
    border-color: #5a8040;
    color: #2a4a20;
    font-weight: bold;
}

/* ── Hero movement info bar ──────────────────────────────────────────────────── */
#hero-info {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    align-items: baseline;
    max-width: 680px;
    padding: 8px 18px;
    background: rgba(18, 14, 8, 0.88);
    border: 1px solid #a07840;
    color: #e8d5a0;
    font-family: Georgia, serif;
    font-size: 13px;
    letter-spacing: 0.4px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s;
}
#hero-info.visible {
    opacity: 1;
}
#hero-info .hi-pos {
    color: #888;
    font-size: 11px;
}
#hero-info .hi-terrain {
    color: #e8d5a0;
    font-weight: bold;
}
#hero-info .hi-feature {
    color: #a8c890;
    font-size: 12px;
}
#hero-info .hi-cost {
    color: #f0c060;
    font-style: italic;
}
#hero-info .hi-elev {
    color: #9ec8e0;
    font-size: 11px;
}
#hero-info .hi-biome {
    color: #c8a870;
    font-size: 11px;
}
#hero-info .hi-flags {
    color: #c890a8;
    font-size: 11px;
}
#hero-info .hi-move {
    color: #d0b060;
    font-size: 11px;
}

/* ── Legend panel ────────────────────────────────────────────────────────────── */
#legend-panel {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: 20;
    width: 270px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    background: #faf6ec;
    border: 1px solid #b0a080;
    box-shadow: 2px 3px 12px rgba(0,0,0,0.22);
    font-family: Georgia, serif;
    font-size: 12px;
    color: #333;

    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
#legend-panel.legend-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
#legend-panel::-webkit-scrollbar { width: 5px; }
#legend-panel::-webkit-scrollbar-track { background: #f0e8d4; }
#legend-panel::-webkit-scrollbar-thumb { background: #b0a070; }

#legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #ede4cc;
    border-bottom: 1px solid #c0a860;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.5px;
}
#legend-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    color: #666;
    padding: 0 2px;
    line-height: 1;
}
#legend-close:hover { color: #111; }

#legend-body {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.legend-empty {
    font-style: italic;
    color: #888;
    font-size: 11px;
}

.legend-section {
    font-size: 9px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #8a7040;
    border-bottom: 1px solid #d8c898;
    padding-bottom: 2px;
    margin-top: 8px;
    margin-bottom: 3px;
}
.legend-section:first-child { margin-top: 2px; }

.legend-biome-name {
    font-size: 13px;
    font-weight: bold;
    color: #2a2010;
    margin-bottom: 2px;
}
.legend-biome-desc {
    font-size: 10px;
    font-style: italic;
    color: #6a5830;
    line-height: 1.4;
    margin-bottom: 4px;
}
.legend-climate {
    font-size: 10px;
    color: #5a5040;
    margin-bottom: 2px;
}
.legend-climate span {
    font-weight: bold;
}

.legend-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 2px;
}
.legend-swatch {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: #444;
    min-width: 110px;
}
.swatch-block {
    display: inline-block;
    width: 16px;
    height: 10px;
    border: 1px solid rgba(0,0,0,0.18);
    flex-shrink: 0;
}
.swatch-water {
    background:
        radial-gradient(circle, rgba(112,132,125,0.7) 1px, transparent 1px) 0    0    / 4px 4px,
        radial-gradient(circle, rgba(112,132,125,0.7) 1px, transparent 1px) 2px  2px  / 4px 4px;
}
.swatch-farmland {
    background: repeating-linear-gradient(
        25deg, transparent 0, transparent 3px,
        rgba(100,80,30,0.30) 3px, rgba(100,80,30,0.30) 4px
    );
}
.swatch-grass {
    background: repeating-linear-gradient(
        90deg, transparent 0, transparent 4px,
        rgba(80,65,25,0.28) 4px, rgba(80,65,25,0.28) 5px
    );
}
.swatch-dunes {
    background: repeating-linear-gradient(
        178deg, transparent 0, transparent 3px,
        rgba(140,105,40,0.32) 3px, rgba(140,105,40,0.32) 4px
    );
}
.swatch-tundra {
    background:
        repeating-linear-gradient(90deg, rgba(80,100,130,0.22) 0, rgba(80,100,130,0.22) 1px, transparent 1px, transparent 8px),
        repeating-linear-gradient(0deg,  rgba(80,100,130,0.22) 0, rgba(80,100,130,0.22) 1px, transparent 1px, transparent 8px);
}
.swatch-heather {
    background: radial-gradient(circle, rgba(110,70,140,0.32) 1px, transparent 1px) 0 0 / 5px 5px;
}
.swatch-canopy {
    background: radial-gradient(circle, rgba(50,90,45,0.32) 2px, transparent 2px) 0 0 / 6px 6px;
}
.swatch-forest {
    background: repeating-linear-gradient(
        -45deg, transparent 0, transparent 3px,
        rgba(55,75,35,0.22) 3px, rgba(55,75,35,0.22) 4px
    );
}
.swatch-bog {
    background: repeating-linear-gradient(
        0deg, transparent 0, transparent 3px,
        rgba(55,75,80,0.28) 3px, rgba(55,75,80,0.28) 4px
    );
}
.swatch-reeds {
    background:
        repeating-linear-gradient(90deg, rgba(45,75,45,0.28) 0, rgba(45,75,45,0.28) 1px, transparent 1px, transparent 5px),
        repeating-linear-gradient(0deg,  rgba(45,75,45,0.28) 0, rgba(45,75,45,0.28) 1px, transparent 1px, transparent 5px);
}
.swatch-peat {
    background: radial-gradient(circle, rgba(35,25,15,0.32) 1px, transparent 1px) 0 0 / 4px 4px;
}
.swatch-rocky {
    background:
        radial-gradient(circle, rgba(95,85,70,0.30) 1px, transparent 1px) 1px 1px / 5px 5px,
        radial-gradient(circle, rgba(95,85,70,0.18) 1px, transparent 1px) 3px 3px / 5px 5px;
}
.swatch-scrub {
    background: radial-gradient(circle, rgba(120,95,55,0.28) 1px, transparent 1px) 2px 2px / 6px 6px;
}

/* Wide swatch for texture entries (label + desc on right) */
.legend-swatch-wide {
    min-width: 100%;
    align-items: flex-start;
    margin-bottom: 1px;
}
.swatch-label {
    display: flex;
    flex-direction: column;
    font-size: 10px;
    color: #444;
    line-height: 1.2;
}
.swatch-desc {
    font-size: 9px;
    color: #888;
    font-style: italic;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 1px 0;
    font-size: 11px;
    color: #333;
}
.legend-symbol {
    font-size: 13px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    color: #5a4820;
}
.legend-icon-svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    overflow: visible;
}
.legend-icon-svg svg { overflow: visible; }
.legend-road-major {
    display: inline-block;
    width: 18px;
    height: 3px;
    background: #c8b06a;
    border: 0.5px solid #5a4a30;
}
.legend-road-road {
    display: inline-block;
    width: 18px;
    height: 2px;
    background: repeating-linear-gradient(90deg,#887060 0,#887060 4px,transparent 4px,transparent 7px);
}
.legend-road-trail {
    display: inline-block;
    width: 18px;
    height: 1px;
    background: repeating-linear-gradient(90deg,#887060 0,#887060 2px,transparent 2px,transparent 6px);
}

/* ── Settings panel ──────────────────────────────────────────────────────────── */
#settings-panel {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: 20;
    width: 290px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    background: #faf6ec;
    border: 1px solid #b0a080;
    box-shadow: 2px 3px 12px rgba(0,0,0,0.22);
    font-family: Georgia, serif;
    font-size: 13px;
    color: #333;

    /* Hidden by default — shown by adding .panel-open */
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
#settings-panel.panel-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* Thin scrollbar for the panel */
#settings-panel::-webkit-scrollbar { width: 5px; }
#settings-panel::-webkit-scrollbar-track { background: #f0e8d4; }
#settings-panel::-webkit-scrollbar-thumb { background: #b0a070; }

#settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #ede4cc;
    border-bottom: 1px solid #c0a860;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.5px;
}
#settings-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    color: #666;
    padding: 0 2px;
    line-height: 1;
}
#settings-close:hover { color: #111; }

#settings-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.setting-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.setting-label {
    font-size: 12px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.setting-val {
    font-size: 12px;
    color: #8a6a20;
    font-style: italic;
}
.hint {
    font-size: 10px;
    color: #999;
    font-style: italic;
    text-transform: none;
    letter-spacing: 0;
}

.setting-range {
    width: 100%;
    accent-color: #8a6a20;
    cursor: pointer;
}

#param-seed {
    width: 100%;
    padding: 4px 7px;
    font-family: Georgia, serif;
    font-size: 12px;
    border: 1px solid #c0b080;
    background: #fff;
    color: #333;
    box-sizing: border-box;
    border-radius: 0;
}

/* ── Section dividers inside settings ───────────────────────────────────────── */
.settings-section-label {
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #8a7040;
    border-bottom: 1px solid #d8c898;
    padding-bottom: 3px;
    margin-top: 2px;
}

/* ── Select dropdowns ────────────────────────────────────────────────────────── */
.setting-select {
    width: 100%;
    padding: 5px 7px;
    font-family: Georgia, serif;
    font-size: 12px;
    border: 1px solid #c0b080;
    background: #fff;
    color: #333;
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a6a20'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    cursor: pointer;
}
.setting-select:focus {
    outline: 1px solid #8a6a20;
}

/* ── Biome description hint ──────────────────────────────────────────────────── */
.setting-hint-line {
    display: block;
    font-size: 10px;
    font-style: italic;
    color: #8a7050;
    line-height: 1.35;
    min-height: 14px;
}

.size-btns {
    display: flex;
    gap: 6px;
}
.size-btn {
    flex: 1;
    padding: 5px 0;
    font-family: Georgia, serif;
    font-size: 12px;
    color: #555;
    background: #fff;
    border: 1px solid #b0a080;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}
.size-btn.active {
    background: #8a6a20;
    color: #fff;
    border-color: #8a6a20;
}
.size-btn:hover:not(.active) { background: #f0ead8; }

.generate-seed-group { margin-bottom: 6px; }
.seed-input-row { display: flex; gap: 6px; }
.seed-input-row input { flex: 1; min-width: 0; box-sizing: border-box; }
.seed-input-row #generate-seed-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 0.78rem;
    font-family: Georgia, serif;
    letter-spacing: 0.04em;
    background: #5a4010;
    border: 1px solid #3a2808;
    color: #e0d8b8;
    cursor: pointer;
    border-radius: 0;
    white-space: nowrap;
}
.seed-input-row #generate-seed-btn:hover  { background: #6e5018; }
.seed-input-row #generate-seed-btn:active { background: #3a2808; }

/* ── Save-seed row ────────────────────────────────────────────────────────── */
.save-seed-row {
    display: flex;
    gap: 6px;
    margin-bottom: 4px;
}
.save-seed-row input {
    flex: 1;
    padding: 4px 7px;
    font-family: Georgia, serif;
    font-size: 12px;
    border: 1px solid #c0b080;
    background: #fff;
    color: #333;
    box-sizing: border-box;
    border-radius: 0;
    min-width: 0;
}
.save-seed-row input:focus { outline: 1px solid #8a6a20; }
#save-seed-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    font-family: Georgia, serif;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    background: #6a5020;
    border: 1px solid #4a3410;
    cursor: pointer;
    letter-spacing: 0.4px;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}
#save-seed-btn:hover  { background: #7e6228; }
#save-seed-btn:active { background: #4a3410; }

/* ── Saved seeds dropdown ─────────────────────────────────────────────────── */
#saved-seeds-section { display: flex; flex-direction: column; gap: 5px; }

.saved-seeds-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}
.saved-seeds-controls select {
    flex: 1;
    min-width: 0;
}
#saved-seed-del-btn {
    flex-shrink: 0;
    padding: 5px 8px;
    font-family: Georgia, serif;
    font-size: 11px;
    cursor: pointer;
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    background: none;
    color: #888;
    border: 1px solid #c8b880;
}
#saved-seed-del-btn:hover { color: #a00; border-color: #a00; background: #fff0f0; }

.generate-btns {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}
.generate-btns button {
    flex: 1;
    padding: 9px 4px;
    font-family: Georgia, serif;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    background: #3a4a10;
    border: 1px solid #283008;
    cursor: pointer;
    letter-spacing: 0.5px;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}
.generate-btns button:hover  { background: #4a5e18; }
.generate-btns button:active { background: #283008; }


/* ── Disable SVG filters while navigating (huge perf win) ──────────────────── */
#map-viewport.interacting * { filter: none !important; }

/* ── Town popup ──────────────────────────────────────────────────────────────── */
#town-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 30;
    width: 290px;
    max-height: calc(100vh - 80px);
    background: #faf6ec;
    border: 1px solid #b0a080;
    box-shadow: 2px 3px 16px rgba(0,0,0,0.32);
    font-family: Georgia, serif;
    font-size: 13px;
    color: #333;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) translateY(10px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
#town-popup.popup-open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) translateY(0);
}

#town-popup-img {
    width: 100%;
    height: 148px;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

#town-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #ede4cc;
    border-bottom: 1px solid #c0a860;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

#town-popup-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    color: #666;
    padding: 0 2px;
    line-height: 1;
}
#town-popup-close:hover { color: #111; }

#town-popup-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    overflow-y: auto;
}
#town-popup-body::-webkit-scrollbar { width: 5px; }
#town-popup-body::-webkit-scrollbar-track { background: #f0e8d4; }
#town-popup-body::-webkit-scrollbar-thumb { background: #b0a070; }

.popup-section-label {
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #8a7040;
    border-bottom: 1px solid #d8c898;
    padding-bottom: 3px;
    margin-top: 2px;
}
.popup-fact {
    font-size: 12px;
    color: #444;
    line-height: 1.45;
}

/* Amenities list in the town popup should match popup-fact text styling */
.popup-amenities {
    list-style: disc;
    margin: 0;
    padding-left: 1.05em; /* align bullets with paragraph text */
    font-family: inherit;
    font-size: 12px;
    color: #444;
    line-height: 1.45;
}
.popup-amenities li {
    margin: 0 0 4px 0;
}

/* Class Strengths with tooltips */
.focus-strength {
    padding: 2px 4px;
    border-radius: 3px;
    cursor: help;
    transition: background-color 0.2s ease;
    display: inline-block;
}
.focus-strength:hover {
    background-color: rgba(218, 165, 32, 0.2);
}
.popup-fact strong { color: #5a4010; }
