:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --card: #1e222b;
  --card-2: #262b36;
  --ink: #f4f1ea;
  --muted: #9aa3b2;
  --line: #2c313c;
  --accent: #e5484d;
  --accent-2: #ff6b6b;
  --good: #46c98b;
  --gold: #f2c14e;
  --paper: #f6f1e7;
  --paper-ink: #14161b;
  --radius: 14px;
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
}
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 50% -10%, #1b1f28 0%, var(--bg) 60%);
  color: var(--ink);
  font-family:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px 14px calc(14px + var(--safe-b));
}

.boot {
  margin: auto;
  color: var(--muted);
}

/* ---------- typography ---------- */
h1,
h2,
h3 {
  margin: 0 0 8px;
  line-height: 1.1;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: 30px;
  text-align: center;
}
.brand .cut {
  display: inline-block;
  background: var(--paper);
  color: var(--paper-ink);
  padding: 0 8px;
  border-radius: 4px;
  transform: rotate(-2deg);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.brand .cut:nth-child(2) {
  transform: rotate(1.5deg);
}
.tagline {
  text-align: center;
  color: var(--muted);
  margin: 6px 0 22px;
}
.muted {
  color: var(--muted);
}
.center {
  text-align: center;
}

/* ---------- cards / layout ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.row.wrap {
  flex-wrap: wrap;
}
.spacer {
  flex: 1;
}
.stack > * + * {
  margin-top: 10px;
}

/* ---------- controls ---------- */
label.field {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type="text"],
input[type="number"] {
  width: 100%;
  height: var(--tap);
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 16px;
}
input:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

button {
  font: inherit;
  font-weight: 700;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s;
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: #fff;
}
button.good {
  background: linear-gradient(180deg, #59e0a0, var(--good));
  border-color: transparent;
  color: #06301f;
}
button.ghost {
  background: transparent;
}
button.full {
  width: 100%;
}
button.sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--muted);
}
.pill.hot {
  color: var(--accent-2);
  border-color: var(--accent);
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.code-chip {
  font-weight: 800;
  letter-spacing: 3px;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.round-chip {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- players ---------- */
.players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}
.player .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  flex: 0 0 auto;
}
.player.off .dot {
  background: #545b68;
}
.player.off {
  opacity: 0.55;
}
.player .name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player .tags {
  display: flex;
  gap: 6px;
  margin-left: 4px;
}
.tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 6px;
}
.tag.host {
  background: #2a3550;
  color: #a9c2ff;
}
.tag.kidnapper {
  background: #4a2230;
  color: var(--accent-2);
}
.tag.you {
  background: #22402f;
  color: var(--good);
}
.tag.done {
  background: #22402f;
  color: var(--good);
}
.tag.wait {
  background: #3a3320;
  color: var(--gold);
}
.player .score {
  margin-left: auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 22px;
  text-align: right;
}

/* ---------- prompt ---------- */
.prompt {
  background: linear-gradient(180deg, #232833, #1b1f28);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 16px;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}
.prompt .kicker {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 6px;
}

/* ---------- timer ---------- */
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 18px;
}
.timer.low {
  color: var(--accent-2);
}
.progress {
  height: 6px;
  background: var(--bg-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.9s linear;
}

/* ---------- tiles / note builder ---------- */
.note {
  min-height: 120px;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08),
    0 10px 24px rgba(0, 0, 0, 0.35);
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 27px,
    rgba(0, 0, 0, 0.05) 28px
  );
  touch-action: none;
}
.note.empty::before {
  content: "Tap words below to build your note. Drag to rearrange.";
  color: #8b8578;
  font-weight: 500;
  font-size: 14px;
  margin: auto;
}
.note-wrap {
  position: relative;
}

/* Keep the note you're assembling — and the timer — pinned while scrolling. */
.sticky-note,
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--bg);
  box-shadow: 0 8px 12px -8px rgba(0, 0, 0, 0.7);
}
.sticky-note {
  padding: 8px 0 4px;
}
.sticky-head {
  padding: 8px 0;
}
.sticky-note #wstatus {
  margin-bottom: 4px;
}

/* Red edge flash for the final seconds of the countdown. */
.edge-flash {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 46px;
  pointer-events: none;
  z-index: 90;
  opacity: 0;
}
.edge-flash.left {
  left: 0;
  background: linear-gradient(to right, rgba(229, 72, 77, 0.95), transparent);
}
.edge-flash.right {
  right: 0;
  background: linear-gradient(to left, rgba(229, 72, 77, 0.95), transparent);
}
body.time-critical .edge-flash {
  animation: edgePulse 0.8s ease-in-out infinite;
}
@keyframes edgePulse {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  body.time-critical .edge-flash {
    animation: none;
    opacity: 0.6;
  }
}

.reshuffle {
  margin: 8px 0 12px;
}
.reshuffle .hint {
  margin-top: 4px;
}

/* Live reactions on notes while the kidnapper judges. */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 2px 2px;
}
.reia {
  min-height: 34px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.reia.on {
  border-color: var(--accent);
  background: #33232e;
}
.reia .rc {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}
.reia:disabled {
  opacity: 1; /* read-only in reveal, but still legible */
  cursor: default;
}

/* Collapsible match settings in the lobby. */
.settings-card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
}
.settings-card > summary::-webkit-details-marker {
  display: none;
}
.settings-card > summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.15s;
}
.settings-card[open] > summary::after {
  transform: rotate(180deg);
}
.settings-card > summary .hint {
  font-weight: 400;
  margin-left: auto;
}
.settings-card > summary::after {
  margin-left: 4px;
}
.settings-card[open] > summary {
  margin-bottom: 12px;
}

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 2px;
}

.tile {
  font-weight: 700;
  font-size: 15px;
  padding: 7px 11px;
  border-radius: 6px;
  background: var(--paper);
  color: var(--paper-ink);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  user-select: none;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
/* Only the note-builder tiles are drag-reordered, so only they suppress
   the browser's touch gestures. Tray tiles must allow vertical scrolling. */
.note .tile {
  touch-action: none;
}
.tray .tile:nth-child(3n) {
  transform: rotate(-1.4deg);
}
.tray .tile:nth-child(3n + 1) {
  transform: rotate(1.1deg);
}
.tray .tile:nth-child(4n) {
  background: #ece4d3;
}
.tray .tile:nth-child(5n) {
  background: #efe9dc;
}
.note .tile {
  background: #fffdf8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.28);
}
.note .tile:nth-child(2n) {
  transform: rotate(-1.6deg);
}
.note .tile:nth-child(3n) {
  transform: rotate(1.4deg);
}
.tile.dragging {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: scale(1.08) rotate(-2deg);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.5);
  transition: none;
}
.tile.placeholder {
  background: rgba(0, 0, 0, 0.08);
  border-style: dashed;
  color: transparent;
  box-shadow: none;
}

/* read-only note (judging / reveal) — must NOT block touch-scrolling like the
   editable builder does, or the voting page becomes un-scrollable. */
.note.readonly,
.note.readonly .tile {
  touch-action: auto;
  cursor: default;
}
.note.readonly {
  min-height: auto;
}

.note-card {
  background: var(--paper);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
  border: 2px solid transparent;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.05s;
}
.note-card .note {
  box-shadow: none;
  background-image: none;
  margin: 0;
  min-height: auto;
}
.note-card.selectable:active {
  transform: translateY(1px);
}
.note-card.chosen {
  border-color: var(--accent);
}
.note-card.winner {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.25), 0 8px 18px rgba(0, 0, 0, 0.3);
}
.note-card .byline {
  color: var(--paper-ink);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 4px 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.note-card .byline .win {
  color: #9a7b12;
}
.note-card.mine .note {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* ---------- sticky action bar ---------- */
.actionbar {
  position: sticky;
  bottom: 0;
  margin: 8px -14px calc(-14px - var(--safe-b));
  padding: 12px 14px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, rgba(15, 17, 21, 0), var(--bg) 40%);
  display: flex;
  gap: 10px;
}
.actionbar button {
  flex: 1;
}

/* ---------- settings grid ---------- */
.settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.settings .full {
  grid-column: 1 / -1;
}

/* ---------- misc ---------- */
.big-status {
  text-align: center;
  padding: 30px 10px;
}
.big-status .emoji {
  font-size: 44px;
  display: block;
  margin-bottom: 10px;
}
.divider {
  height: 1px;
  background: var(--line);
  margin: 16px 0;
}
.count {
  font-variant-numeric: tabular-nums;
}
.hint {
  font-size: 13px;
  color: var(--muted);
}
.trophy {
  color: var(--gold);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%);
  background: #2a2f3a;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 100;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
  text-align: center;
}
.toast.err {
  border-color: var(--accent);
}

@media (min-width: 480px) {
  .brand {
    font-size: 38px;
  }
}
