* {
    margin: 0; padding: 0; box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }

:root {
    --bg: #070b12;
    --bg-soft: #0d1524;
    --panel: rgba(12, 18, 30, 0.94);
    --panel-strong: rgba(18, 26, 41, 0.98);
    --border: rgba(158, 174, 202, 0.18);
    --border-strong: rgba(255, 255, 255, 0.12);
    --text: #ecf2ff;
    --dim: #99a6bf;
    --accent: #ffd166;
    --accent-2: #6ee7ff;
    --green: #7ef0a1;
    --red: #ff7a8a;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    background:
        radial-gradient(circle at top left, rgba(110, 231, 255, 0.14), transparent 30%),
        radial-gradient(circle at 80% 20%, rgba(255, 209, 102, 0.14), transparent 24%),
        linear-gradient(180deg, var(--bg-soft), var(--bg));
    color: var(--text);
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 28px 28px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.4), black 16%, black 84%, rgba(0, 0, 0, 0.35));
    opacity: 0.3;
}

#auth-screen {
    overflow-y: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

#auth-screen .box {
    background: linear-gradient(180deg, rgba(21, 30, 46, 0.98), rgba(12, 18, 30, 0.98));
    border: 1px solid var(--border-strong);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    border-radius: 18px;
    padding: 2rem;
    width: min(100%, 360px);
}

#auth-screen h1 {
    font-size: 1.55rem;
    margin-bottom: 1rem;
    color: var(--accent);
    letter-spacing: 0.08em;
}

#auth-screen input {
    display: block;
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    background: rgba(6, 10, 18, 0.78);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    border-radius: 10px;
}

#auth-screen button {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #000;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    margin-right: 0.5rem;
    border-radius: 999px;
}

#auth-screen .error {
    color: var(--red);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.auth-note {
    margin-top: 0.75rem;
    font-size: 0.8rem;
}

#game-screen,
#watch-screen {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    overflow: hidden;
}

.game-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr) 340px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    overflow: hidden;
}

.game-layout .topbar {
    grid-column: 1 / -1;
}

.game-layout .actions {
    grid-column: 1 / -1;
}

.game-layout.nav-active {
    grid-template-columns: minmax(0, 1fr);
}

.left-panel {
    border-right: 1px solid var(--border);
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(8, 13, 21, 0.92), rgba(10, 16, 27, 0.98));
}

.left-panel section {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.015);
}

.left-panel h3 {
    font-size: 0.75rem;
    color: var(--dim);
    text-transform: uppercase;
    margin-bottom: 0.4rem;
    letter-spacing: 0.12em;
}

.left-panel .cell-info {
    font-size: 0.8rem;
    line-height: 1.5;
}

.left-panel .cell-info .label {
    color: var(--dim);
}

.left-panel .cell-info .value {
    color: var(--text);
}

.panel-subtitle {
    font-size: 0.78rem;
    margin-bottom: 0.5rem;
}

.topbar {
    grid-column: 1 / -1;
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(7, 11, 18, 0.82);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
}

.topbar .credits {
    color: var(--accent);
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-link {
    color: var(--dim);
    text-decoration: none;
    font-size: 0.8rem;
}

.topbar-link:hover {
    color: var(--accent);
}

.topbar-link.active {
    color: var(--accent);
}

.nav-frame {
    width: 100%;
    flex: 1;
    min-height: 0;
    border: none;
    background: var(--bg);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.action-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.action-group-label {
    font-size: 0.75rem;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-right: 0.2rem;
}

.action-group + .action-group {
    margin-left: 2rem;
}

.topbar-actions button,
.watch-loader-actions button,
.watch-controls button,
.watch-transport button {
    padding: 0.4rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    border-radius: 999px;
}

.topbar-actions button:hover,
.watch-loader-actions button:hover,
.watch-controls button:hover,
.watch-transport button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.topbar-actions button:disabled,
.watch-loader-actions button:disabled,
.watch-controls button:disabled,
.watch-transport button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.main {
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.game-layout .main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.left-panel .log {
    flex: 1;
    overflow-y: auto;
}

.map-section {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.015);
}

.map-viewport-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#map-viewport {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: grab;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#map-viewport.is-dragging {
    cursor: grabbing;
}

.map-section h3 {
    font-size: 0.75rem;
    color: var(--dim);
    text-transform: uppercase;
    margin-bottom: 0.4rem;
    letter-spacing: 0.12em;
}

.map-controls {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.map-ctrl-btn {
    padding: 0.3rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    border-radius: 999px;
    line-height: 1;
}

.map-ctrl-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.map-section .cell-info {
    font-size: 0.8rem;
    line-height: 1.5;
}

.map-section .cell-info .label {
    color: var(--dim);
}

.map-section .cell-info .value {
    color: var(--text);
}

.log {
    overflow-y: auto;
    min-height: 0;
    padding: 1rem;
    font-size: 0.85rem;
    line-height: 1.6;
    background:
        radial-gradient(circle at top right, rgba(110, 231, 255, 0.08), transparent 24%),
        rgba(4, 8, 15, 0.28);
}

.log .entry {
    margin-bottom: 0;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
}

.log .entry:first-child {
    border-top: 1px solid var(--border);
}

.log .entry.system {
    color: var(--dim);
}

.log .entry.action {
    color: var(--green);
}

.log .entry.error {
    color: var(--red);
}

.log .entry.info {
    color: var(--accent);
}

.actions {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(11, 17, 28, 0.95), rgba(8, 12, 20, 0.98));
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
}

.actions button {
    padding: 0.4rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    border-radius: 999px;
}

.actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.sidebar {
    border-left: 1px solid var(--border);
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(8, 13, 21, 0.92), rgba(10, 16, 27, 0.98));
}

.sidebar section {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.015);
}

.watch-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(11, 17, 28, 0.95), rgba(8, 12, 20, 0.98));
}

.watch-kicker {
    margin-bottom: 0.25rem;
    color: var(--accent-2);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.72rem;
}

.watch-header h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.watch-status {
    font-size: 0.82rem;
}

.watch-loader {
    display: grid;
    gap: 0.65rem;
    align-content: start;
}

.watch-input {
    display: grid;
    gap: 0.35rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--dim);
}

.watch-input input {
    padding: 0.55rem 0.65rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(4, 8, 15, 0.8);
    color: var(--text);
    font-family: inherit;
}

.watch-loader-actions,
.watch-controls,
.watch-transport {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.watch-summary {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.watch-frame-label {
    color: var(--accent);
    font-size: 0.82rem;
    line-height: 1.5;
}

.watch-fallback {
    margin: 0;
    padding: 0.9rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    line-height: 1.55;
    white-space: pre-wrap;
    color: var(--dim);
    background: rgba(4, 8, 15, 0.65);
}

.watch-entry {
    display: grid;
    gap: 0.25rem;
    width: 100%;
    text-align: left;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(3, 7, 12, 0.42);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
}

.watch-entry.is-selected {
    border-color: rgba(110, 231, 255, 0.5);
    box-shadow: 0 0 0 1px rgba(110, 231, 255, 0.12) inset;
}

.watch-entry-title {
    font-size: 0.82rem;
    color: var(--accent);
}

.watch-entry-meta {
    font-size: 0.74rem;
}

.sidebar h3 {
    font-size: 0.75rem;
    color: var(--dim);
    text-transform: uppercase;
    margin-bottom: 0.4rem;
    letter-spacing: 0.12em;
}

.sidebar .cell-info {
    font-size: 0.8rem;
    line-height: 1.5;
}

.sidebar .cell-info .label {
    color: var(--dim);
}

.sidebar .cell-info .value {
    color: var(--text);
}

.sidebar .entity {
    color: var(--accent);
    font-size: 0.8rem;
}

.sidebar .resource {
    color: var(--green);
    font-size: 0.8rem;
}

.kv-list,
.frontier-info,
.frontier-claim-summary,
.slot-list,
.proposal-feedback,
.proposal-fields,
.proposal-group,
.trade-offers,
.inventory-list {
    display: grid;
    gap: 0.35rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.8rem;
}

.detail-row .label {
    color: var(--dim);
}

.detail-row .value {
    color: var(--text);
    text-align: right;
}

.panel-actions,
.proposal-actions,
.claim-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.panel-actions button,
.proposal-actions button,
.claim-controls button,
.slot-card button {
    padding: 0.45rem 0.8rem;
    background: rgba(4, 8, 15, 0.75);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    border-radius: 999px;
}

.panel-actions button:hover,
.proposal-actions button:hover,
.claim-controls button:hover,
.slot-card button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.panel-actions button:disabled,
.proposal-actions button:disabled,
.claim-controls button:disabled,
.slot-card button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.slot-list {
    margin-top: 0.5rem;
}

.slot-card {
    display: grid;
    gap: 0.35rem;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(3, 7, 12, 0.42);
}

.slot-card.selected {
    border-color: rgba(255, 209, 102, 0.55);
    box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.14) inset;
}

.slot-card-header {
    color: var(--accent);
    font-size: 0.84rem;
}

.slot-card-meta {
    font-size: 0.75rem;
}

.proposal-form {
    display: grid;
    gap: 0.85rem;
}

.proposal-field,
.proposal-group {
    display: grid;
    gap: 0.35rem;
}

.proposal-field-label,
.proposal-group legend {
    font-size: 0.74rem;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.proposal-field input,
.proposal-field select {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(4, 8, 15, 0.8);
    color: var(--text);
    font-family: inherit;
}

.proposal-field select.numeric {
    font-weight: 700;
}

.proposal-group {
    padding: 0.7rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(4, 8, 15, 0.45);
}

.proposal-group legend {
    padding: 0 0.2rem;
}

.proposal-group-helper {
    font-size: 0.75rem;
    line-height: 1.4;
}

.proposal-option-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.4rem;
    margin-top: 0.4rem;
}

.proposal-option {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.55rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    font-size: 0.78rem;
}

.claim-summary-grid {
    display: grid;
    gap: 0.45rem;
}

.claim-live {
    display: grid;
    gap: 0.65rem;
}

.claim-expired {
    color: var(--red);
}

.trade-offer {
    display: grid;
    gap: 0.2rem;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
}

.trade-offer:first-child {
    border-top: none;
    padding-top: 0;
}

.trade-offer-note {
    font-size: 0.74rem;
}

.map-fallback,
.slot,
.inventory-item {
    font-size: 0.8rem;
    color: var(--dim);
}

#map-panel {
    padding: 0.5rem;
    transform-origin: center center;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

#map-panel .mermaid {
    background: transparent;
}

#map-panel svg {
    max-width: none;
    height: auto;
    filter: drop-shadow(0 8px 28px rgba(0, 0, 0, 0.35));
}

.map-fallback {
    white-space: pre-wrap;
    line-height: 1.5;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(4, 8, 15, 0.65);
}

.watch-fallback.is-hidden {
    display: none;
}

.tab-bar {
    display: flex;
    gap: 0;
}

.tab-bar button {
    flex: 1;
    padding: 0.4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom: none;
    color: var(--dim);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75rem;
}

.tab-bar button.active {
    color: var(--accent);
    background: var(--panel);
}

.dim-text {
    color: var(--dim);
}

.success {
    color: var(--green);
}

.error {
    color: var(--red);
}

.placeholder {
    color: var(--dim);
}

.is-hidden {
    display: none !important;
}

@media (max-width: 1100px) {
    #game-screen,
    #watch-screen {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-y: auto;
    }

    .layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: visible;
    }

    .game-layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: visible;
    }

    .game-layout .topbar,
    .game-layout .actions {
        grid-column: 1;
    }

    .left-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 40vh;
    }

    .watch-header {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-left: none;
        border-top: 1px solid var(--border);
        min-height: auto;
        max-height: 50vh;
    }

    #map-viewport {
        max-height: 400px;
    }
}

@media (max-width: 720px) {
    #auth-screen {
        align-items: stretch;
    }

    #auth-screen .box {
        width: 100%;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }

    .actions {
        padding-bottom: 1rem;
    }

    .proposal-option-grid {
        grid-template-columns: 1fr 1fr;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .watch-loader-actions,
    .watch-transport,
    .watch-controls {
        width: 100%;
    }

    .watch-loader-actions button,
    .watch-controls button,
    .watch-transport button {
        flex: 1 1 120px;
    }
}
