/* =========================================================================
   Hexlands / Spacewar
   Zwei Spielwelten, eine Oberfläche. Alle Farben kommen aus CSS-Variablen,
   die auf .app.theme-* liegen; darunter fragt niemand mehr nach dem Theme.
   Layout: Handy zuerst (Flex-Spalte mit Reitern), Desktop ab 960px als Raster.
   ========================================================================= */

:root {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg, #070b16);
    color: var(--ink, #e6edfb);
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

/* --- Paletten ---------------------------------------------------------- */

.app.theme-space {
    --bg: #070b16;
    --bar: #0b1220;
    --surface: #101a30;
    --surface-2: #16233f;
    --surface-3: #1c2c4d;
    --ink: #e6edfb;
    --ink-strong: #ffffff;
    --muted: #8d9cbb;
    --line: #24304d;
    --accent: #4fc3dd;
    --accent-ink: #04212b;
    --accent-2: #27a37a;
    --error: #ff7a70;
    --board-bg: #080d1c;
    --shadow: 0 2px 14px rgba(0, 0, 0, .5);
}

.app.theme-classic {
    --bg: #1d2a3a;
    --bar: #142030;
    --surface: #f7f3ea;
    --surface-2: #eee7d8;
    --surface-3: #e3d9c4;
    --ink: #22201c;
    --ink-strong: #100f0d;
    --muted: #6b6559;
    --line: #cec4b1;
    --accent: #c9662a;
    --accent-ink: #fff;
    --accent-2: #2f7d3a;
    --error: #b23a2c;
    --board-bg: #4f9bd1;
    --shadow: 0 2px 10px rgba(0, 0, 0, .3);
}

/* --- Grundgerüst ------------------------------------------------------- */

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
}

.topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: baseline;
    gap: .8rem;
    padding: .5rem 1rem;
    padding-top: calc(.5rem + env(safe-area-inset-top, 0px));
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    background: var(--bar);
    color: #f2f6ff;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.topbar .brand {
    color: #f2f6ff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: .04em;
    white-space: nowrap;
}
.topbar .tagline {
    color: #9fb0cc;
    font-size: .85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.content {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Nur die Spielansicht füllt randlos; alles andere bekommt Luft und darf scrollen. */
.content > :not(.game) {
    padding: 1rem;
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
}

.home, .lobby { width: 100%; max-width: 640px; margin: 0 auto; }

/* --- Bausteine --------------------------------------------------------- */

.card {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.card h1, .card h2, .card h3, .card h4 { margin: 0 0 .6rem; }
.card h1 { font-size: 1.4rem; }
.card h2 { font-size: 1.1rem; }
.card h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.card h4 { font-size: .95rem; }

label { display: block; margin: .7rem 0; font-size: .9rem; color: var(--muted); }

input, select {
    display: block;
    width: 100%;
    max-width: 320px;
    margin-top: .3rem;
    padding: .55rem .7rem;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink);
    /* 16px verhindert, dass iOS beim Fokus in das Feld hineinzoomt. */
    font: inherit;
    font-size: 16px;
}
input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.row select, .row input { display: inline-block; width: auto; margin: 0; }
.code-input { text-transform: uppercase; letter-spacing: .18em; font-weight: 700; }

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    font: inherit;
    padding: .5rem .9rem;
    min-height: 44px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
    margin: .2rem .2rem .2rem 0;
    touch-action: manipulation;
}
button:hover:not(:disabled), .button:hover { background: var(--surface-3); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary, .button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}
button.primary:hover:not(:disabled), .button.primary:hover { filter: brightness(1.08); }
button.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
button.small { padding: .3rem .7rem; min-height: 36px; font-size: .85rem; }
button.tiny { padding: 0 .5rem; min-height: 32px; min-width: 32px; font-size: .9rem; }
button.big { font-size: 1.15rem; padding: .7rem 1.6rem; min-height: 52px; }
button.block, .button.block { display: flex; width: 100%; margin-left: 0; margin-right: 0; }

.row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.row label { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--error); font-weight: 600; }

.badge {
    display: inline-block;
    font-size: .7rem;
    padding: .1rem .45rem;
    margin-left: .3rem;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--ink);
    vertical-align: middle;
}
.badge.warn { background: var(--accent); color: var(--accent-ink); }

.swatch {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, .4);
    margin-right: .4rem;
    vertical-align: middle;
}

code {
    background: var(--surface-2);
    border: 1px solid var(--line);
    padding: .1rem .4rem;
    border-radius: 5px;
    word-break: break-all;
    font-size: .85em;
}

.invite { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; font-size: .9rem; }

.player-list { list-style: none; padding: 0; margin: 0 0 .6rem; }
.player-list li { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; padding: .35rem 0; border-top: 1px solid var(--line); }
.player-list li:first-child { border-top: 0; }
.pname { font-weight: 600; }

.rules p { font-size: .9rem; line-height: 1.55; color: var(--ink); }

/* --- Spielansicht: Handy ----------------------------------------------- */

.game {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.board-pane {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--board-bg);
}

.sidebar {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: .8rem .8rem 0;
}
.pane { margin-bottom: .8rem; }

/* Genau ein Bereich ist sichtbar — welcher, sagt die Klasse am .game-Element.
   Bewusst nur auf schmalen Schirmen: am Desktop steht alles nebeneinander, und
   diese Regeln dürfen dort gar nicht erst greifen (Spezifität schlägt sonst zurück). */
@media (max-width: 959.98px) {
    /* Die Aktionsleiste steht im Markup vor der Seitenspalte, gehört aber immer direkt
       über die Reiterleiste — sonst rutscht sie nach oben, sobald das Brett verborgen ist. */
    .board-pane { order: 1; }
    .sidebar { order: 2; }
    .dock { order: 3; }
    .tabbar { order: 4; }

    .game.tab-board .sidebar { display: none; }
    .game:not(.tab-board) .board-pane { display: none; }
    .game.tab-hand .pane:not(.pane-hand) { display: none; }
    .game.tab-trade .pane:not(.pane-trade) { display: none; }
    .game.tab-players .pane:not(.pane-players) { display: none; }
    .game.tab-log .pane:not(.pane-log) { display: none; }
}

/* Statusleiste liegt über dem Brett und fängt keine Tipper ab. */
.status-bar {
    position: absolute;
    left: .5rem;
    right: 3.6rem;
    top: .5rem;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem .9rem;
    align-items: center;
    padding: .45rem .7rem;
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border: 1px solid var(--line);
    color: var(--ink);
    font-size: .85rem;
    line-height: 1.3;
    box-shadow: var(--shadow);
    pointer-events: none;
}
.status-bar .dice { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Der Kampfbericht sitzt unten links über dem Brett — dort verdeckt er weder die Statusleiste
   noch die Felder, an denen gerade gehandelt wird. Er verschwindet mit dem Zugende von selbst. */
.battle {
    position: absolute;
    left: .5rem;
    bottom: .5rem;
    max-width: min(19rem, calc(100% - 1rem));
    padding: .45rem .6rem;
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border: 1px solid var(--line);
    border-left: 4px solid var(--line);
    color: var(--ink);
    font-size: .8rem;
    line-height: 1.35;
    box-shadow: var(--shadow);
    pointer-events: none;
}
/* Ausgang des Kampfes an der Kante, damit man ihn erkennt, bevor man liest. */
.battle.won { border-left-color: #c0392b; }
.battle.held { border-left-color: var(--accent-2); }

.battle-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .4rem;
}
.battle-head span { font-variant-numeric: tabular-nums; opacity: .8; white-space: nowrap; }

/* Viele Runden dürfen die Karte nicht sprengen: ab einer Höhe wird gescrollt. */
.battle-rounds {
    margin: .3rem 0;
    max-height: 7.5rem;
    overflow-y: auto;
}
.battle-round {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: .06em;
}
.dice-set { min-width: 3.4rem; }
.dice-set.atk { text-align: right; color: #e08074; }
.dice-set.def { text-align: left; color: var(--accent-2); }
.battle-sep { opacity: .65; }

.battle-foot { opacity: .8; }

/* Aktionsleiste: was gerade dran ist, immer in Daumenreichweite. */
.dock {
    flex: 0 0 auto;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: .5rem .6rem;
}
.dock-row {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    align-items: center;
    font-size: .9rem;
}
/* Bewusst umbrechen statt seitlich scrollen: „Zug beenden" darf nie hinter dem
   Rand verschwinden, und ein waagerechter Scroller sieht aus wie eine volle Zeile. */
.dock-row.build > .chip { flex: 0 0 auto; }
.dock-row.build > .primary { flex: 1 0 100%; margin-left: 0; margin-right: 0; }
.dock-row.winner { justify-content: space-between; }
.dock-row.winner strong { font-size: 1.05rem; }

/* Der eigene Bestand, immer sichtbar. Sechs Rohstoff-Plaketten plus Preisknopf müssen
   auf ein schmales Handy passen, deshalb sind die Innenabstände so knapp. */
.dock-hand {
    display: flex;
    align-items: center;
    gap: .2rem;
    margin: -.1rem 0 .45rem;
    padding-bottom: .45rem;
    border-bottom: 1px solid var(--line);
}
.dock-hand .res {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .1rem;
    min-height: 36px;
    padding: .15rem .1rem;
    margin: 0;
    border: 1px solid var(--line);
    border-bottom: 2px solid var(--rc, var(--line));
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--ink);
    font-size: .82rem;
    line-height: 1;
}
.dock-hand .res .ri { font-size: 1rem; }
.dock-hand .res b { font-variant-numeric: tabular-nums; font-size: .95rem; }
/* Leere Stapel bleiben lesbar, treten aber zurück — sonst sucht das Auge sie ständig ab.
   Gedämpft wird nur der Inhalt: läge die Blende auf dem ganzen Kästchen, verblasste auch
   die Zahl, die gerade erklärt, warum der Stapel leer ist. */
.dock-hand .res.zero > .ri, .dock-hand .res.zero > b { opacity: .45; }
.dock-hand .res.prices {
    flex: 0 0 auto;
    min-width: 40px;
    border-bottom-color: var(--accent);
    cursor: pointer;
}
.dock-hand .res.prices .ri { font-size: 1.15rem; }
.dock-hand .res.prices:hover { background: var(--surface-3); }

.chip {
    border-radius: 999px;
    padding: .45rem .85rem;
    white-space: nowrap;
    margin: 0;
}
.chip.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

/* Kampf-Chips heben sich ab: sie kosten Einheiten statt Gebäude und sind pro Zug begrenzt.
   Ein anderer Farbton warnt vor Zügen, die man nicht zurücknehmen kann. */
.chip.war { border-color: color-mix(in srgb, #c0392b 55%, var(--line)); }
.chip.war.active { background: #c0392b; border-color: #c0392b; color: #fff; }
.chip.war:disabled { opacity: .45; }

/* Reiterleiste am unteren Rand. */
.tabbar {
    flex: 0 0 auto;
    display: flex;
    background: var(--bar);
    border-top: 1px solid rgba(255, 255, 255, .08);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar button {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .1rem;
    margin: 0;
    padding: .35rem .1rem;
    min-height: 52px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #93a4c2;
    font-size: .68rem;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tabbar button .ti { font-size: 1.15rem; line-height: 1.2; }
.tabbar button:hover:not(:disabled) { background: rgba(255, 255, 255, .05); }
.tabbar button.active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

/* Abwerfen blockiert das Spiel, also auch den Bildschirm. */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    background: rgba(3, 6, 14, .72);
    backdrop-filter: blur(2px);
}
.modal {
    width: 100%;
    max-width: 420px;
    max-height: 85dvh;
    overflow-y: auto;
    margin: 0;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.modal-head h3 { flex: 1 1 auto; }
.modal-head button { flex: 0 0 auto; margin: -.2rem -.2rem 0 0; }

/* Preisliste. Bewusst eine Tabelle: drei Spalten, die untereinander fluchten sollen. */
.prices-modal { max-width: 460px; }
.costs h4 { margin: 1rem 0 .4rem; }
.costs h4:first-child { margin-top: 0; }
.cost-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
/* Kein nowrap: „Ruhmpunkt (Technologie)" und Konsorten sprengen sonst die Tabelle
   über den Bildschirmrand hinaus, weil eine Tabelle nicht unter ihre Mindestbreite schrumpft. */
.cost-table th {
    text-align: left;
    font-weight: 600;
    padding: .4rem .5rem .4rem .35rem;
    border-bottom: 1px solid var(--line);
}
.cost-table td {
    padding: .4rem .35rem;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
}
.cost-table tr:last-child th, .cost-table tr:last-child td { border-bottom: 0; }
.cost-cells { width: 100%; }
.cost-vp { text-align: right; font-size: .8rem; line-height: 1.25; }
/* Was man sich leisten kann, soll man auf einen Blick sehen — deshalb Fläche statt nur Textfarbe. */
.cost-table tr.ok th { color: var(--accent-2); }
.cost-table tr.ok { background: color-mix(in srgb, var(--accent-2) 14%, transparent); }
.cost-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin-right: .15rem;
    border-radius: 7px;
    background: var(--surface-2);
    border-bottom: 2px solid var(--rc, var(--line));
    font-size: .95rem;
}
.rates { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }
.rate {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    padding: .25rem .45rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-bottom: 2px solid var(--rc, var(--line));
    font-size: .82rem;
    font-variant-numeric: tabular-nums;
}
.rate.good { color: var(--accent-2); font-weight: 700; }
.rate .ri { font-size: .95rem; }

/* --- Spielansicht: Desktop --------------------------------------------- */

@media (min-width: 960px) {
    .game {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 400px;
        grid-template-rows: minmax(0, 1fr) auto;
        grid-template-areas:
            "board side"
            "dock  side";
        gap: .8rem;
        padding: .8rem;
    }
    .board-pane { grid-area: board; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
    .dock { grid-area: dock; border: 1px solid var(--line); border-radius: var(--radius); }
    .sidebar { grid-area: side; padding: 0; overflow-y: auto; }
    .tabbar { display: none; }

    /* Am Desktop ist Platz genug, da rückt „Zug beenden" ans rechte Ende der Reihe. */
    .dock-row.build > .primary { flex: 0 0 auto; margin-left: auto; }

    /* Auf der breiten Leiste würden die Plaketten sonst auf Handtellergröße auseinandergezogen. */
    .dock-hand { gap: .3rem; }
    .dock-hand .res { flex: 0 0 auto; min-width: 58px; padding: .15rem .5rem; }
}

/* --- Brett: Ausschnitt, Fläche, Werkzeuge ------------------------------ */

.board-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--board-bg);
    /* Wischen und Kneifen gehören board.js, nicht dem Browser. */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.board-canvas {
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    will-change: transform;
}
.board { width: 100%; height: 100%; display: block; }

.board-tools {
    position: absolute;
    right: .5rem;
    bottom: .5rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
.board-tool {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    font-size: 1.1rem;
    line-height: 1;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    box-shadow: var(--shadow);
}

/* --- Brett: SVG -------------------------------------------------------- */

.hex.clickable { cursor: pointer; }
.hex-fill { stroke: rgba(0, 0, 0, .35); stroke-width: 1.5; }
.hex-highlight { fill: rgba(255, 255, 255, .22); stroke: #fff; stroke-width: 3; }
.hex.clickable:hover .hex-highlight { fill: rgba(255, 255, 255, .42); }

/* Das gewählte Ausgangsfeld eines Angriffs — läuft, damit klar ist, dass noch ein Ziel fehlt. */
.hex-selected {
    fill: none;
    stroke: #fff;
    stroke-width: 4;
    stroke-dasharray: 10 7;
    animation: hex-march 1.4s linear infinite;
}

@keyframes hex-march {
    to { stroke-dashoffset: -34; }
}

/* Besetztes Feld: Ring in der Farbe des Besatzers, sichtbar auch ohne Zoom. */
.hex-held {
    fill: none;
    stroke-width: 4;
    stroke-opacity: .95;
    stroke-dasharray: 7 5;
}

/* Geländesymbol im Feld. text-shadow greift in SVG nicht, deshalb ein Konturstrich. */
.hex-icon {
    font-size: 27px;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, .35);
    stroke-width: 2.5;
    stroke-linejoin: round;
}

.unit-badge circle { stroke: rgba(0, 0, 0, .6); stroke-width: 1.6; }

.unit-badge text {
    font-size: 14px;
    font-weight: 800;
    fill: #fff;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, .5);
    stroke-width: 2.5;
}

.token { font-size: 15px; font-weight: 700; }
.pip { }
.port-label { font-size: 11px; font-weight: 700; }

.building { stroke: rgba(0, 0, 0, .55); stroke-width: 1.6; }
.road { stroke-width: 8; stroke-linecap: round; }
.road-outline { stroke: rgba(0, 0, 0, .45); stroke-width: 12; stroke-linecap: round; }

/* Unsichtbare, großzügige Trefferflächen: der Daumen ist breiter als der Weg. */
.hit {
    fill: transparent;
    stroke: transparent;
    stroke-width: 26;
    stroke-linecap: round;
    pointer-events: all;
    cursor: pointer;
}
.vertex-target, .edge-target { cursor: pointer; }
.vertex-highlight { fill: rgba(255, 255, 255, .6); stroke: #fff; stroke-width: 2; pointer-events: none; }
.edge-highlight { stroke: rgba(255, 255, 255, .65); stroke-width: 9; stroke-linecap: round; pointer-events: none; }
.vertex-target:hover .vertex-highlight { fill: #fff; }
.edge-target:hover .edge-highlight { stroke: #fff; }

.robber { pointer-events: none; }

/* Klassik: Pergament-Chrom auf dem Brett. */
.theme-classic .token-bg { fill: #f4ecd8; stroke: #6d6250; stroke-width: 1.4; }
.theme-classic .token { fill: #2b2b2b; }
.theme-classic .token-red { fill: #c0392b; }
.theme-classic .pip { fill: #2b2b2b; }
.theme-classic .pip-red { fill: #c0392b; }
.theme-classic .port-line { stroke: #7a6a4d; stroke-width: 4; }
.theme-classic .port-bg { stroke: #4b4234; stroke-width: 2; }
.theme-classic .port-label { fill: #221f19; }

/* Weltraum: leuchtende Anzeigen auf dunklem Grund. */
.theme-space .token-bg { fill: #0d1830; stroke: #5ad0e8; stroke-width: 1.6; }
.theme-space .token { fill: #e9f4ff; }
.theme-space .token-red { fill: #ff8a7a; }
.theme-space .pip { fill: #9fd8ea; }
.theme-space .pip-red { fill: #ff8a7a; }
.theme-space .port-line { stroke: #3e5f86; stroke-width: 3; stroke-dasharray: 6 5; }
.theme-space .port-bg { stroke: #0b1424; stroke-width: 2; }
.theme-space .port-label { fill: #08111f; }
.theme-space .hex-fill { stroke: rgba(180, 220, 255, .28); }
.theme-space .road-outline { stroke: rgba(0, 0, 0, .6); }

.starfield circle { pointer-events: none; }

.pirate-glow { fill: #ff5a4d; opacity: .18; }
.pirate-hull { fill: #e8453a; stroke: #ffd2cd; stroke-width: 1.4; }
.pirate-core { fill: #ffe9a8; }

/* --- Panels ------------------------------------------------------------ */

.players { width: 100%; border-collapse: collapse; font-size: .9rem; }
.players th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; padding: .25rem .3rem; }
.players td { padding: .4rem .3rem; border-top: 1px solid var(--line); }
.players tr.current td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.players tr.me td:nth-child(2) { font-weight: 700; }

.resources { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.resource {
    flex: 1 1 60px;
    min-width: 60px;
    border: 2px solid;
    border-radius: 10px;
    padding: .35rem .2rem;
    text-align: center;
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.resource .icon { font-size: 1.35rem; line-height: 1.2; }
.resource .count { font-weight: 700; font-size: 1.1rem; }
.resource .ratio { font-size: .68rem; color: var(--muted); }

.devcards { list-style: none; padding: 0; margin: 0; }
.devcards li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    padding: .3rem 0;
    border-top: 1px solid var(--line);
}

.build-buttons { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .5rem; }

.subpanel {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .7rem .8rem;
    margin-top: .6rem;
}
.subpanel.offer { border-left: 4px solid var(--accent); }
.responses { list-style: none; padding: 0; margin: .4rem 0; }
.responses li { display: flex; gap: .5rem; align-items: center; padding: .2rem 0; }

.trade-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.trade-table td, .trade-table th { padding: .25rem .3rem; text-align: left; }
.trade-table td:nth-child(n+2) { white-space: nowrap; }

.resource-picker .pick { display: flex; align-items: center; gap: .4rem; padding: .25rem 0; border-top: 1px solid var(--line); }
.resource-picker .pick:first-child { border-top: 0; }
.resource-picker .pick span:first-child { flex: 1; min-width: 0; }
.pick-count { min-width: 1.8rem; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
/* Plus und Minus werden oft hintereinander getippt, die dürfen nicht klein sein. */
.resource-picker .pick button { min-width: 44px; min-height: 44px; padding: 0 .6rem; font-size: 1.05rem; }
.discard > p { margin-top: 0; }
.discard > .primary { display: flex; width: 100%; margin: .7rem 0 0; }

.log ul { list-style: none; padding: 0; margin: 0; max-height: 40dvh; overflow-y: auto; font-size: .85rem; }
.log li { padding: .25rem 0; border-top: 1px solid var(--line); }
.log li .muted { margin-right: .4rem; font-size: .75rem; }

.winner h3 { color: var(--ink); font-size: 1.15rem; text-transform: none; letter-spacing: 0; }

/* --- Anzeigen ---------------------------------------------------------- */

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

/* Zwei Würfel mit echten Augen. Sie taumeln kurz herein und legen sich hin; die Augen erscheinen
   erst danach — sonst läse man das Ergebnis schon, während der Würfel noch rollt. Ausgelöst wird
   das allein durch den Neuaufbau des Elements, das Markup hängt dafür an der Wurfnummer. */
.status-bar .dice {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    white-space: nowrap;
}

.die {
    display: grid;
    grid-template: repeat(3, 1fr) / repeat(3, 1fr);
    gap: 1px;
    width: 26px;
    height: 26px;
    padding: 3px;
    border-radius: 6px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 1px 3px rgba(0, 0, 0, .4);
    animation: hexDieTumble .6s cubic-bezier(.2, .9, .25, 1.1) both;
}
.die + .die { animation-delay: .08s; }

.die .pip { border-radius: 50%; }
.die .pip.on {
    background: var(--ink);
    animation: hexPipIn .16s ease-out .48s both;
}
.die + .die .pip.on { animation-delay: .56s; }

.dice-sum {
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    animation: hexSumPop .28s ease-out .6s both;
}

@keyframes hexDieTumble {
    0%   { opacity: 0; transform: translateY(-11px) rotate(-165deg) scale(.7); }
    40%  { opacity: 1; }
    62%  { transform: translateY(0) rotate(14deg) scale(1.08); }
    80%  { transform: translateY(-3px) rotate(-5deg) scale(1); }
    100% { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}
@keyframes hexPipIn {
    from { opacity: 0; transform: scale(.3); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes hexSumPop {
    0%   { opacity: 0; transform: scale(.6); }
    65%  { transform: scale(1.18); }
    100% { opacity: 1; transform: scale(1); }
}

/* Einblendungen auf dem Brett. Die äußere Gruppe steht auf dem Feld, die innere bewegt sich —
   ein Element kann nicht gleichzeitig per Attribut positioniert und per CSS verschoben werden. */
.pulse-text {
    font-size: 20px;
    font-weight: 800;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, .65);
    stroke-width: 4;
    stroke-linejoin: round;
}
/* Die Einblendungen liegen über den baubaren Punkten. Dass sie keinen Tipp abfangen, steht schon
   als Attribut im Markup -- hier noch einmal für den ganzen Teilbaum, weil ein verschluckter Tipp
   aufs Brett der teuerste Fehler in diesem Spiel ist und man ihn nicht sofort als solchen erkennt. */
.pulses, .pulses * { pointer-events: none; }

.pulse { animation: hexFloatUp 1.9s cubic-bezier(.2, .7, .3, 1) both; }
.pulse.down { animation-name: hexFloatDown; }

/* Zweite Reihe: fremde Erträge und eigene Ausgaben. Kleiner, blasser, schneller wieder weg —
   sichtbar für den, der hinschaut, aber nicht im Weg für den, der plant. */
.pulse.secondary { animation-duration: 1.3s; opacity: .7; }
.pulse.secondary .pulse-text { font-size: 14px; stroke-width: 3; }

@keyframes hexFloatUp {
    0%   { opacity: 0; transform: translateY(8px) scale(.7); }
    14%  { opacity: 1; transform: translateY(0) scale(1.14); }
    26%  { transform: translateY(-5px) scale(1); }
    70%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-44px) scale(.95); }
}
@keyframes hexFloatDown {
    0%   { opacity: 0; transform: translateY(-8px) scale(.7); }
    14%  { opacity: 1; transform: translateY(0) scale(1.14); }
    26%  { transform: translateY(4px) scale(1); }
    70%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(30px) scale(.9); }
}

/* Dieselbe Sprache an der Rohstoffleiste, für alles ohne Feldbezug: bezahlt, getauscht, geklaut. */
.dock-hand .res { position: relative; }

.tick {
    position: absolute;
    left: 50%;
    bottom: 100%;
    margin-bottom: .1rem;
    font-size: .8rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
    animation: hexTickUp 1.5s cubic-bezier(.2, .7, .3, 1) both;
}
.tick.up { color: var(--accent-2); }
.tick.down { color: var(--error); }
.tick.secondary { font-size: .72rem; opacity: .8; animation-duration: 1.05s; }

@keyframes hexTickUp {
    0%   { opacity: 0; transform: translate(-50%, 8px) scale(.7); }
    16%  { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
    30%  { transform: translate(-50%, -2px) scale(1); }
    70%  { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -26px) scale(.95); }
}

/* --- Bildschirmfüllende Ansage ----------------------------------------- */

/* Drei Sekunden über dem ganzen Bild, dann von selbst wieder weg. Zwei Dinge sind hier wichtig:
   pointer-events bleibt aus, damit die Ansage nie einen Tipp verschluckt — man soll weiterspielen
   können, während sie noch läuft — und die Animation endet bei Deckkraft null und ohne Sichtbarkeit,
   sodass kein Aufräumen vom Server nötig ist. */
.flash {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    display: grid;
    place-items: center;
    pointer-events: none;
    /* Unter den Dialogen, über allem anderen: nach einer Sieben erscheint das Abwerfen-Fenster im
       selben Moment wie die Wurf-Ansage, und das Fenster muss lesbar bleiben. */
    z-index: 40;
    /* Die Ansage bleibt nach dem Verblassen im Dokument stehen. Ohne diese Zeile läge eine
       unsichtbare Fläche über dem ganzen Brett, sobald einmal gewürfelt wurde. */
    visibility: hidden;
    animation: hexFlashLayer 3s ease-out both;
}
.flash-battle { z-index: 41; }
.flash * { pointer-events: none; }

@keyframes hexFlashLayer {
    0%   { opacity: 0; visibility: visible; }
    7%   { opacity: 1; }
    76%  { opacity: 1; }
    100% { opacity: 0; visibility: hidden; }
}

/* Ein weicher dunkler Hof zur Mitte hin. Er nimmt dem Brett kurz die Aufmerksamkeit, ohne es
   zuzudecken: an den Rändern läuft er vollständig aus. */
.flash::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(closest-side,
        color-mix(in srgb, var(--bg) 80%, transparent),
        transparent 78%);
}

.flash-inner {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .7rem;
    padding: 1rem;
    text-align: center;
    animation: hexFlashPop 3s cubic-bezier(.2, .8, .3, 1) both;
}

@keyframes hexFlashPop {
    0%   { transform: scale(.55) translateY(22px); }
    9%   { transform: scale(1.05) translateY(0); }
    17%  { transform: scale(1); }
    78%  { transform: scale(1); }
    100% { transform: scale(.88) translateY(-30px); }
}

/* Die großen Würfel. Sie drehen sich anderthalb Umdrehungen und die Augen erscheinen erst danach —
   bei dieser Größe hätte man das Ergebnis sonst längst gelesen, bevor der Würfel liegt. */
.flash-dice { display: flex; gap: clamp(.5rem, 2vmin, 1rem); }

.flash .die {
    width: clamp(58px, 17vmin, 104px);
    height: clamp(58px, 17vmin, 104px);
    padding: clamp(6px, 1.8vmin, 11px);
    gap: clamp(2px, .6vmin, 4px);
    border-radius: clamp(10px, 3vmin, 18px);
    border-width: 2px;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, .14), 0 6px 22px rgba(0, 0, 0, .55);
    animation: hexDieRollBig 1s cubic-bezier(.2, .85, .3, 1.05) both;
}
.flash .die + .die { animation-delay: .13s; }
.flash .die .pip.on { animation: hexPipIn .22s ease-out .8s both; }
.flash .die + .die .pip.on { animation-delay: .93s; }

@keyframes hexDieRollBig {
    0%   { opacity: 0; transform: translateY(-46px) rotate(-560deg) scale(.35); }
    30%  { opacity: 1; }
    72%  { transform: translateY(0) rotate(16deg) scale(1.12); }
    88%  { transform: translateY(-6px) rotate(-5deg) scale(1); }
    100% { opacity: 1; transform: none; }
}

.flash-sum {
    font-size: clamp(1.8rem, 6vmin, 3rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--ink-strong);
    text-shadow: 0 2px 12px rgba(0, 0, 0, .7);
    animation: hexFlashItem .3s ease-out 1.1s both;
}

.flash-gains { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }

.flash-gain {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .3rem .6rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border: 1px solid var(--accent-2);
    font-size: clamp(.95rem, 2.6vmin, 1.3rem);
    color: var(--ink);
    animation: hexFlashItem .32s cubic-bezier(.2, .9, .3, 1.2) 1.28s both;
}
.flash-gain b { color: var(--accent-2); font-variant-numeric: tabular-nums; }
/* Die Karten kommen nacheinander an, das liest sich als Aufzählung statt als Block. */
.flash-gain:nth-child(2) { animation-delay: 1.38s; }
.flash-gain:nth-child(3) { animation-delay: 1.48s; }
.flash-gain:nth-child(4) { animation-delay: 1.58s; }
.flash-gain:nth-child(n+5) { animation-delay: 1.68s; }

@keyframes hexFlashItem {
    from { opacity: 0; transform: translateY(10px) scale(.8); }
    to   { opacity: 1; transform: none; }
}

/* Der Kampf, groß. Aufbau wie im kleinen Bericht unten links, nur in Ansagegröße. */
.flash-battle-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .7rem;
    font-size: clamp(1rem, 3.2vmin, 1.5rem);
    color: var(--ink-strong);
    text-shadow: 0 2px 12px rgba(0, 0, 0, .7);
}
.flash-battle-odds { font-variant-numeric: tabular-nums; opacity: .85; white-space: nowrap; }

.flash .battle-rounds {
    display: grid;
    gap: .15rem;
    font-size: clamp(.95rem, 2.8vmin, 1.35rem);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
    animation: hexFlashItem .3s ease-out .35s both;
}

.flash-verdict {
    font-size: clamp(1.4rem, 5vmin, 2.4rem);
    font-weight: 800;
    line-height: 1.1;
    text-shadow: 0 2px 14px rgba(0, 0, 0, .75);
    animation: hexFlashItem .34s cubic-bezier(.2, .9, .3, 1.2) .7s both;
}
.flash-battle.won .flash-verdict { color: #ff8a7a; }
.flash-battle.held .flash-verdict { color: var(--accent-2); }

.flash-losses {
    font-size: clamp(.85rem, 2.4vmin, 1.1rem);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    animation: hexFlashItem .3s ease-out .85s both;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }

    /* Die Regel darüber drückt jede Animation auf null — die Einblendungen würden also nur kurz
       aufblitzen, was mehr stört als hilft. Wer keine Bewegung will, bekommt hier nichts: die
       Zahlen stehen ohnehin in der Leiste, der Hergang im Verlauf. */
    .pulse, .tick, .flash { display: none; }

    /* Der Würfel selbst muss bleiben, nur ruhig — sonst fehlte das Ergebnis. */
    .die, .die .pip.on, .dice-sum { animation: none !important; opacity: 1; transform: none; }
}
