:root {
  --bg: #efe6d2;
  --paper: #f8f2e3;
  --ink: #2b2118;
  --muted: #7a6a55;
  --line: #d6c7a8;
  --accent: #8a3b12;
  --accent-ink: #fff8ec;
  --holz: #8b5a2b;
  --lehm: #b5652f;
  --eisen: #5f6b75;
  --ok: #4d6b2f;
  --bad: #a8321e;
  --own: #c98a1a;
  --player: #2f5f8a;
  --barb: #8c8273;
  --grass: #c9d3a5;
  --ally: #3f8f3f;
  --shadow: 0 1px 0 rgba(43, 33, 24, 0.06), 0 4px 14px rgba(43, 33, 24, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1712;
    --paper: #26201a;
    --ink: #ede3cf;
    --muted: #a8977c;
    --line: #3c3329;
    --accent: #d0773f;
    --accent-ink: #1b1712;
    --holz: #c08a55;
    --lehm: #db8a55;
    --eisen: #9aa8b4;
    --ok: #9cbf6b;
    --bad: #ef7a62;
    --grass: #3a4129;
    --ally: #5fae5f;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Alegreya Sans", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2 { font-family: "Alegreya SC", Georgia, serif; font-weight: 700; letter-spacing: 0.01em; }
h2 { font-size: 1.05rem; color: var(--muted); margin: 1.4rem 0 0.5rem; text-transform: none; }

button {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button.secondary { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; text-decoration: underline; }

/* ---------- Auth ---------- */
#auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 1.6rem; width: min(380px, 100%); }
.card h1 { margin: 0; font-size: 2.2rem; color: var(--accent); }
.tagline { margin: 0.2rem 0 1.2rem; color: var(--muted); }
label { display: block; font-weight: 500; margin-bottom: 0.8rem; }
input {
  display: block; width: 100%; margin-top: 0.25rem; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.6rem;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-buttons { display: flex; gap: 0.6rem; margin-top: 1rem; }
.error { color: var(--bad); min-height: 1.4em; margin: 0.8rem 0 0; }

/* ---------- Spiel ---------- */
main { max-width: 860px; margin: 0 auto; padding: 12px 16px 48px; }
header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.title { display: flex; align-items: baseline; gap: 0.5rem; }
#vname { margin: 0; font-size: 1.7rem; cursor: pointer; }
#vname:hover { color: var(--accent); }
#vcoords, .user { color: var(--muted); }
.title { flex-wrap: wrap; }
.loyalty:empty { display: none; }
.loyalty { font-size: 0.85rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 0.55rem; }
.loyalty.low { color: var(--bad); border-color: var(--bad); }
.user { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
#village-select { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 0.25rem 0.4rem; max-width: 14rem; }
.card.restart { width: 100%; max-width: 520px; margin: 1.5rem 0; }
.conquest { color: var(--ok); }

.resources {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; margin: 0.8rem 0;
  background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.res { background: var(--paper); padding: 0.45rem 0.6rem; display: grid; grid-template-columns: auto 1fr; column-gap: 0.4rem; align-items: center; }
.res-icon { width: 10px; height: 10px; border-radius: 2px; grid-row: span 2; }
.res-holz .res-icon { background: var(--holz); }
.res-lehm .res-icon { background: var(--lehm); }
.res-eisen .res-icon { background: var(--eisen); }
.res-label { font-size: 0.78rem; color: var(--muted); }
.res b { font-variant-numeric: tabular-nums; font-size: 1.05rem; grid-column: 1 / -1; }
.res-holz b, .res-lehm b, .res-eisen b { grid-column: 2; }
.res b.full { color: var(--bad); }
.res small { color: var(--ok); font-size: 0.75rem; grid-column: 2; }
.res-cap, .res-pop { grid-template-columns: 1fr; }

.tabs { display: flex; gap: 0.3rem; border-bottom: 1px solid var(--line); margin-top: 0.4rem; }
.tabs button { background: none; color: var(--muted); border-radius: 6px 6px 0 0; padding: 0.5rem 1rem; }
.tabs button.active { color: var(--ink); background: var(--paper); box-shadow: inset 0 -2px 0 var(--accent); }

ul { list-style: none; margin: 0; padding: 0; }
.queue li, .buildings li { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 0.4rem; }
.queue li { padding: 0.55rem 0.75rem; }
.queue li.empty { color: var(--muted); font-style: italic; }
.q-head { display: flex; gap: 0.8rem; align-items: baseline; }
.q-head > span:first-child { flex: 1; font-weight: 700; }
.q-head em { font-style: normal; font-weight: 400; color: var(--muted); }
.q-time { font-variant-numeric: tabular-nums; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 0.4rem; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }

.buildings li { display: grid; grid-template-columns: 1fr auto auto; gap: 0.4rem 1rem; align-items: center; padding: 0.6rem 0.75rem; }
.buildings li.unbuilt .b-name { color: var(--muted); }
.b-name { font-weight: 700; }
.b-level { color: var(--muted); font-size: 0.9rem; }
.b-info p { margin: 0.1rem 0 0; font-size: 0.85rem; color: var(--muted); }
.cost { display: flex; gap: 0.7rem; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.cost span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 1px; }
.c-holz::before { background: var(--holz); }
.c-lehm::before { background: var(--lehm); }
.c-eisen::before { background: var(--eisen); }
.c-time { color: var(--muted); }
.c-time::before { display: none !important; }
.cost .short { color: var(--bad); }
.b-action { text-align: right; min-width: 7.5rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- Alarm, Badges ---------- */
.alarm { background: var(--bad); color: #fff; font-weight: 700; padding: 0.5rem 0.8rem; border-radius: 8px; margin-bottom: 0.4rem; }
.badge { display: inline-block; min-width: 1.3em; padding: 0 0.35em; border-radius: 999px; background: var(--bad); color: #fff; font-size: 0.75rem; line-height: 1.3em; text-align: center; }
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs button { white-space: nowrap; }
.note { background: var(--paper); border: 1px dashed var(--line); padding: 0.8rem; border-radius: 8px; color: var(--muted); margin-top: 1rem; }

/* ---------- Bewegungen ---------- */
.mv { border-left: 4px solid var(--line) !important; }
.mv-incoming { border-left-color: var(--bad) !important; }
.mv-attack { border-left-color: var(--accent) !important; }
.mv-return { border-left-color: var(--ok) !important; }
.mv-detail { font-size: 0.85rem; color: var(--muted); margin-top: 0.2rem; }

/* ---------- Kaserne ---------- */
.stats { white-space: nowrap; }
.recruit { display: flex; gap: 0.35rem; align-items: center; justify-content: flex-end; }
.recruit input, .attack-units input, .coords input { width: 5.2rem; margin: 0; padding: 0.35rem 0.45rem; display: inline-block; }
.units .b-action { min-width: 15rem; }
.legend-line { font-size: 0.8rem; }

/* ---------- Angriff ---------- */
.card.attack { width: 100%; max-width: 520px; margin-top: 1rem; padding: 1rem 1.2rem; }
.card.attack h2:first-child { margin-top: 0; }
.coords { display: flex; align-items: center; gap: 0.6rem; }
.coords label { display: flex; gap: 0.4rem; align-items: center; margin: 0; }
.attack-units { display: grid; gap: 0.35rem; }
.unit-input { display: grid; grid-template-columns: 1fr auto 4rem; gap: 0.6rem; align-items: center; margin: 0; font-weight: 500; }
.unit-input .link { text-align: right; font-variant-numeric: tabular-nums; }
.preview { color: var(--muted); font-size: 0.9rem; min-height: 2.6em; }
.preview b { color: var(--ink); }

.send-buttons { display: flex; gap: 0.6rem; }
.mv-support { border-left-color: var(--player) !important; }
.mv-support-in { border-left-color: var(--ok) !important; }
.q-head em { font-style: normal; color: var(--muted); font-weight: 400; }

/* ---------- Rangliste ---------- */
.ranking-wrap { overflow-x: auto; margin-top: 1rem; }
.ranking { border-collapse: collapse; width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; font-variant-numeric: tabular-nums; }
.ranking th, .ranking td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.ranking th { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.ranking th:nth-child(2), .ranking td:nth-child(2) { text-align: left; width: 100%; }
.ranking tr.me td { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 700; }
.ranking tbody tr:last-child td { border-bottom: 0; }

/* ---------- Stamm ---------- */
.tag { display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; padding: 0.05rem 0.4rem; border-radius: 4px;
  color: #fff; background: var(--tc); vertical-align: 1px; }
.segmented { display: inline-flex; margin-top: 1rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { background: var(--paper); color: var(--muted); border-radius: 0; padding: 0.4rem 1rem; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); }
.tribe-form { width: 100%; max-width: 420px; margin-top: 1rem; }
.tribe-form h2:first-child { margin-top: 0; }
.swatches { border: 0; padding: 0; margin: 0 0 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatches legend { font-weight: 500; margin-bottom: 0.35rem; padding: 0; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch span { display: block; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; box-shadow: inset 0 0 0 2px transparent; }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.tribe-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }
.tribe-head h2 { margin: 0; font-size: 1.4rem; color: var(--ink); }
.tribe-desc { display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 0.6rem; }
.tribe-desc-text { white-space: pre-wrap; margin: 0.6rem 0 0; }
textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.6rem; width: 100%; resize: vertical; }
textarea:focus, .invite-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.board { max-height: 340px; overflow-y: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 0.3rem 0.8rem; }
.board li { padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.board li:last-child { border-bottom: 0; }
.board li p { margin: 0.15rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.board li .muted { font-size: 0.78rem; margin-left: 0.3rem; }
.board li.sys p { color: var(--muted); font-style: italic; font-size: 0.9rem; }
.board-form { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 0.5rem; }
.invite-form { display: flex; gap: 0.5rem; max-width: 420px; }
.invite-form input { margin: 0; }
.members td.actions { white-space: nowrap; }
.members td.actions .link { margin-left: 0.6rem; font-size: 0.85rem; }
.ranking.members th:nth-child(2), .ranking.members td:nth-child(2) { width: auto; text-align: right; }
.ranking.members th:first-child, .ranking.members td:first-child { text-align: left; width: 100%; }
.role { font-size: 0.72rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 0.3rem; margin-left: 0.3rem; font-weight: 700; }
.danger { color: var(--bad) !important; }
button.secondary.danger { box-shadow: inset 0 0 0 1.5px var(--bad); }
.leave { margin-top: 2rem; }
.q-head > button:not(.link) { padding: 0.3rem 0.7rem; }

/* ---------- Ankündigung, Dialog ---------- */
.announcement { background: color-mix(in srgb, var(--own) 18%, var(--paper)); border: 1px solid var(--own); border-radius: 8px;
  padding: 0.55rem 0.8rem; margin: 0.6rem 0 0; white-space: pre-wrap; }
#auth .announcement { margin-top: 1rem; }
dialog.card { padding: 1.4rem; color: var(--ink); }
dialog::backdrop { background: rgba(20, 15, 10, 0.45); }
dialog h2 { margin-top: 0; }

/* ---------- Spielstart ---------- */
.countdown { display: grid; gap: 0.15rem; text-align: center; background: var(--paper); border: 1px solid var(--accent);
  border-radius: 10px; padding: 0.9rem 1rem; margin-bottom: 0.6rem; }
.countdown .cd { font-family: "Alegreya SC", Georgia, serif; font-size: 2rem; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.2; }
.countdown .muted { font-size: 0.85rem; }
.auth-start { background: color-mix(in srgb, var(--accent) 10%, var(--paper)); border-radius: 6px; padding: 0.45rem 0.65rem; margin: -0.6rem 0 1rem; }
body.prestart .send-buttons, body.prestart .recruit button[type=submit] { opacity: 0.45; pointer-events: none; }
.start-row { display: flex; gap: 0.6rem; align-items: center; }
.start-row input { flex: 1; }
.start-info { margin: -0.5rem 0 0.8rem; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.5rem; margin-top: 1rem; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.75rem; }
.stat span { display: block; font-size: 0.78rem; color: var(--muted); }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.admin-card { width: 100%; max-width: 560px; margin-top: 1.2rem; }
.admin-card h2:first-child { margin-top: 0; }
.radios { border: 0; padding: 0; margin: 0 0 0.8rem; }
.radios legend { font-weight: 500; padding: 0; margin-bottom: 0.3rem; }
.radios label, label.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 400; margin-bottom: 0.3rem; }
.radios input, label.check input { width: auto; margin: 0; }
.admin-players td.actions { white-space: nowrap; }
.admin-players td.actions .link { margin-left: 0.6rem; font-size: 0.85rem; }
.ranking.admin-players th:first-child, .ranking.admin-players td:first-child { text-align: left; width: 100%; }
.ranking.admin-players th:nth-child(2), .ranking.admin-players td:nth-child(2) { width: auto; text-align: right; }
.admin-players tr.banned td { color: var(--muted); }
.danger-zone { border-color: var(--bad); }
.danger-zone h2 { color: var(--bad) !important; }
.danger-btn { background: var(--bad); }
.pw-box { width: 100%; max-width: 560px; margin-top: 1rem; border-color: var(--ok); }
.pw-box p { margin: 0.3rem 0; }
.pw code { font-size: 1.3rem; background: var(--bg); padding: 0.2rem 0.5rem; border-radius: 6px; letter-spacing: 0.05em; }

/* ---------- Berichte ---------- */
.reports li { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 0.35rem; padding: 0.55rem 0.75rem; display: flex; gap: 0.6rem; align-items: center; cursor: pointer; }
.reports li.empty { color: var(--muted); font-style: italic; cursor: default; }
.reports li.unseen .r-title { font-weight: 700; }
.r-title { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dot-win { background: var(--ok); }
.dot-loss { background: var(--bad); }
.report-detail { width: 100%; margin-top: 1rem; }
.report-detail h3 { margin: 0.6rem 0 0; font-family: "Alegreya SC", Georgia, serif; }
.report-detail h4 { margin: 1.1rem 0 0.4rem; }
.outcome-win { color: var(--ok); }
.outcome-loss { color: var(--bad); }
.units-table { border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.9rem; display: block; overflow-x: auto; }
.units-table th, .units-table td { padding: 0.3rem 0.6rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.units-table th:first-child, .units-table td:first-child { text-align: left; color: var(--muted); }

/* ---------- Karte ---------- */
.map-nav { display: flex; gap: 0.4rem; align-items: center; margin-top: 1rem; }
.map-nav button { padding: 0.3rem 0.7rem; }
.map-nav span { min-width: 5rem; text-align: center; color: var(--muted); }
.map {
  display: grid; grid-template-columns: repeat(15, 1fr); gap: 2px; margin-top: 1rem;
  background: var(--line); padding: 2px; border-radius: 8px; aspect-ratio: 1; max-width: 560px;
}
.cell { background: var(--grass); border-radius: 2px; cursor: pointer; }
.cell.out { background: var(--bg); cursor: default; }
.cell.current { background: var(--accent); }
.cell.own { background: var(--own); }
.cell.player { background: var(--player); }
.cell.barb { background: var(--barb); }
.cell.ally { background: var(--ally); }
.map-info { color: var(--muted); min-height: 2.4em; display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.map-info b { color: var(--ink); }
.cell[data-vx] { cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 0.9rem; font-size: 0.85rem; color: var(--muted); }
.legend .cell { display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: -1px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; visibility: hidden;
  transition: transform 0.25s, opacity 0.25s, visibility 0.25s;
  background: var(--ink); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px; max-width: calc(100% - 32px);
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

@media (max-width: 620px) {
  .resources { grid-template-columns: repeat(3, 1fr); }
  .res-pop { grid-column: span 2; }
  .b-action { max-width: 9rem; }
  .tabs button { padding: 0.5rem 0.65rem; }
  .units li { grid-template-columns: 1fr; }
  .units .b-action { grid-column: 1; grid-row: auto; max-width: none; min-width: 0; }
  .recruit { justify-content: flex-start; }
  .buildings li { grid-template-columns: 1fr auto; }
  .cost { grid-column: 1 / -1; grid-row: 2; }
  .b-action { grid-column: 2; grid-row: 1; min-width: 0; }
}
