:root {
  --blue: #2743f0; --navy: #1b2668; --ink: #26324b;
  --card: #ffffff; --dim: #8a93b5;
  --yellow: #ffc933; --orange: #ff9c1a; --green: #35c65a; --red: #ff5c5c;
  --sky: #58b8ff;
  --r: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0; height: 100dvh; overflow: hidden;
  background: var(--blue) url(/assets/pattern.png) repeat center / 480px;
  color: var(--ink);
  font: 600 15px/1.4 "Baloo 2", ui-rounded, system-ui, sans-serif;
  display: flex; flex-direction: column;
}

/* ------------------------------------------------- header */
header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 18px; gap: 12px; }
#logo { height: 54px; margin: 2px 0; object-fit: contain; filter: drop-shadow(0 3px 0 rgba(0,0,0,.25)); }
.h-side { display: flex; align-items: center; gap: 8px; }
.h-side.left { justify-content: flex-start; }
.h-side.right { justify-content: flex-end; }
.tagline { color: #cdd7ff; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; font-size: 12px; text-shadow: 0 1px 0 rgba(0,0,0,.3); }
.pill {
  white-space: nowrap;
  background: var(--card); color: var(--ink); border: 3px solid var(--navy); border-radius: 30px;
  padding: 3px 12px; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 var(--navy);
}
.pill.dim { color: var(--dim); cursor: default; }
#name {
  width: 130px; background: var(--card); color: var(--ink); border: 3px solid var(--navy);
  border-radius: 12px; padding: 4px 10px; font: inherit; font-weight: 700; box-shadow: 0 3px 0 var(--navy);
}
#name:focus, #guess:focus { outline: none; border-color: var(--sky); }

/* ------------------------------------------------- layout */
main { flex: 1; display: flex; gap: 14px; padding: 0 18px 14px; min-height: 0; }
.card { background: var(--card); border-radius: var(--r); box-shadow: 0 6px 0 rgba(0,0,0,.22); }

#playersCard { width: 250px; overflow-y: auto; padding: 10px; }
#players { list-style: none; margin: 0; padding: 0; }
#players li { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-bottom: 2px solid #eef1fb; }
#players li:last-child { border-bottom: none; }
#players li img.av { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--navy); background: #ffe9b3; }
#players li .who { flex: 1; min-width: 0; }
#players li .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
#players li .who span { color: var(--dim); font-size: 13px; }
#players li .mark { font-size: 20px; width: 26px; text-align: center; }
#players li.guessed .mark::before { content: "✔"; color: var(--green); font-weight: 800; }
#players li.drawing .mark::before { content: "✏️"; }

#stageCard { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 12px 14px; }
#wordBar { display: flex; align-items: center; gap: 14px; padding: 0 4px 8px; }
#status { color: var(--dim); font-weight: 700; }
#word { flex: 1; text-align: center; font-size: 24px; font-weight: 800; letter-spacing: 7px; color: var(--ink); }
#timer { font-size: 20px; font-weight: 800; color: var(--orange); min-width: 48px; text-align: right; }

#media { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; container-type: size; }
#frame {
  position: relative; aspect-ratio: 16/9;
  width: min(100cqw, calc(100cqh * 16 / 9));
  background: #fff; border-radius: 12px; overflow: hidden; border: 3px solid #e8ecfa;
}
.screen { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; opacity: 0; transition: opacity 0.45s; }
.screen.show { opacity: 1; }
#pad { position: absolute; inset: 0; width: 100%; height: 100%; display: none; touch-action: none; cursor: crosshair; background: #fff; -webkit-touch-callout: none; user-select: none; }

/* drawer: canvas fills the frame, live render becomes a corner PiP */
body.drawer #pad { display: block; }
body.drawer .screen { inset: auto 10px 10px auto; top: 10px; right: 10px; left: auto; width: 30%; height: auto; aspect-ratio: 16/9; border: 3px solid var(--navy); border-radius: 10px; box-shadow: 0 5px 14px rgba(0,0,0,.35); z-index: 4; background: #000; }

#tools { position: absolute; left: 10px; bottom: 10px; display: none; gap: 6px; z-index: 5; }
body.drawer #tools { display: flex; }
#tools button, #mute {
  background: var(--card); border: 3px solid var(--navy); border-radius: 10px; box-shadow: 0 3px 0 var(--navy);
  font-size: 16px; padding: 4px 9px; cursor: pointer;
}
#tools button.on { background: var(--yellow); }
#mute { position: absolute; right: 10px; bottom: 10px; z-index: 5; }
body.drawer #mute { display: none; }
#genState { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: var(--navy); color: #fff; border-radius: 20px; padding: 2px 12px; font-size: 12px; z-index: 5; }
#genState:empty { display: none; }

#timerBar { height: 12px; border-radius: 8px; background: var(--navy); margin-top: 10px; overflow: hidden; }
#timerFill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--orange), var(--yellow)); border-radius: 8px; transition: width 0.25s linear; }

#chatCard { width: 300px; display: flex; flex-direction: column; padding: 10px; position: relative; }
.cardTab {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; border-radius: 9px; padding: 2px 16px; font-weight: 800; letter-spacing: 1px; font-size: 13px;
}
#feed { list-style: none; margin: 10px 0 0; padding: 4px; flex: 1; overflow-y: auto; min-height: 0; }
#feed li { padding: 2px 4px; word-break: break-word; font-weight: 600; }
#feed li.sys { color: var(--dim); font-style: italic; }
#feed li.correct { color: var(--green); font-weight: 800; }
#feed li.close { color: var(--orange); font-weight: 800; }
#feed li.club { color: var(--dim); }
#guessRow { display: flex; gap: 6px; }
#guessRow input {
  flex: 1; min-width: 0; background: #fff; color: var(--ink); border: 3px solid var(--navy); border-radius: 12px;
  padding: 9px 12px; font: inherit; font-weight: 700;
}
#guessRow button {
  background: var(--yellow); border: 3px solid var(--navy); border-radius: 12px; box-shadow: 0 3px 0 var(--navy);
  padding: 0 14px; font-size: 16px; cursor: pointer;
}

/* ------------------------------------------------- overlays */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 80, .55); display: flex; align-items: center; justify-content: center; z-index: 10; }
.card.modal { padding: 26px 30px 22px; min-width: 340px; max-width: 500px; max-height: 82vh; overflow-y: auto; text-align: center; position: relative; }
.ribbon {
  background: url(/assets/ribbon.png) center / contain no-repeat;
  width: 300px; aspect-ratio: 542 / 149; margin: -52px auto 8px;
  display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.25));
}
.ribbon span { color: #fff; font-weight: 800; letter-spacing: 2px; font-size: 15px; text-shadow: 0 2px 0 rgba(0,0,0,.35); padding-bottom: 4px; }
.modal h2 { margin: 4px 0 10px; font-size: 32px; font-weight: 800; color: var(--blue); letter-spacing: 1px; }
.dim { color: var(--dim); }
.modal ul { list-style: none; padding: 0; margin: 8px 0 0; text-align: left; }
.modal li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 2px; border-bottom: 2px solid #eef1fb; }
.modal li:last-child { border-bottom: none; }
.modal li:only-child { justify-content: center; color: var(--dim); }
.modal li span { color: var(--green); font-weight: 800; }
.modal p:empty { display: none; }
#resNext { margin: 10px 0 0; }
#resReason { margin: 0 0 4px; }
#resDrawing { width: 100%; background: #fff; border: 3px solid var(--navy); border-radius: 12px; margin: 6px 0 2px; }
#pickWords { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#pickWords button, #lbTabs button {
  background: var(--sky); color: #fff; border: 3px solid var(--navy); border-radius: 14px; box-shadow: 0 4px 0 var(--navy);
  padding: 12px; font: inherit; font-size: 18px; font-weight: 800; cursor: pointer;
}
#pickWords button:hover { background: var(--yellow); color: var(--ink); }
#lbTabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
#lbTabs button { padding: 5px 14px; font-size: 14px; }
#lbTabs button.on { background: var(--yellow); color: var(--ink); }

#falBadge {
  position: fixed; left: 14px; bottom: 12px; z-index: 6;
  background: var(--navy); color: #cdd7ff; border-radius: 20px; padding: 5px 14px;
  font-size: 12px; font-weight: 700; box-shadow: 0 3px 8px rgba(0,0,0,.35);
}
#falBadge b { color: #fff; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: var(--yellow); border-radius: 30px; padding: 9px 18px; z-index: 20; font-weight: 800;
}
[hidden] { display: none !important; }

@media (max-width: 900px) {
  main { flex-direction: column; gap: 8px; padding: 0 8px 26px; }
  header { padding: 6px 10px; gap: 8px; }
  .tagline { display: none; }
  #logo { height: 40px; margin: 0; }
  #name { width: 88px; font-size: 16px; padding: 3px 8px; }
  .pill { padding: 2px 9px; font-size: 12px; }

  /* players become a horizontal strip */
  #playersCard { order: 1; width: 100%; padding: 6px 8px; overflow-x: auto; overflow-y: hidden; flex: none; }
  #players { display: flex; gap: 4px; }
  #players li { flex-direction: column; border-bottom: none; padding: 0 6px; min-width: 66px; text-align: center; gap: 2px; flex: none; }
  #players li img.av { width: 38px; height: 38px; border-width: 2px; }
  #players li .who b { font-size: 11px; max-width: 66px; }
  #players li .who span { font-size: 10px; display: block; }
  #players li .mark { font-size: 13px; width: auto; height: 16px; }

  #stageCard { order: 2; flex: none; padding: 8px; }
  #wordBar { padding: 0 2px 6px; gap: 8px; }
  #status { font-size: 12px; }
  #word { font-size: 17px; letter-spacing: 4px; }
  #timer { font-size: 16px; min-width: 40px; }
  #media { flex: none; display: block; container-type: normal; }
  #frame { width: 100%; height: auto; }
  #timerBar { height: 9px; margin-top: 8px; }
  #tools { gap: 5px; left: 8px; bottom: 8px; }
  #tools button { font-size: 17px; padding: 7px 11px; }
  body.drawer .screen { width: 34%; top: 8px; right: 8px; }

  #chatCard { order: 3; width: 100%; flex: 1; min-height: 140px; }
  #feed li { font-size: 14px; }
  #guessRow input { font-size: 16px; padding: 11px 12px; } /* 16px stops iOS focus zoom */

  .card.modal { min-width: 0; width: calc(100vw - 40px); padding: 22px 18px 18px; }
  .ribbon { width: min(260px, 70vw); margin-top: -46px; }
  .modal h2 { font-size: 26px; }
  #pickWords button { font-size: 16px; padding: 11px; }

  #falBadge { font-size: 10px; padding: 3px 10px; left: 8px; bottom: 5px; box-shadow: none; }
}
