/* ==================================================================
   Laumupenninn — skissulegt útlit: rúðustrikaður pappír, blek,
   handskrift og „handteiknaðir“ rammar.
   ================================================================== */

:root {
  --paper: #fbf8ef;
  --paper-2: #f3eedf;
  --card: #fffdf7;
  --ink: #2a2a33;
  --ink-soft: #5d5c66;
  --grid: rgba(70, 110, 180, 0.11);
  --marker: #ffd75e;      /* gulur yfirstrikunarpenni */
  --red: #e2513b;
  --blue: #2f6fb5;
  --green: #3b9a4b;
  --font-hand: "Patrick Hand", "Comic Sans MS", "Segoe Print", cursive;
  --font-title: "Caveat", "Patrick Hand", cursive;
  /* Ójöfn horn sem líta út fyrir að vera teiknuð með penna */
  --wobble: 255px 14px 225px 16px / 16px 225px 14px 255px;
  --wobble-2: 14px 225px 16px 255px / 255px 16px 225px 14px;
  --shadow: 3px 4px 0 var(--ink);
  --panel-w: 300px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-hand);
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 26px 26px;
}

button, input { font-family: inherit; }

/* ------------------------------------------------------------------
   Útlit: aðalsvæði + stigatafla til hægri
   ------------------------------------------------------------------ */
#layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: calc(22px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}
.screen.active { display: flex; }

/* Föst hæð: striginn má aldrei ýta skjánum niður fyrir sjónsvið. */
.screen-canvas {
  padding: 0;
  max-width: none;
  flex: none;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ------------------------------------------------------------------
   Fyrirsagnir og texti
   ------------------------------------------------------------------ */
.logo-wrap { text-align: center; margin: 18px 0 22px; }
h1.logo {
  font-family: var(--font-title);
  font-size: 3.4rem;
  line-height: 1;
  margin: 0;
  display: inline-block;
  position: relative;
  transform: rotate(-2deg);
}
h1.logo::after {
  /* yfirstrikun undir titli */
  content: "";
  position: absolute;
  left: -6px; right: -6px; bottom: 4px;
  height: 18px;
  background: var(--marker);
  z-index: -1;
  border-radius: 4px 12px 6px 14px;
  transform: rotate(1deg);
}
.logo-pen { font-size: 2.2rem; margin-left: 4px; display: inline-block; transform: rotate(10deg); }
.subtitle { color: var(--ink-soft); margin: 10px 0 0; font-size: 1.05rem; }

h2 {
  font-family: var(--font-title);
  font-size: 2.1rem;
  font-weight: 700;
  margin: 4px 0 8px;
  line-height: 1.1;
}
h3 {
  font-family: var(--font-title);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 18px 0 6px;
}

.hint { color: var(--ink-soft); font-size: 1rem; }
.error-text { color: var(--red); min-height: 1.2em; margin-top: 10px; font-size: 1rem; }

.code-pill {
  display: inline-block;
  background: var(--marker);
  color: var(--ink);
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  font-family: var(--font-hand);
  font-weight: 700;
  letter-spacing: 0.12em;
  transform: rotate(-2deg);
}
.code-pill-big { font-size: 2.2rem; padding: 0 16px; }

/* ------------------------------------------------------------------
   Takkar, reitir, spjöld
   ------------------------------------------------------------------ */
.btn {
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  padding: 12px 18px;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--ink);
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active:not(:disabled) { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-big { width: 100%; padding: 15px; font-size: 1.35rem; }
.btn-primary { background: var(--marker); }
.btn-secondary { background: var(--card); border-radius: var(--wobble-2); }
.btn-danger { background: #ffd9d4; color: #b3261e; border-radius: var(--wobble-2); margin-top: 18px; font-size: 0.95rem; }

.input {
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-2);
  color: var(--ink);
  padding: 12px 14px;
  font-size: 1.2rem;
  width: 100%;
  outline: none;
}
.input:focus { box-shadow: 0 0 0 4px rgba(255, 215, 94, 0.7); }
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
  width: auto;
  flex: 1;
  min-width: 0;
}

.field-label { display: block; margin: 14px 0 6px; font-size: 1.15rem; }

.card-stack { display: flex; flex-direction: column; gap: 18px; margin-top: 6px; }
.inline-form { display: flex; gap: 10px; }
.inline-form .btn { flex: none; white-space: nowrap; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); }
.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-top: 2px dashed rgba(42, 42, 51, 0.35);
}

.paper-card {
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-2);
  box-shadow: var(--shadow);
  padding: 6px 16px 18px;
}

.doodle-note {
  margin-top: 30px;
  background: #fff6b8;
  padding: 14px 16px;
  font-size: 1rem;
  line-height: 1.35;
  transform: rotate(1.2deg);
  box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.12);
  position: relative;
}
.doodle-note::before {
  /* límband */
  content: "";
  position: absolute;
  top: -10px; left: 50%;
  width: 80px; height: 20px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(200, 200, 200, 0.55);
}

/* ------------------------------------------------------------------
   Fígúruval
   ------------------------------------------------------------------ */
.figure-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 4px 0 16px;
}
.figure-btn {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  background: var(--paper);
  font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.figure-btn:nth-child(odd) { border-radius: var(--wobble-2); }
.figure-btn.selected {
  background: var(--marker);
  box-shadow: 2px 3px 0 var(--ink);
  transform: rotate(-4deg) scale(1.06);
}
.figure-btn.taken { opacity: 0.2; pointer-events: none; }

/* ------------------------------------------------------------------
   Leikmannalistar
   ------------------------------------------------------------------ */
.player-list { list-style: none; margin: 8px 0 20px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.player-list li {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
}
.player-list li:nth-child(even) { border-radius: var(--wobble-2); transform: rotate(0.4deg); }
.player-list li:nth-child(odd) { transform: rotate(-0.4deg); }
.player-figure { font-size: 1.5rem; }
.player-name { flex: 1; min-width: 0; }
.player-badge {
  font-size: 0.85rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--wobble-2);
  padding: 0 8px;
  background: var(--paper-2);
}
.player-offline { opacity: 0.45; }
.player-score { font-weight: 700; font-size: 1.3rem; }

.vote-list li { cursor: pointer; }
.vote-list li.voted-for { background: var(--marker); box-shadow: var(--shadow); }
.vote-list li.disabled { opacity: 0.3; pointer-events: none; }
.vote-progress { text-align: center; font-size: 1.2rem; }

/* ------------------------------------------------------------------
   Hlutverkaspjald
   ------------------------------------------------------------------ */
.role-card {
  margin: auto;
  text-align: center;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble-2);
  box-shadow: 5px 6px 0 var(--ink);
  padding: 40px 24px 26px;
  width: 100%;
  transform: rotate(-1.2deg);
  position: relative;
}
.role-card::before {
  content: "";
  position: absolute;
  top: -12px; left: 50%;
  width: 110px; height: 24px;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(200, 200, 200, 0.6);
}
.role-text { font-size: 1.5rem; margin-bottom: 26px; line-height: 1.4; }
.role-text .impostor,
.role-text .word {
  display: inline-block;
  font-family: var(--font-title);
  font-size: 3.2rem;
  font-weight: 700;
  margin-top: 6px;
  padding: 0 12px;
  background: var(--marker);
  transform: rotate(-2deg);
}
.role-text .impostor { color: var(--red); background: transparent; border-bottom: 4px solid var(--red); }

/* ------------------------------------------------------------------
   Teikning og umræður
   ------------------------------------------------------------------ */
.draw-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 2.5px solid var(--ink);
  background: var(--paper);
}
.draw-header-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.draw-round { font-size: 1.05rem; color: var(--ink-soft); }
.draw-turn { font-size: 1.35rem; }
.draw-turn.my-turn {
  display: inline-block;
  align-self: flex-start;
  background: var(--marker);
  padding: 0 8px;
  transform: rotate(-1deg);
}
.draw-turn .offline-tag { color: var(--red); font-size: 1rem; }

.peek-btn {
  border: 2px solid var(--ink);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--wobble-2);
  padding: 2px 12px;
  font-size: 1rem;
  max-width: 65%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.peek-btn.revealed { background: var(--marker); }
.peek-btn.revealed.impostor { background: #ffd0c8; color: var(--red); }

/* Striginn hefur alltaf sömu hlutföll (3:4) svo myndin líti eins út
   á öllum skjám. Stærðin er reiknuð í app.js út frá .canvas-wrap. */
.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
}
canvas {
  box-sizing: content-box; /* ramminn er utan við teikniflötinn */
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 6px 10px 5px 12px;
  box-shadow: 4px 5px 0 var(--ink);
  touch-action: none;
  display: block;
  -webkit-user-select: none;
  user-select: none;
}

.bottom-bar {
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 2.5px solid var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  text-align: center;
}
.bottom-bar .hint { margin: 0; }
.bottom-bar .btn { width: 100%; max-width: 420px; }
.discuss-title { font-family: var(--font-title); font-weight: 700; font-size: 1.9rem; margin: 0; line-height: 1.1; }

/* ------------------------------------------------------------------
   Niðurstaða og stigatöflur
   ------------------------------------------------------------------ */
.reveal-banner {
  text-align: center;
  font-family: var(--font-title);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  padding: 16px 14px;
  margin-top: 8px;
  border: 3px solid currentColor;
  border-radius: var(--wobble);
  transform: rotate(-1.5deg);
}
.reveal-banner.success { color: var(--green); background: rgba(59, 154, 75, 0.08); }
.reveal-banner.fail { color: var(--red); background: rgba(226, 81, 59, 0.08); }
.reveal-word { text-align: center; font-size: 1.3rem; margin: 14px 0 0; }
.reveal-word strong { background: var(--marker); padding: 0 6px; }

.scoreboard li { justify-content: space-between; }
.scoreboard li.is-impostor { background: #ffe3dc; }
.player-game-points { width: 3.2em; text-align: center; color: var(--ink-soft); }
.player-game-points.plus { color: var(--green); font-weight: 700; }
.scoreboard .player-score { width: 3.2em; text-align: right; }
.score-head { display: flex; gap: 10px; padding: 0 14px; color: var(--ink-soft); font-size: 0.95rem; }
.score-head span:first-child { flex: 1; text-align: left !important; padding-left: 36px; }
.score-head span { width: 3.2em; text-align: center; }
.score-head span:last-child { text-align: right; }
.impostor-tag {
  font-size: 0.85rem;
  color: var(--red);
  border: 1.5px solid var(--red);
  border-radius: var(--wobble-2);
  padding: 0 6px;
  margin-left: 4px;
  white-space: nowrap;
}

.host-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ------------------------------------------------------------------
   Stigatafla til hægri
   ------------------------------------------------------------------ */
.score-panel {
  display: none;
  flex-direction: column;
  width: var(--panel-w);
  padding: calc(18px + env(safe-area-inset-top)) 18px 24px;
  background: var(--paper-2);
  background-image: repeating-linear-gradient(transparent 0 31px, rgba(47, 111, 181, 0.16) 31px 32px);
  border-left: 2.5px solid var(--ink);
  overflow-y: auto;
}
body.in-room .score-panel { display: flex; }

.score-panel-head { display: flex; align-items: center; justify-content: space-between; }
.score-panel-title { margin: 0; transform: rotate(-1.5deg); }
.score-close {
  display: none;
  border: 2px solid var(--ink);
  background: var(--card);
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 1rem;
  cursor: pointer;
}

.standings { list-style: none; padding: 0; margin: 10px 0 6px; display: flex; flex-direction: column; gap: 6px; }
.standings li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  background: var(--card);
  font-size: 1.1rem;
}
.standings li:nth-child(even) { border-radius: var(--wobble-2); }
.standings li.me { background: #fff3c0; }
.standings li.offline { opacity: 0.5; }
.standings .rank { width: 1.4em; font-family: var(--font-title); font-weight: 700; font-size: 1.4rem; text-align: center; }
.standings li.first .rank { font-size: 1.1rem; }
.standings .st-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .st-delta { font-size: 0.95rem; color: var(--green); min-width: 2em; text-align: right; }
.standings .st-delta.zero { color: var(--ink-soft); }
.standings .st-total { font-weight: 700; font-size: 1.35rem; min-width: 1.6em; text-align: right; }

.rules-card {
  margin-top: 16px;
  background: #fff6b8;
  padding: 4px 14px 10px;
  transform: rotate(-1deg);
  box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.12);
}
.rules-card h3 { margin-top: 6px; }
.rules { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 1rem; line-height: 1.25; }
.rules li { display: flex; gap: 8px; align-items: baseline; }
.rule-pts {
  flex: none;
  min-width: 2.2em;
  text-align: center;
  font-weight: 700;
  border: 2px solid var(--ink);
  border-radius: 50%;
  padding: 0 4px;
  background: var(--card);
}
.rule-pts.plus { color: var(--green); }
.rule-pts.big { color: var(--red); }

.history { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 8px; }
.history li {
  border-bottom: 2px dashed rgba(42, 42, 51, 0.3);
  padding: 2px 0 8px;
  font-size: 1rem;
  line-height: 1.3;
}
.history .h-title { display: flex; justify-content: space-between; font-weight: 700; }
.history .h-result.win { color: var(--green); }
.history .h-result.lose { color: var(--red); }
.history .h-word { background: var(--marker); padding: 0 4px; }

.score-toggle {
  display: none;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  z-index: 40;
  width: 46px; height: 46px;
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  background: var(--marker);
  box-shadow: 2px 3px 0 var(--ink);
  font-size: 1.3rem;
  cursor: pointer;
}
.score-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(42, 42, 51, 0.35);
  z-index: 44;
}

/* Breiður skjár: stigataflan er alltaf sýnileg hægra megin. */
@media (min-width: 900px) {
  .score-panel {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    flex: none;
  }
}

/* Mjór skjár (sími): stigataflan rennur inn frá hægri. */
@media (max-width: 899px) {
  body.in-room .score-toggle { display: block; }
  body.in-room .draw-header { padding-right: 66px; }
  body.in-room .screen:not(.screen-canvas) { padding-right: 66px; }
  .score-panel {
    display: flex;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(86vw, var(--panel-w));
    z-index: 45;
    transform: translateX(105%);
    transition: transform 0.22s ease-out;
    box-shadow: -6px 0 0 rgba(42, 42, 51, 0.15);
  }
  body:not(.in-room) .score-panel { visibility: hidden; }
  body.score-open .score-panel { transform: translateX(0); }
  body.score-open .score-backdrop { display: block; }
  .score-close { display: block; }
}
@media (max-width: 420px) {
  body.in-room .screen:not(.screen-canvas) { padding-right: 20px; padding-top: calc(66px + env(safe-area-inset-top)); }
}

/* ------------------------------------------------------------------
   Tilkynningar
   ------------------------------------------------------------------ */
.hidden { display: none !important; }

.conn-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  background: var(--red);
  color: #fff;
  text-align: center;
  font-size: 1rem;
  padding: calc(4px + env(safe-area-inset-top)) 12px 4px;
  border-bottom: 2.5px solid var(--ink);
}

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px) rotate(-1deg);
  background: #fff6b8;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--wobble-2);
  box-shadow: var(--shadow);
  padding: 10px 18px;
  font-size: 1.1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  text-align: center;
  z-index: 70;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-1deg); }

/* Prufuleikmenn */
.btn-add-bot { margin-bottom: 14px; border-style: dashed; box-shadow: none; }
.bot-remove {
  border: 2px solid var(--ink);
  background: var(--card);
  border-radius: 50%;
  width: 30px; height: 30px;
  font-size: 0.85rem;
  cursor: pointer;
  flex: none;
}

/* Hlekkur aftur í leikjavalmyndina */
.back-to-menu {
  align-self: flex-start;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
  border-bottom: 2px dashed rgba(42, 42, 51, 0.4);
}
.back-to-menu:hover { border-bottom-style: solid; }
