:root {
    color-scheme: dark;
    --ink: #f4ecd5;
    --muted: #9caab3;
    --line: rgba(244, 236, 213, 0.14);
    --panel: #17212a;
    --panel-raised: #1d2b35;
    --accent: #e7bc68;
    --accent-soft: #8b6b39;
    --cyan: #54b7d6;
}

* {
    box-sizing: border-box;
}

body.chronicle-page {
    min-width: 320px;
    margin: 0;
    background: radial-gradient(circle at 50% 0%, #293b45 0, #101922 42%, #0b1117 100%);
    color: var(--ink);
    font-family: "Segoe UI", "Yu Gothic", sans-serif;
}

.chronicle-shell {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 24px;
}

.chronicle-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}

.eyebrow,
.panel-label {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.16em;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 3px;
    font-family: Georgia, serif;
    font-size: clamp(1.9rem, 4vw, 3.5rem);
    letter-spacing: 0.015em;
}

.subtitle {
    margin-bottom: 0;
    color: var(--muted);
}

.header-stats {
    display: grid;
    gap: 5px;
    min-width: 130px;
    padding: 12px 15px;
    border: 1px solid var(--line);
    background: rgba(15, 24, 31, 0.7);
    text-align: right;
}

.header-stats span {
    color: var(--cyan);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
}

.header-stats strong {
    font-size: 0.76rem;
    color: var(--muted);
}

.header-stats b {
    color: var(--ink);
}

.chronicle-console {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 18px;
    align-items: start;
}

.map-panel,
.control-panel {
    min-width: 0;
}

.map-frame {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #101922;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

#ck-canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
    image-rendering: pixelated;
    cursor: crosshair;
}

.map-help {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 4px 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.move-legend {
    white-space: nowrap;
}

.move-legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin: 0 3px 0 6px;
    border: 1px solid currentColor;
    vertical-align: -1px;
}

.move-legend-ok {
    background: rgba(84, 183, 214, 0.65);
    color: var(--cyan);
}

.move-legend-blocked {
    background: rgba(217, 93, 122, 0.55);
    color: #d95d7a;
}

kbd {
    padding: 1px 5px;
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--ink);
    font-family: inherit;
    font-size: 0.68rem;
}

.control-panel {
    display: grid;
    gap: 12px;
}

.panel-card {
    padding: 14px;
    border: 1px solid var(--line);
    background: rgba(23, 33, 42, 0.9);
}

.identity-card h2,
.selection-card h2 {
    margin-bottom: 10px;
    font-family: Georgia, serif;
}

.identity-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-top: 7px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.78rem;
}

.identity-row strong {
    color: var(--ink);
}

.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.metric {
    display: grid;
    gap: 4px;
}

.metric span {
    color: var(--muted);
    font-size: 0.72rem;
}

.metric strong {
    font-size: 1.15rem;
}

.research-metric {
    grid-column: 1 / -1;
}

.selection-card p {
    min-height: 38px;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 0.82rem;
}

.unit-stack {
    display: grid;
    gap: 5px;
    margin: -4px 0 12px;
}

.unit-stack[hidden] {
    display: none;
}

.unit-stack-label {
    color: var(--muted);
    font-size: 0.72rem;
}

.unit-stack-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
}

.unit-stack-list button {
    min-height: 30px;
    padding: 4px 6px;
    border: 1px solid var(--line);
    background: #20303a;
    color: var(--ink);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
}

.unit-stack-list button.selected {
    border-color: var(--accent);
    background: var(--panel-raised);
}

.selection-actions,
.result-actions,
.seed-row {
    display: flex;
    gap: 8px;
}

.improvement-actions {
    display: grid;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.improvement-actions > span {
    color: var(--muted);
    font-size: 0.72rem;
}

.improvement-actions > div {
    display: flex;
    gap: 6px;
}

.improvement-actions .button {
    flex: 1;
    min-height: 30px;
    padding: 4px 6px;
    font-size: 0.72rem;
}

label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.78rem;
}

input,
select {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    background: #0d151b;
    color: var(--ink);
    font: inherit;
}

input {
    min-width: 0;
    padding: 7px 9px;
}

select {
    padding: 7px;
}

.button,
.tech-list button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--panel-raised);
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-size: 0.8rem;
    text-decoration: none;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.button:hover,
.tech-list button:hover {
    border-color: var(--accent);
    background: #2a3a45;
}

.button:active,
.tech-list button:active {
    transform: translateY(1px);
}

.button.primary {
    border-color: var(--accent-soft);
    background: #6d542e;
    color: #fff1c9;
}

.button.quiet {
    color: var(--muted);
}

.button.wide {
    width: 100%;
}

.button:disabled,
select:disabled {
    cursor: not-allowed;
    opacity: 0.42;
}

.technology-card {
    min-height: 100px;
}

.production-status {
    display: grid;
    gap: 7px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.production-status[hidden] {
    display: none;
}

.production-summary {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 0.76rem;
}

.production-summary strong {
    color: var(--ink);
}

.production-track {
    height: 8px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #0d151b;
}

.production-track span {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--accent));
    transition: width 160ms ease;
}

.production-status small {
    color: var(--muted);
    font-size: 0.7rem;
}

.research-status {
    display: grid;
    gap: 6px;
    margin: 8px 0 10px;
    padding: 8px;
    border: 1px solid var(--line);
    background: rgba(13, 21, 27, 0.55);
}

.research-summary {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.76rem;
}

.research-summary strong,
.research-status small {
    color: var(--muted);
}

.research-track {
    height: 7px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #0d151b;
}

.research-track span {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, #8cc8e0, #8e7ee8);
    transition: width 160ms ease;
}

.research-status small {
    font-size: 0.68rem;
}

.city-details {
    display: grid;
    gap: 9px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.city-details[hidden] {
    display: none;
}

.city-detail-block {
    display: grid;
    gap: 5px;
}

.city-detail-label {
    color: var(--muted);
    font-size: 0.7rem;
}

.tag-list,
.compact-list {
    color: var(--ink);
    font-size: 0.72rem;
    line-height: 1.45;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tag-list span {
    padding: 2px 5px;
    border: 1px solid var(--line);
    background: #20303a;
}

.growth-table {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    color: var(--muted);
    font-size: 0.68rem;
}

.growth-table span {
    padding: 4px;
    border: 1px solid var(--line);
    text-align: center;
}

.growth-table strong {
    display: block;
    margin-top: 2px;
    color: var(--ink);
    font-size: 0.74rem;
}

.terrain-details {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 0.74rem;
    line-height: 1.45;
}

.terrain-details strong {
    color: var(--ink);
    font-size: 0.95rem;
}

.terrain-legend {
    display: grid;
    gap: 3px;
    margin-top: 9px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.67rem;
    line-height: 1.35;
}

.diplomacy-list {
    display: grid;
    gap: 8px;
}

.diplomacy-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    align-items: center;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--line);
}

.diplomacy-row:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.diplomacy-name {
    display: grid;
    gap: 2px;
}

.diplomacy-name strong {
    font-size: 0.78rem;
}

.diplomacy-name small {
    color: var(--muted);
    font-size: 0.68rem;
}

.diplomacy-actions {
    display: flex;
    gap: 4px;
}

.diplomacy-actions .button {
    min-height: 28px;
    padding: 3px 6px;
    font-size: 0.68rem;
}

.tech-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.tech-list button {
    min-height: 32px;
    padding: 4px 6px;
    font-size: 0.7rem;
}

.tech-list button.selected {
    border-color: var(--cyan);
    color: #d9f5ff;
}

.log-card pre {
    min-height: 100px;
    margin: 0;
    overflow: auto;
    color: var(--muted);
    font-family: "Cascadia Mono", Consolas, monospace;
    font-size: 0.7rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

.panel-actions {
    display: grid;
    gap: 8px;
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(8, 14, 18, 0.76);
}

.overlay[hidden] {
    display: none;
}

.overlay-card {
    width: min(440px, 100%);
    padding: clamp(22px, 4vw, 40px);
    border: 1px solid rgba(231, 188, 104, 0.45);
    background: #17212a;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.36);
}

.overlay-card h2 {
    margin-bottom: 12px;
    font-family: Georgia, serif;
    font-size: clamp(1.7rem, 4vw, 2.7rem);
}

.overlay-card > p:not(.eyebrow) {
    color: var(--muted);
    line-height: 1.7;
}

.seed-row {
    margin-bottom: 14px;
}

.seed-row .button {
    white-space: nowrap;
}

.overlay-card > .button {
    width: 100%;
}

.event-options {
    display: grid;
    gap: 8px;
}

.event-options .button,
.event-options button {
    justify-content: flex-start;
    text-align: left;
}

@media (max-width: 980px) {
    .chronicle-console {
        grid-template-columns: 1fr;
    }

    .control-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }

    .identity-card,
    .selection-card,
    .technology-card,
    .diplomacy-card,
    .log-card,
    .panel-actions {
        grid-column: span 2;
    }
}

@media (max-width: 620px) {
    .chronicle-shell {
        padding: 14px;
    }

    .chronicle-header {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .header-stats {
        text-align: left;
    }

    .map-help {
        flex-direction: column;
        font-size: 0.68rem;
    }

    .control-panel {
        grid-template-columns: 1fr;
    }

    .identity-card,
    .selection-card,
    .technology-card,
    .diplomacy-card,
    .log-card,
    .panel-actions {
        grid-column: auto;
    }

    .metric-grid {
        grid-template-columns: 1fr 1fr;
    }
}
