:root {
  --wood: #1c100c;
  --cloth: #16332b;
  --cloth-2: #1e4a3c;
  --paper: #f3e6c8;
  --paper-2: #e8d5a8;
  --ink: #24180f;
  --muted: #6b5744;
  --gold: #d4a017;
  --line: rgba(36, 24, 15, 0.14);
  --forest: #2d6a4f;
  --hills: #c17048;
  --fields: #e9c46a;
  --pasture: #7dce9a;
  --mountains: #778da9;
  --desert: #e6ccb2;
  --sea: #1b4a63;
  --red: #c0392b;
  --blue: #2471a3;
  --orange: #e67e22;
  --white: #f7f1e3;
  --brown: #6d4c41;
  --green: #1e8449;
  --font: "Nunito Sans", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--paper);
  font-family: var(--font);
  background: var(--wood);
}

.cloth {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(212, 160, 23, 0.18), transparent 50%),
    radial-gradient(900px 500px at 100% 10%, rgba(45, 106, 79, 0.35), transparent 45%),
    linear-gradient(180deg, #2a1810, #16332b 42%, #10241e);
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold);
}

h1, h2 {
  font-family: var(--display);
  font-weight: 700;
  margin: 0.2rem 0 0;
  color: var(--paper);
}

h1 { font-size: clamp(2.4rem, 7vw, 4.4rem); line-height: 0.95; }
h2 { font-size: 1.35rem; }

.lede, .fine, .hint { color: #d9cbb0; }
.fine { font-size: 0.88rem; padding: 1rem 0 2rem; text-align: center; }

.top, .hub-grid, .lobby-grid, .rooms-panel {
  width: min(1100px, calc(100% - 2rem));
  margin-left: auto;
  margin-right: auto;
}

.top { padding: 1.8rem 0 1rem; }

.hub-grid, .lobby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.panel, .game-card {
  background: rgba(20, 12, 8, 0.45);
  border: 1px solid rgba(243, 230, 200, 0.14);
  border-radius: 1.1rem;
  padding: 1.2rem 1.3rem 1.3rem;
  backdrop-filter: blur(8px);
}

.game-card { color: inherit; display: block; }
.game-card:hover { border-color: var(--gold); text-decoration: none; transform: translateY(-2px); transition: 0.15s ease; }

.game-hex { display: flex; gap: 0.35rem; margin-bottom: 0.8rem; }
.hx {
  width: 2.2rem; height: 2.5rem;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.hx.forest { background: var(--forest); }
.hx.fields { background: var(--fields); }
.hx.hills { background: var(--hills); }
.go { display: inline-block; margin-top: 0.8rem; font-weight: 700; color: var(--gold); }

label { display: block; margin: 0.7rem 0; font-size: 0.92rem; color: #e8dcc4; }
input, select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(243, 230, 200, 0.2);
  background: rgba(243, 230, 200, 0.08);
  color: var(--paper);
  font: inherit;
}
.check { display: flex; align-items: center; gap: 0.55rem; }
.check input { width: auto; margin: 0; }

.btn {
  appearance: none;
  border: 1px solid rgba(243, 230, 200, 0.28);
  background: rgba(243, 230, 200, 0.08);
  color: var(--paper);
  font: inherit;
  font-weight: 700;
  padding: 0.55rem 0.9rem;
  border-radius: 0.7rem;
  cursor: pointer;
}
.btn:hover { background: rgba(243, 230, 200, 0.16); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--gold); color: #2a1810; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.warn { background: #8b2e22; border-color: transparent; }

.rooms { display: grid; gap: 0.45rem; margin-top: 0.6rem; }
.room-row {
  display: flex; justify-content: space-between; gap: 0.8rem; align-items: center;
  padding: 0.5rem 0.7rem;
  border-radius: 0.6rem;
  background: rgba(243, 230, 200, 0.06);
}

.table {
  min-height: 100vh;
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid rgba(243, 230, 200, 0.12);
  background: rgba(12, 8, 6, 0.35);
  flex-wrap: wrap;
}
.brand { font-family: var(--display); font-size: 1.35rem; color: var(--paper); font-weight: 700; }
.brand:hover { text-decoration: none; color: var(--gold); }
.code {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.18em;
  background: var(--gold);
  color: #2a1810;
  padding: 0.2rem 0.55rem;
  border-radius: 0.4rem;
  cursor: pointer;
}
.phase { margin: 0; flex: 1; color: #e8dcc4; }
.dice { display: flex; gap: 0.35rem; }
.dice span {
  width: 2rem; height: 2rem;
  display: grid; place-items: center;
  background: var(--paper);
  color: var(--ink);
  border-radius: 0.35rem;
  font-weight: 800;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.25);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr) minmax(200px, 280px);
  gap: 0.45rem;
  padding: 0 0.4rem 0.4rem;
  min-height: 0;
  overflow: hidden;
}

.players, .dock {
  position: relative;
  z-index: 2;
  padding: 0.7rem;
  overflow: auto;
  min-width: 0;
  min-height: 0;
  background: rgba(12, 8, 6, 0.92);
}

.seat {
  padding: 0.55rem 0.6rem;
  border-radius: 0.7rem;
  margin-bottom: 0.45rem;
  border: 1px solid transparent;
  background: rgba(243, 230, 200, 0.06);
}
.seat.on { border-color: var(--gold); background: rgba(212, 160, 23, 0.12); }
.seat-top { display: flex; justify-content: space-between; gap: 0.4rem; font-weight: 700; }
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; display: inline-block; margin-right: 0.35rem; vertical-align: middle; border: 1px solid rgba(0,0,0,0.25); }
.seat-meta { font-size: 0.8rem; color: #d9cbb0; margin: 0.2rem 0 0; }

.board-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 42%, #3a8fb5 0%, #1f5f7a 55%, #16384a 100%);
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  touch-action: none;
  overflow: hidden;
}
.hint {
  position: absolute;
  left: 0.7rem; right: 0.7rem; bottom: 0.6rem;
  margin: 0;
  text-align: center;
  font-weight: 700;
  text-shadow: 0 1px 8px #0e3344;
}

.you-banner { font-weight: 800; margin-bottom: 0.4rem; }
.hand { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.6rem; }
.chip {
  min-width: 3.2rem;
  padding: 0.35rem 0.45rem 0.3rem;
  border-radius: 0.55rem;
  text-align: center;
  color: #1c100c;
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}
.chip small { display: block; font-weight: 700; font-size: 0.68rem; opacity: 0.8; }
.chip.on { outline: 2px solid #fff; }
.res-wood { background: #3d7a58; color: #f3e6c8; }
.res-brick { background: #c17048; }
.res-wheat { background: #e9c46a; }
.res-sheep { background: #8fd4a4; }
.res-ore { background: #8b9bb4; }

.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.7rem; }
.chat { display: flex; gap: 0.35rem; margin-bottom: 0.5rem; }
.chat input { margin: 0; }
.log {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.8rem;
  color: #d9cbb0;
  max-height: 28vh;
  overflow: auto;
}
.log li { padding: 0.18rem 0; border-bottom: 1px solid rgba(243,230,200,0.08); }

.modal {
  position: fixed; inset: 0;
  background: rgba(10, 6, 4, 0.55);
  display: grid; place-items: center;
  z-index: 20;
  padding: 1rem;
}
.modal-card {
  width: min(520px, 100%);
  background: #2a1c14;
  color: var(--paper);
  border-radius: 1rem;
  padding: 1.1rem 1.2rem 1.2rem;
  border: 1px solid rgba(243,230,200,0.18);
}
.modal-card h2 { margin-bottom: 0.5rem; }
.modal-card p { color: #e8dcc4; }
.picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.7rem 0; }
.modal-actions { display: flex; gap: 0.4rem; justify-content: flex-end; margin-top: 0.8rem; }

.toast {
  position: fixed;
  bottom: 1rem; left: 50%;
  transform: translateX(-50%);
  background: #8b2e22;
  color: #fff;
  padding: 0.55rem 0.9rem;
  border-radius: 0.6rem;
  z-index: 30;
  font-weight: 700;
}

.theme-pick {
  margin: 0.6rem 0 0;
  max-width: 16rem;
}
.theme-pick.bar-theme {
  margin: 0;
  max-width: none;
  font-size: 0.82rem;
  color: #e8dcc4;
}
.theme-pick select {
  width: 100%;
}
.theme-pick.bar-theme select {
  width: auto;
  min-width: 9.5rem;
  margin: 0;
  padding: 0.35rem 0.55rem;
}
.board-zoom {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 3;
  display: flex;
  gap: 0.25rem;
}
.board-zoom .btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 8, 6, 0.55);
  font-size: 1.15rem;
  line-height: 1;
}

body[data-theme="nacht"] {
  --wood: #070b14;
  --cloth: #0a1220;
  --paper: #e8dcc0;
  --gold: #d4a84b;
  --ink: #e8dcc0;
  --muted: #8a7a5c;
}
body[data-theme="nacht"] .cloth {
  background:
    radial-gradient(900px 500px at 80% 0%, rgba(80, 120, 200, 0.22), transparent 50%),
    radial-gradient(700px 400px at 10% 100%, rgba(212, 168, 75, 0.12), transparent 45%),
    linear-gradient(180deg, #0a1020, #0d1a2e 48%, #070b14);
}
body[data-theme="nacht"] .board-wrap {
  background: radial-gradient(circle at 50% 42%, #1a3a58 0%, #0c1c2e 55%, #070e18 100%);
}
body[data-theme="nacht"] .panel, body[data-theme="nacht"] .game-card,
body[data-theme="nacht"] .players, body[data-theme="nacht"] .dock, body[data-theme="nacht"] .bar {
  background: rgba(8, 12, 22, 0.88);
}
body[data-theme="nacht"] .modal-card { background: #121a28; }
body[data-theme="nacht"] .hint { text-shadow: 0 1px 8px #061018; }

body[data-theme="karte"] {
  --wood: #3a2a18;
  --cloth: #cbb892;
  --paper: #f4ead0;
  --gold: #8b2e22;
  --ink: #3a2818;
  --muted: #6b5744;
}
body[data-theme="karte"] { color: #f4ead0; }
body[data-theme="karte"] .cloth {
  background:
    radial-gradient(1000px 600px at 30% 0%, rgba(232, 210, 160, 0.35), transparent 55%),
    linear-gradient(180deg, #4a3420, #3a2818 40%, #2a1c10);
}
body[data-theme="karte"] .board-wrap {
  background: radial-gradient(circle at 50% 42%, #8aadb8 0%, #5a7a88 58%, #3a5460 100%);
}
body[data-theme="karte"] .panel, body[data-theme="karte"] .game-card {
  background: rgba(58, 40, 20, 0.55);
  border-color: rgba(74, 48, 32, 0.35);
}
body[data-theme="karte"] .players, body[data-theme="karte"] .dock, body[data-theme="karte"] .bar {
  background: rgba(42, 28, 16, 0.92);
}
body[data-theme="karte"] .modal-card { background: #4a3420; }
body[data-theme="karte"] .code { background: #8b2e22; color: #f4ead0; }
body[data-theme="karte"] .hint { text-shadow: 0 1px 8px #3a5460; }

body[data-theme="polar"] {
  --wood: #062028;
  --cloth: #0a3038;
  --paper: #e8f8f4;
  --gold: #7ee0d0;
  --ink: #123038;
  --muted: #7aa8a0;
}
body[data-theme="polar"] { color: #e8f8f4; }
body[data-theme="polar"] .cloth {
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(126, 224, 208, 0.28), transparent 50%),
    radial-gradient(800px 450px at 100% 80%, rgba(160, 120, 220, 0.22), transparent 48%),
    linear-gradient(180deg, #0a2830, #062028 45%, #041820);
}
body[data-theme="polar"] .board-wrap {
  background: radial-gradient(circle at 50% 42%, #2a8898 0%, #1a5a6e 55%, #0e2838 100%);
}
body[data-theme="polar"] .panel, body[data-theme="polar"] .game-card {
  background: rgba(8, 32, 40, 0.55);
  border-color: rgba(126, 224, 208, 0.22);
}
body[data-theme="polar"] .players, body[data-theme="polar"] .dock, body[data-theme="polar"] .bar {
  background: rgba(6, 28, 36, 0.92);
}
body[data-theme="polar"] .btn.primary { color: #062028; }
body[data-theme="polar"] .code { color: #062028; }
body[data-theme="polar"] .modal-card { background: #0e3038; }
body[data-theme="polar"] .hint { text-shadow: 0 1px 8px #062028; }
body[data-theme="polar"] .lede, body[data-theme="polar"] .fine, body[data-theme="polar"] .hint,
body[data-theme="polar"] .seat-meta, body[data-theme="polar"] .log, body[data-theme="polar"] .phase {
  color: #c8ece4;
}

.legal-vertex { fill: rgba(255, 236, 179, 0.95); stroke: #2a1810; stroke-width: 0.03; cursor: pointer; }
.legal-edge { cursor: pointer; }
.legal-hex { filter: brightness(1.08); cursor: pointer; stroke: #ffe08a !important; }

@media (max-width: 900px) {
  .table { height: auto; max-height: none; overflow: visible; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(46vh, 56vh) auto;
    overflow: visible;
  }
  .players { display: flex; gap: 0.4rem; overflow: auto; }
  .seat { min-width: 9.5rem; margin: 0; }
  .board-wrap { height: 56vh; }
}

.win-banner {
  text-align: center;
  padding: 0.8rem;
  background: var(--gold);
  color: #2a1810;
  font-family: var(--display);
  font-size: 1.4rem;
}
