:root {
    --bg: #0f1520;
    --bg-2: #161f2e;
    --panel: #1b2536;
    --panel-2: #222e42;
    --line: #2f3d55;
    --text: #e8edf5;
    --muted: #93a1b8;
    --accent: #e8b44c;
    --accent-2: #f4cf7c;
    --danger: #e05656;
    --ok: #4cb36b;
    --ocean-1: #1d4766;
    --ocean-2: #0d2238;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    background: radial-gradient(circle at 20% 0%, #1c2940 0%, var(--bg) 55%) fixed;
    color: var(--text);
    font: 15px/1.5 Inter, system-ui, sans-serif;
    min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h1, h2, .brand { font-family: Cinzel, Georgia, serif; letter-spacing: .04em; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
a { color: var(--accent-2); }
em { color: var(--muted); font-style: normal; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

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

.panel {
    background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #241a06; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: .85rem; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.actions-center { justify-content: center; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    background: rgba(232, 180, 76, .12);
    border: 1px solid rgba(232, 180, 76, .4);
    color: var(--accent-2);
    font-family: Inter, sans-serif;
    font-size: .85rem;
    letter-spacing: 0;
}
.badge strong { letter-spacing: .12em; }

.tag {
    display: inline-block;
    font-size: .7rem;
    padding: 1px 7px;
    border-radius: 99px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
    vertical-align: middle;
    margin-left: 4px;
}
.tag-on { color: var(--ok); border-color: rgba(76, 179, 107, .5); }
.tag-off { color: var(--danger); border-color: rgba(224, 86, 86, .45); }

.dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .15);
    vertical-align: middle;
}
.dot-empty { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }

input[type="text"], select {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field { display: block; margin: 0 0 14px; border: 0; padding: 0; }
.field > span, .field > legend { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 5px; }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.form-error { color: var(--danger); }
.hint { color: var(--muted); font-size: .85rem; margin: 12px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.chip {
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    border-radius: 99px;
    padding: 4px 12px;
    font: inherit;
    cursor: pointer;
}
.chip.is-active { background: var(--accent); color: #241a06; border-color: var(--accent); font-weight: 600; }

.big-number { font-size: 1.5rem; color: var(--accent-2); font-family: Cinzel, serif; }

/* ---------------------------------------------------------------- Startseite */

.home { max-width: 1080px; margin: 0 auto; padding: 48px 16px 64px; }
.home-hero { text-align: center; margin-bottom: 36px; }
.home-hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); color: var(--accent-2); text-shadow: 0 4px 30px rgba(232, 180, 76, .25); margin-bottom: .2em; }
.home-hero p { color: var(--muted); font-size: 1.1rem; margin: 0; }
.home-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
.home-side { display: grid; gap: 20px; }
.bot-list { display: grid; gap: 8px; margin-bottom: 8px; }
.bot-row { display: flex; gap: 8px; }
.options { margin: 4px 0 8px; }
.options summary { cursor: pointer; color: var(--accent-2); margin-bottom: 12px; }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-weight: 600; }
.rules ol { margin: 0; padding-left: 20px; color: var(--muted); }
.rules li { margin-bottom: 8px; }
.rules strong { color: var(--text); }

/* ---------------------------------------------------------------- Spiel */

.game { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(15, 21, 32, .85);
    backdrop-filter: blur(6px);
    flex-wrap: wrap;
}
.brand { color: var(--accent-2); text-decoration: none; font-size: 1.2rem; font-weight: 700; }
.topbar-info { display: flex; gap: 8px; align-items: center; }
.turn-banner {
    margin-left: auto;
    padding: 6px 14px;
    border-radius: 99px;
    background: var(--panel);
    border: 1px solid var(--line);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.turn-banner.is-me { background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #241a06; border-color: var(--accent); animation: pulse 2s infinite; }
#countdown { font-variant-numeric: tabular-nums; }
#countdown.is-urgent { color: var(--danger); font-weight: 700; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(232, 180, 76, .5); }
    50% { box-shadow: 0 0 0 8px rgba(232, 180, 76, 0); }
}

.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; padding: 16px; align-items: start; }

.board {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    position: sticky;
    top: 16px;
}
#map { display: block; width: 100%; height: auto; user-select: none; }

#map .grid line { stroke: rgba(255, 255, 255, .04); stroke-width: 1; }
#map .sea-routes line { stroke: rgba(255, 255, 255, .45); stroke-width: 1.5; stroke-dasharray: 4 5; }
#map .lands path { fill: #1a2433; }
#map .outlines path { fill: none; stroke-width: 3.5; stroke-linejoin: round; pointer-events: none; opacity: .95; }

#map .cell {
    fill-opacity: .78;
    stroke: rgba(10, 15, 25, .75);
    stroke-width: 1.4;
    stroke-linejoin: round;
    cursor: pointer;
    transition: fill .4s, fill-opacity .2s, opacity .2s;
}
#map .cell:hover { fill-opacity: .95; }
#map .cell.is-source { fill-opacity: .95; }
#map .cell.is-target { fill-opacity: .9; stroke: #fff; stroke-width: 2.5; stroke-dasharray: 6 4; animation: march 1s linear infinite; }
#map .cell.is-selected { fill-opacity: 1; stroke: var(--accent-2); stroke-width: 3.5; }
#map .cell.is-dimmed { fill-opacity: .32; }

@keyframes march { to { stroke-dashoffset: -20; } }

#map .territory-name {
    font-size: 9px;
    fill: rgba(255, 255, 255, .85);
    text-anchor: middle;
    pointer-events: none;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, .55);
    stroke-width: 2.5px;
    font-weight: 600;
}

#map .badge { cursor: pointer; transition: transform .3s; }
#map .badge circle { stroke: #fff; stroke-width: 2; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); transition: fill .4s; }
#map .badge text { font-size: 11px; font-weight: 700; fill: #fff; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: rgba(0, 0, 0, .45); stroke-width: 2px; }
#map .badge.is-big circle { r: 14; }
#map .badge.is-selected circle { stroke: var(--accent-2); stroke-width: 3; }
#map .badge.is-hit circle { animation: hit .6s ease-out; }

@keyframes hit {
    0% { stroke: #fff; stroke-width: 2; }
    30% { stroke: #ff5d5d; stroke-width: 7; }
    100% { stroke: #fff; stroke-width: 2; }
}

#map .attack-arrow { stroke-width: 4; stroke-linecap: round; opacity: 0; pointer-events: none; filter: url(#glow); }
#map .attack-arrow.is-visible { animation: arrow 2.6s ease-out forwards; }

@keyframes arrow {
    0% { opacity: 0; stroke-dasharray: 0 300; }
    15% { opacity: 1; stroke-dasharray: 300 0; }
    75% { opacity: 1; }
    100% { opacity: 0; }
}

.map-tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(15, 21, 32, .95);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: .85rem;
    display: grid;
    gap: 2px;
    box-shadow: var(--shadow);
    z-index: 5;
}
.map-tooltip span { color: var(--muted); display: flex; align-items: center; gap: 6px; }

.battle-overlay {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px 18px;
    border-radius: var(--radius);
    background: rgba(15, 21, 32, .92);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-weight: 600;
}
.battle-overlay.is-visible { animation: rise .35s ease-out; }
.battle-side { display: flex; align-items: center; gap: 8px; }
.battle-vs { color: var(--muted); font-size: .8rem; }
.battle-result { width: 100%; text-align: center; color: var(--accent-2); font-family: Cinzel, serif; }
.dice { display: flex; gap: 4px; }
.die {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-weight: 700;
    animation: roll .45s ease-out;
}
.die-attack { background: #c83d3d; color: #fff; }
.die-defend { background: #f1f1f1; color: #1b2536; }
.loss { color: var(--danger); }

@keyframes roll {
    0% { transform: rotate(-200deg) scale(.4); opacity: 0; }
    100% { transform: rotate(0) scale(1); opacity: 1; }
}
@keyframes rise {
    from { transform: translate(-50%, 12px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------------------------------------------------------------- Seitenleiste */

.sidebar { display: grid; gap: 14px; }
.sidebar .panel { padding: 14px 16px; }
.action-panel p { margin: 0 0 6px; }

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin-top: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.slider { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.slider input { flex: 1; accent-color: var(--accent); }
.slider output { min-width: 2.5em; text-align: right; font-weight: 700; font-size: 1.2rem; color: var(--accent-2); }

.player-list, .continent-list, .log, .lobby-players { list-style: none; margin: 0; padding: 0; }
.player-list li {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
    align-items: center;
    padding: 7px 8px;
    border-radius: 8px;
    border: 1px solid transparent;
}
.player-list li.is-current { background: rgba(232, 180, 76, .08); border-color: rgba(232, 180, 76, .35); }
.player-list li.is-eliminated { opacity: .45; }
.player-list li.is-eliminated .player-name { text-decoration: line-through; }
.player-name { font-weight: 600; }
.player-stats { grid-column: 2; display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.continent-list li { display: grid; grid-template-columns: auto 1fr auto auto auto; gap: 8px; align-items: center; padding: 3px 0; font-size: .9rem; }
.continent-list .bonus { color: var(--accent-2); font-weight: 600; }

.log-panel { max-height: 300px; display: flex; flex-direction: column; }
.log { overflow-y: auto; font-size: .82rem; color: var(--muted); }
.log li { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid rgba(47, 61, 85, .5); }
.log li .dot { margin-top: 5px; width: 8px; height: 8px; }
.log li:first-child { color: var(--text); }

.cards { display: flex; flex-wrap: wrap; gap: 8px; }
.card {
    width: 78px;
    min-height: 98px;
    border-radius: 8px;
    border: 2px solid var(--line);
    background: linear-gradient(160deg, #f6eedb, #e1d2ae);
    color: #3a2c10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
    cursor: pointer;
    font: inherit;
    transition: transform .15s, border-color .15s;
}
.card:disabled { cursor: default; }
.card:hover:not(:disabled) { transform: translateY(-2px); }
.card.is-selected { border-color: var(--accent); transform: translateY(-5px); box-shadow: 0 6px 16px rgba(232, 180, 76, .35); }
.card.is-owned { box-shadow: inset 0 0 0 2px rgba(58, 154, 74, .65); }
.card-icon { font-size: 1.7rem; line-height: 1; }
.card-type { font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.card-territory { font-size: .68rem; text-align: center; line-height: 1.15; }
.card-joker { background: linear-gradient(160deg, #f4d77f, #d6a640); }

/* ---------------------------------------------------------------- Dialoge */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 14, .72);
    backdrop-filter: blur(3px);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 20;
    overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-box {
    width: min(560px, 100%);
    background: linear-gradient(180deg, var(--panel), var(--bg-2));
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}
.modal-box h2 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; color: var(--accent-2); }
.modal-box h3 { margin-top: 18px; }
.modal-center { text-align: center; }
.modal-center h2 { justify-content: center; }
.trophy { font-size: 3.5rem; }

.share { display: flex; gap: 8px; }
.share input { font-size: .85rem; color: var(--muted); }
.lobby-players li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(47, 61, 85, .6); }
.lobby-players li > span:first-of-type { flex: 1; }
.join-row { display: flex; gap: 8px; margin-top: 12px; }
.join-row select, .join-row input { flex: 1; }
.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option-grid label { font-size: .85rem; color: var(--muted); display: grid; gap: 4px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    padding: 10px 18px;
    border-radius: 10px;
    background: var(--danger);
    color: #fff;
    font-weight: 600;
    box-shadow: var(--shadow);
    z-index: 30;
    max-width: calc(100% - 32px);
}
.toast-info { background: var(--panel-2); border: 1px solid var(--accent); }

/* ---------------------------------------------------------------- Mobil */

@media (max-width: 980px) {
    .layout { grid-template-columns: 1fr; padding: 10px; }
    .board { position: relative; top: 0; }
    .home-grid { grid-template-columns: 1fr; }
    .turn-banner { margin-left: 0; width: 100%; justify-content: center; }
}

@media (max-width: 520px) {
    .option-grid { grid-template-columns: 1fr; }
    #map .territory-name { display: none; }
    .topbar { padding: 8px 12px; }
}

.player-stats span { white-space: nowrap; }

/* ---------------------------------------------------------------- Portal & Zugang */

.back-link { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 8px; font-size: .9rem; }
.back-link:hover { color: var(--accent-2); }

.access { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.access-box { width: min(380px, 100%); }
.access-box h1 { color: var(--accent-2); font-size: 1.8rem; margin-bottom: .3em; }
.access-box input[type="password"] {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
.access-box input[type="password"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-block { width: 100%; }

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.game-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: var(--text);
    text-decoration: none;
    transition: transform .15s, border-color .15s;
}
a.game-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.game-card h2 { color: var(--accent-2); font-size: 1.4rem; margin-bottom: .3em; }
.game-card p { color: var(--muted); margin: 0; }
.game-card-body { flex: 1; }
.game-card-meta { display: flex; gap: 6px; margin-top: 12px; }
.game-card-meta .tag { margin-left: 0; }
.game-card .btn { align-self: flex-start; }
.game-card-art {
    height: 140px;
    border-radius: 10px;
    background: radial-gradient(circle at 50% 45%, var(--ocean-1), var(--ocean-2));
    display: grid;
    place-items: center;
}
.game-card-art svg { width: 110px; height: 110px; }
.game-card-art circle:not(.marker) { fill: #1a2433; stroke: var(--accent-2); stroke-width: 3; }
.game-card-art path { fill: none; stroke: rgba(244, 207, 124, .55); stroke-width: 2; }
.game-card-art .marker { fill: #d64545; stroke: #fff; stroke-width: 2; }
.game-card-art .marker-2 { fill: #3b6fd8; }
.game-card-soon { border-style: dashed; box-shadow: none; background: transparent; justify-content: center; min-height: 200px; }
