/* ================================================================
   SPIELKISTE – Design-System (Papier / Tinte / Sticker)
   Kein AI-Look: harte Schatten, Tintenränder, leichte Rotationen.
   ================================================================ */

:root {
  --paper: #f6efdd;
  --paper-2: #efe6cd;
  --paper-3: #e9ddbf;
  --ink: #2b2620;
  --ink-soft: #6b6155;
  --ink-faint: #a99c86;
  --red: #c1440e;
  --red-soft: #f6d9c9;
  --blue: #2f5d8a;
  --blue-soft: #d4e2ee;
  --green: #4a6b3a;
  --green-soft: #dde8d4;
  --yellow: #e9c46a;
  --yellow-soft: #f7eccb;
  --purple: #6a4c93;
  --line: var(--ink);
  --shadow: 4px 4px 0 rgba(43, 38, 32, 0.18);
  --shadow-sm: 3px 3px 0 rgba(43, 38, 32, 0.15);
  --font-hand: "Caveat", "Comic Sans MS", cursive;
  --font-body: "Nunito", system-ui, -apple-system, sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.43 0 0 0 0 0.38 0 0 0 0 0.29 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E"),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(43, 38, 32, 0.045) 31px 32px),
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(43, 38, 32, 0.045) 31px 32px);
  min-height: 100dvh;
}

.font-hand { font-family: var(--font-hand); font-weight: 700; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-lg { width: 26px; height: 26px; }

/* ---------- Topbar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: rgba(246, 239, 221, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 2px solid var(--ink);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.brand-mini { display: flex; align-items: center; gap: 8px; font-size: 22px; }
.brand-mini .ic { color: var(--red); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 2px solid var(--ink); border-radius: 999px;
  padding: 3px 10px; font-size: 13px; font-weight: 700;
  background: var(--paper-2);
}
.chip-sm { padding: 1px 8px; font-size: 12px; }
.chip-status { font-variant-numeric: tabular-nums; }
.chip-status[data-ok="1"] { background: var(--green-soft); }
.chip-status[data-ok="0"] { background: var(--red-soft); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font-body); font-weight: 800; font-size: 14px;
  color: var(--ink); background: #fffdf4;
  border: 2px solid var(--ink); border-radius: 10px;
  padding: 8px 14px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .06s ease, box-shadow .06s ease;
  user-select: none;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 5px 0 rgba(43,38,32,.2); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--red); color: #fff8ec; border-color: var(--ink); }
.btn-primary:disabled { background: var(--red-soft); color: var(--ink-soft); }
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--ink-faint); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 11px 20px; font-size: 16px; border-radius: 12px; }
.btn-tiny { padding: 2px 7px; font-size: 11px; border-radius: 6px; box-shadow: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  border: 2px solid var(--ink); background: #fffdf4;
  color: var(--ink); cursor: pointer; box-shadow: var(--shadow-sm);
}
.icon-btn:active { transform: translate(1px,1px); box-shadow: none; }

/* ---------- Karten / Panels ---------- */
.paper-card {
  background: #fffdf4;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  position: relative;
}
.sticker {
  display: inline-block;
  background: var(--yellow);
  border: 2px dashed var(--ink);
  border-radius: 8px;
  padding: 3px 12px;
  font-family: var(--font-hand); font-size: 18px; font-weight: 700;
  transform: rotate(-2deg);
  box-shadow: var(--shadow-sm);
}

/* ---------- Screens ---------- */
.screen { max-width: 1080px; margin: 0 auto; padding: 18px 14px 60px; }
.hero { text-align: center; padding: 26px 0 10px; }
.hero-badge { margin-bottom: 8px; }
.hero-title {
  font-size: clamp(58px, 12vw, 96px);
  line-height: 1; margin: 4px 0;
  transform: rotate(-1.5deg);
  color: var(--ink);
}
.hero-title::after {
  content: ""; display: block; width: 46%; margin: 8px auto 0;
  border-bottom: 5px solid var(--red);
  border-radius: 3px; transform: rotate(1deg);
}
.hero-sub { color: var(--ink-soft); font-size: 16px; line-height: 1.55; }

/* ---------- Startseite: Spiel-Kacheln ---------- */
.game-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px; margin-top: 26px;
}
.game-tile {
  background: #fffdf4; border: 2px solid var(--ink);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  position: relative; cursor: default;
  transition: transform .08s ease;
}
.game-tile:nth-child(odd) { transform: rotate(-0.6deg); }
.game-tile:nth-child(even) { transform: rotate(0.6deg); }
.game-tile:hover { transform: rotate(0) translateY(-3px); }
.game-tile .icon-wrap {
  width: 52px; height: 52px; border-radius: 12px;
  border: 2px solid var(--ink); background: var(--paper-2);
  display: flex; align-items: center; justify-content: center;
}
.game-tile .icon-wrap .ic { width: 40px; height: 40px; }
.game-tile h3 { font-size: 21px; margin: 6px 0 0; }
.game-tile .tagline { font-size: 13.5px; color: var(--ink-soft); flex: 1; line-height: 1.45; }
.game-tile .players-hint { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.tile-actions { display: flex; gap: 8px; margin-top: 6px; }
.tile-actions .btn { flex: 1; }
.tape {
  position: absolute; top: -11px; left: 50%; transform: translateX(-50%) rotate(-2deg);
  width: 92px; height: 24px;
  background: rgba(233, 196, 106, 0.85);
  border-left: 2px dashed rgba(43,38,32,.35); border-right: 2px dashed rgba(43,38,32,.35);
}

/* ---------- Beitritts-Karte ---------- */
.join-card { margin-top: 30px; text-align: center; }
.join-card h2 { margin: 0 0 2px; font-size: 26px; }
.join-row { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.code-input {
  font-family: var(--font-body); font-weight: 800; font-size: 22px;
  letter-spacing: 6px; text-transform: uppercase; text-align: center;
  width: 150px; padding: 8px 4px 8px 10px;
  border: 2px solid var(--ink); border-radius: 10px;
  background: #fffdf4; color: var(--ink);
  box-shadow: inset 2px 2px 0 rgba(43,38,32,.08);
}
.code-input:focus { outline: 3px solid var(--yellow); }

/* ---------- Lobby ---------- */
.lobby-grid { display: grid; grid-template-columns: 1fr 300px; gap: 18px; }
.lobby-main { display: flex; flex-direction: column; gap: 18px; }
.invite-panel { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.invite-panel h2 { margin: 0; font-size: 26px; }
.code-big {
  display: inline-block; font-family: var(--font-body); font-weight: 900;
  letter-spacing: 8px; font-size: 30px; color: var(--red);
  background: var(--paper-2); border: 2px dashed var(--ink);
  border-radius: 10px; padding: 2px 10px 2px 18px;
  transform: rotate(-1deg);
}
.invite-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#invite-qr {
  background: #fff; border: 2px solid var(--ink); border-radius: 10px;
  padding: 6px; box-shadow: var(--shadow-sm); image-rendering: pixelated;
}
.game-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0 14px; }
.picker-item {
  border: 2px solid var(--ink); border-radius: 12px; background: #fffdf4;
  padding: 10px; cursor: pointer; text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform .06s ease;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.picker-item:hover { transform: translateY(-2px); }
.picker-item.selected { background: var(--yellow-soft); box-shadow: 0 0 0 3px var(--yellow); }
.picker-item .ic { width: 30px; height: 30px; }
.picker-item .p-name { font-weight: 800; font-size: 13.5px; }
.picker-item .p-range { font-size: 11.5px; color: var(--ink-soft); font-weight: 700; }
.settings-grid { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 14px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.setting-row label { font-weight: 700; font-size: 14px; }
.setting-row select, .setting-row input[type="number"] {
  font-family: var(--font-body); font-weight: 700; font-size: 14px;
  border: 2px solid var(--ink); border-radius: 8px; background: #fffdf4;
  padding: 6px 10px; color: var(--ink); min-width: 130px;
}
.start-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Spielerliste ---------- */
.player-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex; align-items: center; gap: 8px;
  border: 2px solid var(--ink); border-radius: 10px;
  background: #fffdf4; padding: 6px 10px;
  box-shadow: var(--shadow-sm);
}
.player-list li.me { background: var(--yellow-soft); }
.player-list li.offline { opacity: .55; }
.player-list .p-name { font-weight: 800; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .p-name.spectator-name { font-weight: 700; color: var(--ink-soft); }
.player-dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--green); flex: none; }
.offline .player-dot { background: var(--ink-faint); }
.bot-tag { font-size: 10.5px; font-weight: 800; border: 1.5px solid var(--ink); border-radius: 6px; padding: 0 5px; background: var(--paper-2); }
.bot-row { margin-top: 10px; display: flex; gap: 8px; }

/* ---------- Spielbereich ---------- */
.game-layout { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.game-area { min-width: 0; }
.sidebar { position: sticky; top: 66px; }
.sidebar-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab {
  flex: 1; font-family: var(--font-body); font-weight: 800; font-size: 13.5px;
  border: 2px solid var(--ink); border-radius: 9px; background: transparent;
  padding: 6px; cursor: pointer; color: var(--ink);
}
.tab.active { background: var(--ink); color: var(--paper); }
.chat-log { height: 42dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px; }
.chat-msg { border: 2px solid var(--ink); border-radius: 10px; padding: 6px 10px; background: #fffdf4; box-shadow: var(--shadow-sm); font-size: 14px; line-height: 1.4; }
.chat-msg .c-name { font-weight: 900; font-size: 12.5px; display: block; margin-bottom: 1px; }
.chat-msg.system { background: var(--paper-2); border-style: dashed; font-size: 12.5px; color: var(--ink-soft); }
.chat-msg.self { background: var(--yellow-soft); }
.chat-msg .c-name.self { color: var(--red); }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input {
  flex: 1; min-width: 0; font-family: var(--font-body); font-weight: 600; font-size: 14px;
  border: 2px solid var(--ink); border-radius: 10px; padding: 7px 10px; background: #fffdf4; color: var(--ink);
}

/* ---------- Codenames ---------- */
.cn-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.cn-clue {
  border: 2px solid var(--ink); border-radius: 12px; background: #fffdf4;
  box-shadow: var(--shadow); padding: 10px 18px; text-align: center; min-width: 210px;
}
.cn-clue .clue-word { font-family: var(--font-hand); font-size: 34px; line-height: 1; }
.cn-clue .clue-num { font-size: 15px; font-weight: 800; color: var(--ink-soft); }
.cn-clue.team-red { background: var(--red-soft); }
.cn-clue.team-blue { background: var(--blue-soft); }
.cn-turn-banner {
  border: 2px dashed var(--ink); border-radius: 12px; padding: 8px 16px;
  font-weight: 800; font-size: 15px; background: var(--yellow-soft); transform: rotate(-1deg);
}
.cn-turn-banner.team-red { background: var(--red-soft); }
.cn-turn-banner.team-blue { background: var(--blue-soft); }
.cn-board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  margin-top: 14px; max-width: 720px;
}
.cn-card {
  aspect-ratio: 4 / 3.1;
  border: 2px solid var(--ink); border-radius: 10px;
  background: #fffdf4; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  padding: 6px; text-align: center;
  font-weight: 800; font-size: clamp(11px, 1.6vw, 15px);
  cursor: default; user-select: none;
  transition: transform .07s ease;
  word-break: break-word;
  position: relative;
}
.cn-card:nth-child(3n) { transform: rotate(.5deg); }
.cn-card:nth-child(4n) { transform: rotate(-.5deg); }
.cn-card.clickable { cursor: pointer; }
.cn-card.clickable:hover { transform: rotate(0) scale(1.04); z-index: 2; }
.cn-card.revealed { color: #fff; font-weight: 800; transform: rotate(0); }
.cn-card.revealed.team-red { background: var(--red); border-color: #7c2a08; }
.cn-card.revealed.team-blue { background: var(--blue); border-color: #1c3a58; }
.cn-card.revealed.team-neutral { background: var(--ink-faint); color: #fff; }
.cn-card.revealed.team-assassin { background: #1c1814; color: #f0e6d2; }
.cn-card.key-red::after, .cn-card.key-blue::after, .cn-card.key-neutral::after, .cn-card.key-assassin::after {
  content: ""; position: absolute; inset: -4px; border-radius: 13px; border: 3px solid; pointer-events: none;
}
.cn-card.key-red::after { border-color: var(--red); }
.cn-card.key-blue::after { border-color: var(--blue); }
.cn-card.key-neutral::after { border-color: var(--ink-faint); border-style: dashed; }
.cn-card.key-assassin::after { border-color: #1c1814; }
.cn-teams { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 16px; }
.cn-team {
  border: 2px solid var(--ink); border-radius: 10px; padding: 8px 14px;
  background: #fffdf4; box-shadow: var(--shadow-sm); font-size: 13.5px; min-width: 170px;
}
.cn-team.red { border-left: 8px solid var(--red); }
.cn-team.blue { border-left: 8px solid var(--blue); }
.cn-team h4 { margin: 0 0 4px; font-size: 14px; }
.cn-team .sm { font-weight: 800; color: var(--red); }
.cn-team .sb { font-weight: 800; color: var(--blue); }
.cn-log {
  margin-top: 14px; max-width: 720px; max-height: 150px; overflow-y: auto;
  border: 2px dashed var(--ink); border-radius: 10px; background: rgba(255,253,244,.6);
  padding: 8px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 3px;
}
.cn-clue-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.cn-clue-form input {
  font-family: var(--font-body); font-weight: 700; font-size: 16px;
  border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; background: #fffdf4; color: var(--ink);
}
.cn-clue-form .clue-word-input { flex: 1; min-width: 150px; }
.cn-clue-form .clue-num-input { width: 70px; text-align: center; }

/* ---------- Overlays ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 520px); }
.toast {
  display: flex; align-items: center; gap: 10px;
  border: 2px solid var(--ink); border-radius: 12px; background: #fffdf4;
  box-shadow: var(--shadow); padding: 10px 16px; font-weight: 700; font-size: 14.5px;
  animation: toast-in .18s ease;
}
.toast.error { background: var(--red-soft); }
.toast.ok { background: var(--green-soft); }
.toast .ic { color: var(--red); }
.toast.ok .ic { color: var(--green); }
@keyframes toast-in { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(43,38,32,.35); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 8px 8px 0 rgba(43,38,32,.25); padding: 22px; max-width: 440px; width: 100%;
  position: relative;
}
.modal h2 { font-family: var(--font-hand); font-size: 30px; margin: 0 0 6px; }
.modal .modal-body { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.modal input[type="text"] {
  font-family: var(--font-body); font-weight: 700; font-size: 17px;
  border: 2px solid var(--ink); border-radius: 10px; padding: 10px 14px; background: #fffdf4; color: var(--ink); width: 100%;
}
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.tape-modal { position: absolute; top: -13px; left: 50%; transform: translateX(-50%) rotate(-3deg); width: 110px; height: 26px; background: rgba(233,196,106,.9); border-left: 2px dashed rgba(43,38,32,.35); border-right: 2px dashed rgba(43,38,32,.35); }

/* ---------- Overlays: Spielende ---------- */
.game-over {
  margin-top: 18px; border: 3px solid var(--ink); border-radius: 16px;
  background: var(--yellow-soft); padding: 18px; text-align: center; box-shadow: var(--shadow);
}
.game-over h2 { font-family: var(--font-hand); font-size: 40px; margin: 0 0 4px; }
.game-over .go-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .lobby-grid, .game-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .chat-log { height: 30dvh; }
  .cn-board { gap: 6px; }
}
