:root {
  --bg: #f6efe2;
  --paper: #fffdf8;
  --ink: #2a251f;
  --muted: #7d7366;
  --line: #e6dbc8;
  --accent: #ff6a3d;
  --accent-soft: #ffe3d8;
  --ok: #2f9e5b;
  --ok-soft: #dcf3e4;
  --warn: #c98a00;
  --warn-soft: #fff1c9;
  --danger: #d93b3b;
  --radius: 14px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}

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

html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 1px 1px, rgba(42, 37, 31, .07) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
}

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.15; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
small, .muted { color: var(--muted); }

/* ---------- basiselementen ---------- */

.card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 4px 0 var(--ink);
  padding: 14px;
}

button {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: .5em 1em;
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  transition: transform .06s, box-shadow .06s, background .15s;
}
button:hover:not(:disabled) { background: #fff6e8; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #ff7d55; }
button.danger { background: var(--danger); color: #fff; }
button.ghost { box-shadow: none; border-color: var(--line); }
button.wide { width: 100%; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: .5em .7em;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; }
.field > span, .field > legend { font-weight: 700; font-size: .9rem; padding: 0; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.row.wrap { flex-wrap: wrap; gap: 16px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-weight: 600; }

/* ---------- startscherm ---------- */

.home { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.home-card { width: min(400px, 100%); padding: 28px; }
.logo { font-size: 3rem; letter-spacing: -.02em; margin: 0; }
.logo span { display: inline-block; transform: rotate(12deg); margin-left: 6px; font-size: .8em; }
.tagline { margin: 4px 0 22px; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 10px; margin: 20px 0 12px; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 2px dashed var(--line); }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; text-align: center; }

/* ---------- room-layout ---------- */

.room {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 290px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "players main chat";
  gap: 14px;
  height: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 14px;
}

.topbar { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 10px 14px; }
.room-code { white-space: nowrap; }
.room-code b { letter-spacing: .15em; font-size: 1.15rem; }
.game-info { flex: 1; display: flex; align-items: center; justify-content: center; gap: 16px; min-width: 0; }
.round { color: var(--muted); font-weight: 700; white-space: nowrap; }

.word { display: flex; align-items: baseline; gap: 10px; font-weight: 800; font-size: 1.3rem; flex-wrap: wrap; justify-content: center; }
.word .label { font-size: .9rem; color: var(--muted); font-weight: 700; }
.word .reveal { color: var(--accent); letter-spacing: .04em; }
.word .mask { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.word .ch { display: inline-block; min-width: .8em; text-align: center; border-bottom: 3px solid var(--ink); line-height: 1.1; text-transform: lowercase; }
.word .ch.blank { color: transparent; }
.word .gap { display: inline-block; width: .7em; }
.word .count { font-size: .8rem; color: var(--muted); }

.timer {
  min-width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--ink); font-weight: 800; font-size: 1.1rem; background: #fff;
}
.timer.low { background: var(--accent); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* spelers */
.players { grid-area: players; overflow: auto; }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; background: #fff; border: 2px solid var(--line);
}
.player .rank { font-weight: 800; color: var(--muted); width: 1.4em; }
.player .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.player .score { font-weight: 800; }
.player .tags { display: flex; gap: 2px; }
.player.me { border-color: var(--ink); }
.player.guessed { background: var(--ok-soft); border-color: var(--ok); }
.player.drawing { background: var(--accent-soft); border-color: var(--accent); }
.player.offline { opacity: .5; }

/* midden */
.main { grid-area: main; min-height: 0; display: flex; flex-direction: column; }
.lobby { overflow: auto; }
.lobby h2 { font-size: 1.5rem; }
.pack-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.pack {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  padding: 10px; border: 2px solid var(--line); border-radius: 10px; background: #fff;
}
.pack:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pack input { margin-top: 3px; accent-color: var(--accent); }
.pack b { display: block; }
.pack small { display: block; }
.lobby-footer { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; padding-top: 12px; border-top: 2px dashed var(--line); }
.lobby-footer #btn-start { margin-left: auto; font-size: 1.1rem; padding: .6em 1.6em; }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.board-area { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board {
  position: relative; background: #fff;
  border: 2px solid var(--ink); border-radius: var(--radius); box-shadow: 0 4px 0 var(--ink);
  overflow: hidden;
}
.board canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.board.can-draw canvas { cursor: crosshair; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(255, 253, 248, .97); text-align: center; overflow: auto;
}
.overlay-card { max-width: 440px; width: 100%; }
.overlay h2 { font-size: 1.6rem; }
.big-word { font-size: 2.4rem !important; color: var(--accent); }
.choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.choices button { font-size: 1.15rem; }
.turn-points, .podium { list-style: none; padding: 0; margin: 14px 0; display: flex; flex-direction: column; gap: 6px; }
.turn-points li, .podium li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 12px; background: #fff; border: 2px solid var(--line); border-radius: 10px;
}
.turn-points .plus { color: var(--ok); }
.podium li { align-items: center; }
.podium .medal { width: 2em; text-align: left; }
.podium .pname { flex: 1; text-align: left; font-weight: 700; }
.podium .top1 { font-size: 1.25rem; border-color: var(--ink); background: var(--warn-soft); }

/* gereedschap */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; padding: 10px; }
.toolbar .group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar .group + .group { padding-left: 12px; border-left: 2px dashed var(--line); }
.toolbar .tool, .toolbar .size { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; font-size: 1.1rem; box-shadow: 0 2px 0 var(--ink); }
.toolbar .active { background: var(--accent-soft); outline: 3px solid var(--accent); outline-offset: 1px; }
.swatch { width: 28px; height: 28px; padding: 0; border-radius: 50%; background: var(--c) !important; box-shadow: none; }
.swatch.active { outline: 3px solid var(--ink); outline-offset: 2px; }
.size .dot { width: var(--s); height: var(--s); border-radius: 50%; background: var(--ink); }

/* chat */
.chat { grid-area: chat; display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.msg { padding: 3px 8px; border-radius: 8px; overflow-wrap: anywhere; }
.msg:nth-child(odd) { background: rgba(42, 37, 31, .03); }
.msg.system { color: var(--muted); font-style: italic; }
.msg.correct { background: var(--ok-soft) !important; color: var(--ok); font-weight: 700; }
.msg.close { background: var(--warn-soft) !important; color: var(--warn); font-weight: 700; }
.msg.secret { color: var(--ok); }
.msg.secret::before { content: "🤫 "; }
.chat-form { border-top: 2px solid var(--ink); }
.chat-form input { width: 100%; border: 0; border-radius: 0; padding: 12px; }

/* ---------- mobiel ---------- */

@media (max-width: 900px) {
  .room {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "top" "main" "chat" "players";
    height: auto; padding: 10px; gap: 10px;
  }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .game-info { order: 3; flex-basis: 100%; }
  #btn-leave { margin-left: auto; }
  .board-area { height: min(75vw, 64vh); flex: none; }
  .chat { height: 260px; }
  .player-list { flex-direction: row; flex-wrap: wrap; }
  .player { flex: 1 1 150px; }
}

/* ---------- beheerpagina ---------- */

.admin { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.admin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.admin-head a { color: var(--ink); font-weight: 700; }
.admin-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.admin-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.admin-list button { width: 100%; text-align: left; display: flex; justify-content: space-between; box-shadow: none; border-color: var(--line); }
.admin-list button.active { border-color: var(--accent); background: var(--accent-soft); }
.between { justify-content: space-between; }
.link { background: none; border: 0; box-shadow: none; text-decoration: underline; padding: 0; color: var(--muted); font-weight: 600; }
.file { font-weight: 700; cursor: pointer; }
#save-status { font-weight: 700; color: var(--ok); }
@media (max-width: 760px) { .admin-grid { grid-template-columns: 1fr; } }
