:root {
  --bg: #f4f1ea;
  --ink: #1f2937;
  --muted: #6b7280;
  --card: #fff;
  --line: #d6d3cb;
  --block: #1f2937;
  --host: #2563eb;
  --host-soft: #dbe6fd;
  --guest: #db2777;
  --guest-soft: #fbdcea;
  --wrong: #dc2626;
  --sel: #fde68a;
  --word: #fef3c7;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; border: 0; border-radius: 10px; padding: 10px 14px;
  background: #e7e3da; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--ink); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); }
input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; }
[hidden] { display: none !important; }

/* Lobby */
#lobby { max-width: 480px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
h1 { margin: 8px 0 4px; font-size: 28px; }
h1 span { color: var(--guest); }
h2 { margin: 0 0 10px; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.card { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card p { margin: 0 0 10px; }
.card .primary { width: 100%; }
.row { display: flex; gap: 8px; }
#join-code { font-size: 14px; }
.puzzle-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.puzzle-list button { text-align: left; background: #f4f1ea; border: 2px solid transparent; padding: 10px; }
.puzzle-list button small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.puzzle-list button.on { border-color: var(--ink); }
.modes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.modes label { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; }
.modes small { grid-column: 2; color: var(--muted); font-size: 12px; }

/* Spiel */
#game { height: 100dvh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
header { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.chip { padding: 6px 10px; font-weight: 700; letter-spacing: 1px; background: #fff; }
.status { flex: 1; font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.who-host { color: var(--host); font-weight: 600; }
.who-guest { color: var(--guest); font-weight: 600; }
.turn-banner { margin: 0 10px 6px; padding: 6px 6px 6px 12px; border-radius: 10px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; min-height: 40px; }
.turn-banner span { flex: 1; }
.turn-banner button { padding: 6px 12px; background: var(--ink); color: #fff; font-size: 14px; }
.turn-banner.mine { background: #dcfce7; color: #166534; }
.turn-banner.theirs { background: #e5e7eb; color: var(--muted); }
.turn-banner.theirs button { display: none; }

/* Übersicht vs. Wortansicht */
#game.overview #word-head, #game.overview #keyboard { display: none; }
#game.editing #hint { display: none; }
#hint { margin: 6px 0 10px; text-align: center; font-size: 13px; color: var(--muted); }

#board-wrap { flex: 1; min-height: 0; overflow: hidden; position: relative; margin: 0 4px; touch-action: none; }
#board { position: absolute; left: 0; top: 0; display: grid; gap: 1px; user-select: none; -webkit-user-select: none;
  transform-origin: 0 0; font-size: 34px; }
#board.anim { transition: transform .3s ease; }
.cell { position: relative; background: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; text-transform: uppercase; border-radius: 3px; outline: 1px solid var(--line); }
.cell.block { background: transparent; outline: none; }
.by-host .ch, .slot.by-host { color: var(--host); }
.by-guest .ch, .slot.by-guest { color: var(--guest); }
.cell.partner-word { background: var(--pw-soft); }
.cell.ok, .slot.ok { background: #dcfce7; }
.cell.word { background: var(--word); }
.cell.sel { background: var(--sel); }
.cell.partner-sel { box-shadow: inset 0 0 0 4px var(--pw); }
.cell.wrong .ch, .slot.wrong { color: var(--wrong); text-decoration: line-through; }
.cell.wrong, .slot.wrong { background: #fee2e2; }
.solved .cell:not(.block):not(.clue) { background: #dcfce7; }

/* Frage-Kästchen im Gitter (Schwedenrätsel) */
.cell.clue { background: #e8e4da; outline-color: #cfc9bb; flex-direction: column; align-items: stretch;
  text-transform: none; font-weight: 600; color: #3f3a30; cursor: pointer; }
.cell.clue .q { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 10.5px; line-height: 1.05; padding: 1px 2px 1px 1px; hyphens: auto; overflow-wrap: anywhere; overflow: hidden; }
.cell.clue .q + .q { border-top: 1px solid #cfc9bb; }
.cell.clue .q i { position: absolute; font-style: normal; font-size: 8px; color: #8a8273; }
.cell.clue .q[data-dir=across] i { right: 1px; top: 50%; transform: translateY(-50%); }
.cell.clue .q[data-dir=down] i { bottom: 0; left: 50%; transform: translateX(-50%); }
.cell.clue .q.ok { background: #bbf7d0; color: #166534; }
.cell.clue .q.bad { background: #fecaca; color: #991b1b; }
.cell.clue .q.partner { background: var(--pw-soft); }
.cell.clue .q.active { background: var(--sel); color: var(--ink); }

/* Wortansicht: Kopf mit Frage + Kästchen */
#word-head { margin: 0 8px 6px; background: #fff; border-radius: 14px; padding: 6px 6px 10px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.wh-top { display: flex; align-items: center; gap: 2px; }
.wh-top button { background: transparent; padding: 8px 10px; }
#clue-text { flex: 1; font-size: 16px; line-height: 1.25; text-align: center; }
#clue-text b { margin-right: 6px; }
#slots { display: flex; justify-content: center; gap: 4px; margin-top: 6px; }
.slot { width: min(34px, calc((100vw - 60px) / var(--n))); aspect-ratio: 1 / 1.15; border: 2px solid var(--line); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; background: #fafaf7; cursor: pointer; }
.slot.active { border-color: var(--ink); background: var(--sel); }

#keyboard { padding: 4px 4px 8px; display: flex; flex-direction: column; gap: 6px; }
.krow { display: flex; gap: 4px; justify-content: center; }
.krow button { flex: 1; max-width: 44px; padding: 13px 0; font-weight: 600; font-size: 17px; background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.15); border-radius: 7px; }
.krow button.wide { max-width: 72px; flex: 1.6; font-size: 15px; }
#keyboard.locked button { opacity: .35; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: #fff; width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; }
.sheet > button { text-align: left; background: #f4f1ea; }
.sheet.center { text-align: center; }
.sheet.center > button { text-align: center; }
.sheet .big { font-size: 56px; }
.toast { position: fixed; left: 50%; bottom: 40%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 20; font-size: 14px; }
body:not(.is-host) .host-only { display: none; }

/* Einladen */
a.btn { display: block; padding: 10px 14px; border-radius: 10px; background: #25d366; color: #fff; font-weight: 600; text-decoration: none; }
#qr { width: min(220px, 60vw); margin: 0 auto; }
#qr svg { width: 100%; height: auto; display: block; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0; }
#invite-link { font-size: 12px; color: var(--muted); text-align: center; }
