:root {
    --bg-1: #1b2a1b;
    --bg-2: #132014;
    --panel: #1f3a2b;
    --panel-dark: #14281e;
    --accent: #d8c178;
    --accent-2: #6dbf75;
    --text: #e7f2e2;
    --danger: #d25f5f;
    --warn: #e0b84f;
    --shadow: rgba(0, 0, 0, 0.45);
    --legend-offset: 190px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Chakra Petch", "Press Start 2P", "Consolas", monospace;
    background: radial-gradient(circle at top, #243924 0%, var(--bg-1) 40%, var(--bg-2) 100%);
    color: var(--text);
    min-height: 100vh;
    overscroll-behavior: none;
}

.app {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    touch-action: none;
    overscroll-behavior: none;
}

.ui-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.panel {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-dark) 100%);
    border: 2px solid #2b5237;
    box-shadow: 0 6px 0 #0c1b12, 0 12px 24px var(--shadow);
    padding: 8px 10px;
    border-radius: 6px;
    pointer-events: auto;
    touch-action: manipulation;
}

.panel-title {
    font-size: 18px;
    letter-spacing: 1px;
    color: var(--accent);
    margin-bottom: 8px;
    text-shadow: 0 2px 0 #0d1c12;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.fps-readout {
    display: none;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 11px;
    letter-spacing: 0.3px;
    color: var(--accent-2);
    background: rgba(12, 27, 18, 0.45);
    border-radius: 3px;
    padding: 2px 6px;
}

.fps-readout.is-visible {
    display: inline-flex;
}

.label {
    font-size: 10px;
    color: #b9cfb5;
}

.value {
    font-size: 16px;
    margin-top: 2px;
}

.sub {
    font-size: 10px;
    color: #c2d9be;
}

.hud-row .sub {
    text-align: center;
}

.hud-health-label {
    font-size: 12px;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}

.hud-score-label {
    font-size: 11px;
    letter-spacing: 0.4px;
}

.hud-score {
    text-align: center;
    width: 100%;
}

.hud-score-value {
    font-size: 48px;
    line-height: 1;
    margin: 0;
    color: #e7f0db;
    position: relative;
    z-index: 1;
}

.hud-score-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 4px;
    align-items: stretch;
}

.hud-score-block {
    display: grid;
    justify-items: center;
    gap: 2px;
    grid-template-rows: auto 1fr;
    min-height: 70px;
    align-content: stretch;
}

.hud-score-content {
    min-height: 48px;
    display: grid;
    place-items: center;
}

.capture-dial {
    --dial-color: #8bbf63;
    --dial-angle: -90deg;
    width: 86px;
    height: 48px;
    margin: 0;
    position: relative;
    top: -10px;
}

.capture-dial-wrap {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.pressure-leds {
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
    height: 48px;
    padding-bottom: 2px;
    justify-content: flex-start;
}

.pressure-leds .led {
    width: 7px;
    height: 5px;
    border-radius: 2px;
    background: linear-gradient(180deg, rgba(60, 16, 16, 0.9), rgba(24, 7, 7, 0.9));
    box-shadow: inset 0 0 0 1px rgba(255, 140, 140, 0.12);
}

.led-pressure.on {
    background: linear-gradient(180deg,
        var(--led-color, #ff7a6a) 0%,
        var(--led-color-mid, #d64a3a) 55%,
        var(--led-color-dark, #9f2a23) 100%);
    box-shadow: 0 0 6px rgba(255, 110, 98, 0.65), inset 0 0 3px rgba(255, 255, 255, 0.35);
}

.capture-dial-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.capture-dial-track,
.capture-dial-progress {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
}

.capture-dial-track {
    stroke: #243727;
    opacity: 0.8;
}

.capture-dial-progress {
    stroke: var(--dial-color);
    filter: drop-shadow(0 0 4px rgba(120, 200, 120, 0.2));
    stroke-dasharray: 0 126;
}

.capture-dial-needle {
    position: absolute;
    left: 50%;
    bottom: 4px;
    width: 2px;
    height: 24px;
    background: #e7f0db;
    transform-origin: 50% 100%;
    transform: translateX(-50%) rotate(var(--dial-angle));
    box-shadow: 0 0 4px rgba(231, 240, 219, 0.3);
}

.capture-dial-needle::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -2px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d7e4c9;
    transform: translateX(-50%);
    box-shadow: 0 0 4px rgba(215, 228, 201, 0.35);
}

.btn {
    font-family: inherit;
    font-size: 11px;
    padding: 6px 8px;
    min-height: 34px;
    border-radius: 4px;
    background: #2c4a35;
    border: 1px solid #4f7a57;
    color: var(--text);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: inset 0 0 0 1px #1a2c21;
    touch-action: manipulation;
}

.btn:hover {
    background: #386345;
}

.btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(216, 193, 120, 0.3);
}

.btn:disabled,
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.warning {
    border-color: var(--warn);
}

.btn.invalid {
    border-color: var(--danger);
}

.hud {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 280px;
}

.hud-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 6px;
}

.select-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

select {
    font-family: inherit;
    font-size: 11px;
    padding: 6px 8px;
    min-height: 34px;
    border-radius: 4px;
    background: #203a2a;
    border: 1px solid #4f7a57;
    color: var(--text);
    cursor: pointer;
}

.select-row {
    align-items: flex-end;
}

.select-row .select-group {
    flex: 1;
}

.palette {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 180px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
}

.section-title {
    font-size: 11px;
    margin: 8px 0 6px;
    color: #c9e1c4;
}

.tool-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-with-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-icon {
    width: 18px;
    text-align: center;
    pointer-events: none;
}

.btn-label {
    display: inline-block;
}

.plant-icon {
    width: 20px;
    height: 20px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

#terrainToolsTitle,
#terrainTools {
    display: none;
}

.inspector {
    position: absolute;
    bottom: 12px;
    left: 12px;
    width: 280px;
}

.inspect-content {
    font-size: 11px;
    line-height: 1.4;
    margin-bottom: 8px;
}

.help {
    position: absolute;
    bottom: 12px;
    right: 210px;
    width: 260px;
}

.help-text {
    font-size: 10px;
    line-height: 1.4;
    color: #cbdcc6;
}

.modal {
    position: absolute;
    inset: 0;
    background: rgba(8, 12, 8, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 30;
}

.modal-card {
    background: linear-gradient(180deg, #203528 0%, #111f17 100%);
    border: 2px solid #3c6145;
    padding: 16px;
    width: min(320px, 90vw);
    box-shadow: 0 12px 30px var(--shadow);
    border-radius: 6px;
}

.howto-card {
    width: min(520px, 94vw);
}

.howto-section {
    margin-bottom: 12px;
}

.howto-title {
    font-size: 12px;
    margin-bottom: 6px;
    color: var(--accent);
}

.howto-section p {
    font-size: 11px;
    line-height: 1.4;
    margin-bottom: 4px;
}

.modal-card p {
    font-size: 12px;
    margin: 10px 0 12px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.onboard-tooltip {
    position: absolute;
    max-width: 220px;
    padding: 10px 12px;
    background: linear-gradient(180deg, #1e3326 0%, #13251a 100%);
    border: 2px solid #3c6145;
    border-radius: 6px;
    color: #e1f0d7;
    font-size: 11px;
    line-height: 1.4;
    box-shadow: 0 10px 18px var(--shadow);
    pointer-events: none;
    z-index: 20;
}

.onboard-tooltip::after {
    content: "";
    position: absolute;
    right: -10px;
    top: 18px;
    border-left: 10px solid #3c6145;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

.splash-card {
    width: min(66vw, 900px);
    padding: 16px;
}

.splash-art {
    width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #2b5237;
    background: #142217;
}

.splash-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.splash-actions {
    margin-top: 12px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.splash-hint {
    font-size: 9px;
    color: rgba(219, 233, 215, 0.55);
    text-align: center;
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.save-led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #0e2a15;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.save-led.on {
    background: #3bff4c;
    box-shadow: 0 0 6px rgba(59, 255, 76, 0.9);
}

.splash-footer {
    margin-top: 10px;
    font-size: 9px;
    text-align: center;
    color: rgba(219, 233, 215, 0.5);
}

.howto-secret {
    font-size: 9px;
    color: rgba(219, 233, 215, 0.55);
    margin-top: 8px;
    text-align: center;
}

.hidden {
    display: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.legend {
    position: absolute;
    bottom: var(--legend-offset);
    left: 12px;
    width: 280px;
}

.led-meter {
    display: flex;
    gap: 3px;
    margin: 4px 0 6px;
}

.led {
    width: 10px;
    height: 6px;
    border-radius: 2px;
    background: #0f1b14;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.led-water.on {
    background: var(--led-color, #5aa8ff);
    box-shadow: 0 0 6px rgba(90, 168, 255, 0.55);
}

.led-health.on {
    background: var(--led-color, #67c66b);
    box-shadow: 0 0 6px rgba(103, 198, 107, 0.5);
}

.led-time {
    background: var(--led-color, #1a2c4a);
    opacity: 0.6;
    width: 8px;
}

.led-time.on {
    opacity: 1;
    box-shadow: 0 0 6px rgba(120, 180, 255, 0.6);
}

.legend-section {
    margin-bottom: 8px;
}

.legend-title {
    font-size: 11px;
    color: #c9e1c4;
    margin-bottom: 4px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: #dbe9d7;
}

.legend-count {
    color: #b4c7b0;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0d1c12;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.legend-image,
.legend-canvas {
    width: 24px;
    height: 24px;
    border-radius: 2px;
    border: 1px solid #0d1c12;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    background: #17281f;
    image-rendering: pixelated;
}

.legend-image {
    display: inline-block;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}

.legend-canvas {
    display: inline-block;
    background: #2a3f32;
}

.terrain-water { background: var(--legend-water, #2d78a6); }
.terrain-mud { background: var(--legend-mud, #5b4634); }
.terrain-peat { background: var(--legend-peat, #4a3533); }
.terrain-grass { background: var(--legend-grass, #3e8c3d); }
.terrain-sand { background: var(--legend-sand, #d8c793); }

.plant-sundew { background-image: url("sundew.png"); }
.plant-pitcher { background-image: url("pitcher.png"); }
.plant-flytrap { background-image: url("venus.png"); }

.controls {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 180px;
    touch-action: none;
}

.debug-panel {
    position: absolute;
    right: 12px;
    bottom: 200px;
    width: 220px;
}

.debug-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin: 6px 0 2px;
    font-size: 10px;
    color: #c2d9be;
}

.debug-panel input[type="range"] {
    width: 100%;
}

.debug-hint {
    margin-top: 6px;
    font-size: 9px;
    color: rgba(219, 233, 215, 0.55);
    text-align: center;
}

.controls-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
}

.dpad-btn {
    min-width: 32px;
    min-height: 32px;
    padding: 4px;
}

.dpad-btn[data-pan="up"] {
    grid-column: 2;
    grid-row: 1;
}

.dpad-btn[data-pan="left"] {
    grid-column: 1;
    grid-row: 2;
}

.dpad-btn[data-pan="right"] {
    grid-column: 3;
    grid-row: 2;
}

.dpad-btn[data-pan="down"] {
    grid-column: 2;
    grid-row: 2;
}

.zoom-group {
    display: flex;
    flex-direction: row;
    gap: 6px;
    width: 100%;
}

.zoom-btn {
    flex: 1;
    min-width: 0;
    min-height: 32px;
    padding: 4px;
    touch-action: none;
}

@media (max-width: 900px) {
    .hud,
    .palette,
    .inspector,
    .help,
    .legend {
        width: 180px;
    }

    .help {
        right: 190px;
    }

    .tool-grid {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    :root {
        --legend-offset: 220px;
    }

    .hud {
        width: 200px;
    }

    .palette {
        width: 160px;
    }

    .inspector,
    .help,
    .legend {
        width: 200px;
    }

    .btn {
        padding: 8px 10px;
        font-size: 10px;
        min-height: 44px;
    }

    .help {
        bottom: 200px;
        right: 12px;
    }

    .legend {
        bottom: 220px;
    }


    .controls {
        width: 160px;
    }

    .dpad {
        width: 96px;
    }
}
