/* Querpackey tabletop design tokens. */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("/static/vendor/fraunces/fraunces-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/static/vendor/inter/inter-latin.woff2") format("woff2");
}

:root {
  --felt: #4A5B51;
  --felt-deep: #2E3B34;
  --felt-shadow: #1B241F;
  --paper: #FBF7EC;
  --paper-bright: #FFFDF4;
  --paper-edge: #D8CFBA;
  --input-edge: #8F846C;
  --scrim-score: rgba(10, 15, 12, 0.50);
  --scrim-dice: rgba(10, 15, 12, 0.10);
  /* The score sheet is paper at 92% over the scrimmed table.  Nearly opaque,
     so the dice read as a faint texture behind the card instead of a hole in
     it, while ink keeps 14.9:1 and muted ink 5.2:1 on the worst backdrop
     (a bright die face under the 50% scrim). */
  --sheet-opacity: 0.92;
  --sheet-blur: 6px;
  --ink: #161C19;
  --ink-muted: #5A665F;
  --cream: #F7F1E3;
  --cream-dim: rgba(247, 241, 227, 0.80);
  --hairline: rgba(247, 241, 227, 0.22);
  --hairline-strong: rgba(247, 241, 227, 0.55);
  --brass: #C9A227;
  --brass-bright: #E3C05A;     /* felt only, never on paper */
  --brass-deep: #6B5211;        /* text-safe brass on paper */
  --oxide: #A6402F;
  --oxide-bright: #D46A57;     /* felt only, never on paper */
  --success: #35704C;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1.0625rem;
  --text-lg: 1.375rem;
  --text-xl: 2rem;
  --display: clamp(2.5rem, 6vw, 3.75rem);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-card: 0 24px 60px rgba(10, 15, 12, 0.38);
  --shadow-control: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 2px 0 var(--brass-deep);
  --shadow-tile: 0 1px 0 var(--paper-edge), 0 2px 4px rgba(22, 28, 25, 0.10);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --fast: 120ms;
  --base: 200ms;
  --slow: 320ms;
  --motion-press: 90ms;
  --motion-hover: 120ms;
  --motion-entry: 250ms;
  --motion-chip: 180ms;
  --motion-pill: 200ms;
  --motion-dot: 150ms;
  --motion-stamp: 180ms;
  --motion-timer: 1s;
  --motion-score: 220ms;
  --motion-count: 500ms;
  --motion-tile: 20ms;
}

/* Base styles. */
* {
  box-sizing: border-box;
}

body {
  background: var(--felt);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  height: 100%;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

html, body {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

/* Touch targets: every button is at least 44x44 CSS pixels.  Flex centering
   keeps the label centered when the theme's fixed line-height is shorter. */
button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

section#entry :focus-visible,
section#lobby .rules-card :focus-visible,
section#score :focus-visible {
  outline-color: var(--ink);
}

h1, h2, h3 {
  font-family: var(--font-display);
}

button, input, select, textarea {
  font: inherit;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

form {
  margin-block-end: 1em;
}

table {
  background: transparent;
}
table th, table td {
  border: none;
  margin: 2px 0;
  padding: 4px 0;
}

/* Content available to assistive technology but not shown visually. */
.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

/* Modal dialogs. */
#modal-shade {
  background: rgba(0, 0, 0, 0.5);
  height: 100%;
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 98;
}
body:not(.modal) #modal-shade {
  display: none;
}
body:not(.modal) #modal {
  display: none;
}
#modal {
  z-index: 99;
}
body.modal {
  height: 100%;
  overflow: hidden;
}

#modal {
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
}

#modal button {
  margin: 1ex;
  width: 15em;
}

/* Messages. */
#messages {
  bottom: 0;
  margin: 1ex;
  opacity: 0.8;
  position: fixed;
  right: 0;
  width: min(500px, calc(100% - 2ex));
  z-index: 5;
}
#messages .alert {
  animation: 7s ease-out;
  animation-name: message;
}
@keyframes message {
    0% { opacity: 1.0; }
    90% { opacity: .0; }
   100% { opacity: 0.0; }
}

/********************************* Sections ***********************************/

/* The body carries a `view-*` id; section ids stay unprefixed. */
body:not(#view-connecting) section#connecting,
body:not(#view-error) section#error,
body:not(#view-entry) section#entry,
body:not(#view-lobby) section#lobby,
body:not(#view-game) section#game
{
  display: none;
}

/* #score is a fixed overlay controlled by .visible class, not by view-* */
section#score {
  display: flex;
}

/********************************** Loading ***********************************/

section#connecting {
  margin: auto;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
}

/*********************************** Error ************************************/

section#error {
  margin: 20%;
}

/*********************************** Entry ************************************/

section#entry {
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 5vh 1rem 1rem;
  width: min(520px, 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (prefers-reduced-motion: no-preference) {
  section#entry .invitation-card {
    animation: entry-arrive var(--motion-entry) var(--ease) both;
  }
}

section#entry .invitation-card {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 40px;
  width: 100%;
}

section#entry h1 {
  color: var(--ink);
  font-size: var(--display);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 0;
  text-align: center;
}

section#entry .wordmark-rule {
  background: var(--brass);
  display: block;
  height: 2px;
  margin: 16px auto 28px;
  width: 24px;
}

section#entry form {
  margin: 0;
}

section#entry form > p:first-child {
  color: var(--ink-muted);
  margin: 0 0 20px;
}

section#entry .field-stack {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

section#entry .field-stack label {
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-top: 16px;
  text-transform: uppercase;
}

section#entry .field-stack input {
  width: 100%;
}

section#entry .field-stack label:first-child {
  margin-top: 0;
}

section#entry .alert {
  margin: 16px 0;
}

section#entry button[type="submit"] {
  margin-top: var(--s3);
  min-height: 48px;
  width: 100%;
}

@media (max-width: 480px) {
  section#entry {
    padding: 1rem;
  }
  section#entry .invitation-card {
    padding: 24px;
  }
}

@keyframes entry-arrive {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/*********************************** Lobby ************************************/

section#lobby {
  margin: auto;
  max-width: 1120px;
  min-width: 0;
  padding: max(2rem, env(safe-area-inset-top)) 1rem env(safe-area-inset-bottom);
  text-align: left;
}

section#lobby .lobby-invite {
  color: var(--cream-dim);
  font-size: var(--text-sm);
  margin: 0 0 var(--s4);
}

section#lobby .lobby-grid {
  align-items: start;
  display: grid;
  gap: var(--s6);
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.8fr);
}

section#lobby .table-card,
section#lobby .rules-card {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  color: var(--ink);
  padding: var(--s5);
}

section#lobby .table-card {
  align-items: center;
  display: flex;
  gap: var(--s3);
  justify-content: space-between;
  min-width: 0;
}

section#lobby .table-card-copy {
  min-width: 0;
}

section#lobby #table-name {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0 0 var(--s1);
  overflow-wrap: anywhere;
}

section#lobby #table-url {
  color: var(--ink-muted);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  margin: 0;
  overflow-wrap: anywhere;
}

section#lobby #copy-table-link {
  flex: 0 0 auto;
}

section#lobby #copy-table-link svg,
section#lobby .handicap-marker svg {
  fill: none;
  height: 1rem;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  width: 1rem;
}

section#lobby #copy-table-link.copied {
  border-color: var(--success);
  color: var(--success);
}

section#lobby .roster-heading {
  align-items: center;
  display: flex;
  gap: var(--s2);
  margin: var(--s5) 0 var(--s2);
}

section#lobby .roster-heading h2 {
  color: var(--cream);
  font: 600 var(--text-sm) var(--font-ui);
  letter-spacing: 0.08em;
  margin: 0;
  text-transform: uppercase;
}

section#lobby .roster-count {
  align-items: center;
  background: var(--brass);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: var(--text-xs);
  font-weight: 600;
  height: 24px;
  justify-content: center;
  min-width: 24px;
  padding: 0 6px;
}

section#lobby ul.players {
  display: grid;
  gap: var(--s2);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

@media (prefers-reduced-motion: no-preference) {
  section#lobby ul.players li {
    animation: player-arrive var(--motion-chip) var(--ease) both;
    animation-delay: calc(var(--arrival-index, 0) * var(--motion-tile));
  }
}

section#lobby ul.players li {
  align-items: center;
  background: rgba(247, 241, 227, 0.08);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  color: var(--cream);
  display: flex;
  gap: var(--s2);
  margin: 0;
  min-height: 48px;
  padding: var(--s2);
}

section#lobby ul.players li.me {
  border-color: var(--brass);
}

section#lobby .player-initials {
  align-items: center;
  background: var(--brass);
  border-radius: 50%;
  color: var(--ink);
  display: inline-flex;
  flex: 0 0 32px;
  font-size: var(--text-xs);
  font-weight: 600;
  height: 32px;
  justify-content: center;
}

section#lobby .player-name {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
}

section#lobby .you-marker {
  background: var(--brass-bright);
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 6px;
  height: 6px;
  overflow: hidden;
  text-indent: -999px;
  width: 6px;
}

section#lobby .handicap-marker {
  color: var(--oxide-bright);
  display: inline-flex;
}

@keyframes player-arrive {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

section#lobby .begin {
  margin: var(--s4) 0 0;
}

section#lobby .begin button {
  min-height: 48px;
  width: 100%;
}

section#lobby form .alert {
  margin-bottom: var(--s2);
}

section#lobby .rules-card {
  margin: 0;
  text-align: left;
}

section#lobby .rules-card h2 {
  border-bottom: 1px solid var(--paper-edge);
  color: var(--brass-deep);
  font: 600 var(--text-xs) var(--font-ui);
  letter-spacing: 0.08em;
  margin: 0 0 var(--s4);
  padding-bottom: var(--s2);
  text-transform: uppercase;
}

section#lobby .handicap-toggle {
  align-items: center;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-size: var(--text-sm);
  gap: var(--s2);
  margin: 0 0 var(--s5);
  position: relative;
}

section#lobby .handicap-toggle input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

section#lobby .switch-track {
  background: var(--input-edge);
  border-radius: 999px;
  flex: 0 0 40px;
  height: 24px;
  position: relative;
  transition: background-color var(--motion-hover) ease;
}

section#lobby .switch-track::after {
  background: var(--paper-bright);
  border-radius: 50%;
  content: "";
  height: 18px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform var(--motion-hover) ease;
  width: 18px;
}

section#lobby .handicap-toggle input:checked + .switch-track {
  background: var(--brass-deep);
}

section#lobby .handicap-toggle input:checked + .switch-track::after {
  transform: translateX(16px);
}

section#lobby .handicap-toggle input:focus-visible + .switch-track {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

section#lobby .round-length {
  border: 0;
  margin: 0;
  padding: 0;
}

section#lobby .round-length legend {
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: var(--s2);
  padding: 0;
  text-transform: uppercase;
}

section#lobby .round-length-options {
  border: 1px solid var(--input-edge);
  border-radius: var(--radius-md);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

section#lobby .round-length label {
  align-items: center;
  cursor: pointer;
  display: flex;
  justify-content: center;
  margin: 0;
  min-height: 44px;
  position: relative;
}

section#lobby .round-length label + label {
  border-left: 1px solid var(--paper-edge);
}

section#lobby .round-length input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

section#lobby .round-length label span {
  align-items: center;
  color: var(--ink);
  display: flex;
  font-size: var(--text-xs);
  height: 100%;
  justify-content: center;
  position: relative;
  width: 100%;
}

section#lobby .round-length input:checked + span {
  background: var(--brass);
  color: var(--ink);
  font-weight: 600;
}

section#lobby .round-length input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: -3px;
}

@media (max-width: 720px) {
  section#lobby .lobby-grid {
    grid-template-columns: 1fr;
  }
  section#lobby .rules-card {
    order: 2;
  }
}

@media (max-width: 480px) {
  section#lobby ul.players {
    grid-template-columns: 1fr;
  }
  section#lobby .table-card,
  section#lobby .rules-card {
    padding: var(--s4);
  }
  section#lobby #copy-table-link {
    font-size: 0;
    padding: 0.5rem;
  }
  section#lobby #copy-table-link svg {
    height: 1.25rem;
    width: 1.25rem;
  }
}

/************************************ Game ************************************/

/* The dice canvas: full viewport, touch-friendly. */
section#game #stage {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Focus the tray without changing the WebGL render. */
section#game #game-vignette {
  background: radial-gradient(
    ellipse at center,
    rgba(10, 15, 12, 0) 30%,
    rgba(10, 15, 12, 0.35) 100%
  );
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 2;
}

/* Live submitted-word groups, shown above the tray. */
section#game #word-group-summary {
  background: linear-gradient(to bottom, rgba(27, 36, 31, 0.68), rgba(27, 36, 31, 0));
  height: 4.1rem;
  left: 0;
  max-width: none;
  padding: 0.4rem 0.6rem 0.7rem;
  position: fixed;
  top: 0;
  transform: none;
  width: 100%;
  z-index: 10;
}
section#game #word-group-row {
  align-items: stretch;
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  width: 100%;
}

section#game .word-group-gap {
  flex: 0 0 auto;
  pointer-events: none;
}

section#game .word-group-pill {
  background: var(--felt-deep);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  color: var(--cream);
  flex: 1 1 0;
  font-size: clamp(0.75rem, 1.5vw, 0.95rem);
  font-weight: 600;
  height: 2.75rem;
  isolation: isolate;
  line-height: 1;
  max-width: 12rem;
  min-width: 0;
  overflow: hidden;
  padding: 0.35rem 0.7rem;
  position: relative;
  transition: border-color var(--motion-hover) ease, background-color var(--motion-hover) ease;
  white-space: nowrap;
}

section#game .word-group-pill::before {
  background: rgba(201, 162, 39, 0.08);
  border-bottom: 3px solid var(--brass);
  bottom: 0;
  content: "";
  height: 100%;
  inset-inline-start: 0;
  position: absolute;
  transition: width var(--motion-pill) ease;
  width: var(--word-group-progress, 0%);
  z-index: -1;
}

section#game .word-group-pill.complete {
  border-color: var(--brass);
}

section#game .word-group-pill.complete::after {
  background: var(--brass);
  border-radius: 50%;
  content: "";
  height: 4px;
  position: absolute;
  right: 6px;
  top: 6px;
  width: 4px;
}

@media (prefers-reduced-motion: no-preference) {
  section#game .word-group-pill.complete::after {
    animation: complete-dot-pop var(--motion-dot) var(--ease) both;
  }
}

@keyframes complete-dot-pop {
  from { opacity: 0; transform: scale(0.4); }
  to { opacity: 1; transform: scale(1); }
}

section#game .word-group-pill:hover {
  background: rgba(247, 241, 227, 0.08);
  border-color: var(--cream);
}

section#game .word-group-pill:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

section#game .word-group-label {
  display: none;
  position: relative;
}

section#game #word-group-row[data-label-mode="words"] .word-group-label-words,
section#game #word-group-row[data-label-mode="numeric"] .word-group-label-numeric {
  display: inline;
}

section#game #word-group-card {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  color: var(--ink);
  max-height: min(60vh, 28rem);
  max-width: min(90vw, 18rem);
  overflow-y: auto;
  padding: 0.75rem 1rem 0.9rem;
  position: fixed;
  width: max-content;
  z-index: 11;
}

section#game #word-group-card h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  text-align: center;
}

section#game #word-group-card ol {
  list-style: decimal;
  margin: 0;
  padding-left: 1.8rem;
}

section#game #word-group-card li {
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.45;
  text-transform: uppercase;
}

section#game #word-group-card li::marker {
  color: var(--brass-deep);
}

section#game.round-over #word-group-summary,
section#game.round-over #word-group-card {
  opacity: 0.5;
  pointer-events: none;
}

section#game #bottom-bar {
  background: linear-gradient(to top, rgba(27, 36, 31, 0.76), rgba(27, 36, 31, 0));
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 1em;
  left: 0;
  padding: 1.5rem 1em calc(0.5em + env(safe-area-inset-bottom));
  position: fixed;
  right: 0;
  z-index: 10;
}

section#game #bottom-bar-left {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

section#game #bottom-bar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

section#game #bottom-bar-right {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

section#game #timer {
  color: var(--cream);
  font-size: clamp(1.75rem, 10vw, 2em);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

section#game #timer.warning {
  color: var(--brass-bright);
}

/* The bottom scrim puts the timer on roughly felt-deep, where oxide-bright
   reaches 3.8:1; oxide itself is 2.2:1 there and fails as large text. */
section#game #timer.critical {
  color: var(--oxide-bright);
}

@media (prefers-reduced-motion: no-preference) {
  section#game #timer.critical {
    animation: timer-pulse var(--motion-timer) ease-in-out infinite;
  }
}

@keyframes timer-pulse {
  50% { opacity: 0.72; }
}

/* The word being built: a light, dice-like pill over the bottom center. */
section#game #active-word-pill {
  background: var(--paper-bright);
  border: 1px solid var(--ink);
  border-bottom-width: 2px;
  border-radius: 6px;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-tile);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 10vw, 2em);
  font-weight: 700;
  left: 50%;
  letter-spacing: 0.06em;
  line-height: 1;
  max-width: calc(100% - 2rem);
  opacity: 0;
  overflow: hidden;
  padding: 0.3em 0.75em;
  pointer-events: none;
  position: fixed;
  text-overflow: ellipsis;
  transform: translate(-50%, calc(100vh + 1rem));
  transition:
    opacity 0s linear var(--motion-score),
    transform var(--motion-score) ease-in,
    visibility 0s linear var(--motion-score);
  visibility: hidden;
  white-space: nowrap;
  z-index: 12;
}

section#game #active-word-pill.visible {
  opacity: 1;
  transform: translate(-50%, 0);
  transition: opacity var(--motion-stamp) ease;
  visibility: visible;
}

@media (max-width: 480px) {
  section#game #bottom-bar {
    flex-wrap: wrap;
    gap: 0.4em 0.8em;
    padding: 0.4em 0.6em calc(0.4em + env(safe-area-inset-bottom));
  }
  section#game #word-group-summary {
    max-width: 100%;
    padding: 0.3rem 0.35rem;
  }
  section#game #word-group-row {
    gap: 0.2rem;
  }
  section#game .word-group-pill {
    padding: 0.3rem 0.35rem;
  }
  section#game #bottom-bar-left,
  section#game #bottom-bar-right {
    flex: 1 1 50%;
  }
  section#game #bottom-bar-center {
    flex: 1 1 100%;
    order: 1;
    padding-top: 0.2em;
  }
  section#game #active-word-pill {
    font-size: clamp(1.65rem, 10vw, 1.9rem);
    max-width: calc(100% - 1.5rem);
  }
}

/* The round is over (server or local timer): dim the table, block input. */
section#game.round-over #stage {
  filter: none;
}

section#game.round-over::after {
  background: rgba(46, 59, 52, 0.45);
  content: "";
  inset: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity var(--base) ease;
  z-index: 2;
}

section#game.round-over #word-group-summary,
section#game.round-over #word-group-card,
section#game.round-over #bottom-bar,
section#game.round-over #timer {
  opacity: 0.5;
  pointer-events: none;
}

/* The "New Game" button sits on the game view after the final round; the
   score screen is where it is normally reached. */

section#game button[data="new-game"] {
  display: none;
  left: 50%;
  position: fixed;
  top: 48px;
  transform: translateX(-50%);
  z-index: 10;
}

section#game.over button[data="new-game"] {
  display: block;
}

/************************************ Score ***********************************/

/* Score overlay: a paper sheet at 92% over the table, with a reversible
   collapse that reveals the dice used this round. */
section#score {
  align-items: center;
  background: var(--scrim-score);
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 0;
  padding: 1rem;
  pointer-events: none;
  position: fixed;
  transition: background-color var(--motion-score) ease, opacity var(--motion-score) ease;
  z-index: 20;
}

section#score.visible {
  opacity: 1;
  pointer-events: auto;
}

section#score.dice-mode {
  background: var(--scrim-dice);
}

section#score .score-card {
  background: color-mix(in srgb, var(--paper) calc(var(--sheet-opacity) * 100%), transparent);
  -webkit-backdrop-filter: blur(var(--sheet-blur));
  backdrop-filter: blur(var(--sheet-blur));
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  color: var(--ink);
  max-height: calc(100dvh - 2rem);
  max-width: 760px;
  overflow-y: auto;
  padding: 0;
  text-align: left;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

section#score .score-header {
  align-items: center;
  background: inherit;
  border-bottom: 1px solid var(--paper-edge);
  display: grid;
  gap: var(--s3);
  grid-template-columns: minmax(0, 1fr) auto auto;
  padding: var(--s4) var(--s5);
  position: sticky;
  top: 0;
  z-index: 3;
}

section#score .score-heading-group {
  min-width: 0;
}

section#score #score-round {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.1;
  margin: 0;
}

section#score .score-heading-rule {
  background: var(--brass);
  display: block;
  height: 2px;
  margin-top: 10px;
  width: 32px;
}

section#score .score-summary {
  align-items: center;
  display: flex;
  gap: var(--s2);
  justify-content: flex-end;
}

section#score .score-points {
  color: var(--brass-deep);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
}

section#score .score-total {
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

section#score .rank-badge {
  align-items: center;
  background: var(--brass);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: var(--text-xs);
  font-weight: 600;
  height: 28px;
  justify-content: center;
  min-width: 28px;
  padding: 0 8px;
}

section#score .score-collapse {
  border-color: var(--input-edge);
  color: var(--ink);
  gap: 6px;
}

section#score .score-collapse:hover:not(:disabled) {
  background: rgba(22, 28, 25, 0.05);
  color: var(--ink);
}

section#score .score-collapse svg,
section#score .crown-icon svg {
  fill: none;
  height: 1rem;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 1rem;
}

section#score .crown-icon {
  color: var(--brass-deep);
  display: inline-flex;
  vertical-align: -2px;
}

section#score .crown-icon svg {
  fill: var(--brass);
  stroke: var(--brass-deep);
}

section#score .winner-strip {
  align-items: center;
  background: linear-gradient(110deg, var(--brass) 0%, var(--brass) 42%, rgba(255, 253, 244, 0.55) 50%, var(--brass) 58%, var(--brass) 100%);
  background-size: 220% 100%;
  color: var(--ink);
  display: flex;
  font-family: var(--font-display);
  font-weight: 600;
  gap: 6px;
  justify-content: center;
  padding: 10px var(--s5);
}

section#score #score-winner:empty {
  display: none;
}

section#score .score-content {
  display: grid;
  gap: var(--s6);
  grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr);
  padding: var(--s5);
}

section#score .score-words h3 {
  color: var(--brass-deep);
  font: 600 var(--text-xs) var(--font-ui);
  letter-spacing: 0.08em;
  margin: 0 0 var(--s3);
  text-transform: uppercase;
}

section#score .score-standings {
  min-width: 0;
}

section#score table {
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin: 0;
  min-width: 0;
  text-align: left;
  width: 100%;
}

section#score table thead th {
  border-bottom: 1px solid var(--paper-edge);
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 8px 6px;
  text-transform: uppercase;
}

section#score table tbody th,
section#score table tbody td {
  border-bottom: 1px solid var(--paper-edge);
  height: 40px;
  padding: 6px;
}

section#score table tbody th {
  color: var(--ink-muted);
  font-weight: 500;
  width: 42px;
}

section#score table tbody td:nth-child(3),
section#score table tbody td:nth-child(4) {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

section#score table tr.me {
  background: rgba(201, 162, 39, 0.08);
  box-shadow: inset 2px 0 0 var(--brass);
}

section#score table tr.winner {
  font-weight: 600;
}

section#score .winner-name {
  font-weight: 600;
}

section#score .word-review {
  margin: 0;
  text-align: left;
}

section#score .accepted-words {
  margin-bottom: var(--s4);
}

section#score .words-grid {
  display: grid;
  gap: var(--s3);
  grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
  text-align: center;
}

section#score .word-column {
  align-items: stretch;
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

section#score .column-header {
  align-items: baseline;
  color: var(--ink-muted);
  display: flex;
  font-size: 11px;
  font-weight: 600;
  justify-content: space-between;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  text-transform: uppercase;
}

section#score .column-count {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

section#score .word-list,
section#score .extra-details,
section#score .rejected-details {
  list-style: none;
  margin: 0;
  padding: 0;
}

section#score .word-list li,
section#score .extra-details li,
section#score .rejected-details li {
  border-radius: 6px;
  margin: 3px 0;
}

section#score .word-list li.accepted {
  background: var(--cream);
  border: 1px solid var(--paper-edge);
  border-bottom-width: 2px;
  box-shadow: var(--shadow-tile);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 9px 10px;
  text-transform: uppercase;
}

section#score .accepted-icon,
section#score .word-times-icon {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  vertical-align: -2px;
}

section#score .accepted-icon {
  color: var(--success);
  margin-right: 4px;
}

section#score .word-times-icon {
  color: var(--oxide);
  margin-right: 3px;
}

section#score .accepted-icon svg,
section#score .word-times-icon svg {
  fill: none;
  height: 0.8em;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 0.8em;
}

section#score .word-list li.bonus-word {
  position: relative;
}

section#score .word-list li.bonus-word::after {
  color: var(--brass-deep);
  content: "★";
  font-size: 0.7em;
  position: absolute;
  right: 3px;
  top: -5px;
}

section#score .extra-words,
section#score .rejected-words {
  border-top: 1px solid var(--paper-edge);
  margin-top: var(--s3);
  padding-top: var(--s3);
}

section#score .extra-label,
section#score .rejected-label {
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: var(--s2);
  text-transform: uppercase;
}

section#score .rejected-label .red,
section#score .rejected-label {
  color: var(--oxide);
}

section#score .extra-details,
section#score .rejected-details {
  display: grid;
  gap: var(--s2);
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

section#score .extra-details li {
  background: rgba(22, 28, 25, 0.06);
  color: var(--ink-muted);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  padding: 9px 10px;
  text-transform: uppercase;
}

section#score .rejected-details li {
  background: rgba(166, 64, 47, 0.09);
  border-left: 2px solid var(--oxide);
  color: var(--oxide);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
}

section#score .rejected-details .word {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

section#score .rejected-details .reason {
  color: var(--oxide);
  font-size: 11px;
  line-height: 1.35;
}

section#score .empty {
  color: var(--ink-muted);
  margin: 0;
}

section#score #score-error {
  margin: 0 var(--s5) var(--s3);
}

section#score #score-actions {
  background: inherit;
  border-top: 1px solid var(--paper-edge);
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  padding: var(--s3) var(--s5) calc(var(--s3) + env(safe-area-inset-bottom));
  position: sticky;
  z-index: 3;
}

section#score #next-round {
  flex: 1 1 180px;
}

section#score #score-new-game {
  flex: 0 1 160px;
}

section#score #score-new-game.primary {
  background: var(--brass);
  border-color: var(--brass-deep);
  box-shadow: var(--shadow-control);
  color: var(--ink);
}

section#score .dice-review-bar[hidden] {
  display: none;
}

section#score .dice-review-bar {
  align-items: center;
  background: color-mix(in srgb, var(--paper) calc(var(--sheet-opacity) * 100%), transparent);
  -webkit-backdrop-filter: blur(var(--sheet-blur));
  backdrop-filter: blur(var(--sheet-blur));
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-md);
  bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-card);
  color: var(--ink);
  display: flex;
  gap: var(--s3);
  justify-content: space-between;
  left: 50%;
  max-width: calc(100% - 2rem);
  padding: 6px 6px 6px var(--s4);
  position: fixed;
  transform: translateX(-50%);
  z-index: 22;
}

section#score .dice-review-bar span {
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

section#score.dice-mode .score-card {
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
}

@media (prefers-reduced-motion: no-preference) {
  section#score .score-card {
    transition: opacity var(--motion-score) var(--ease), transform var(--motion-score) var(--ease);
  }
  section#score .dice-review-bar {
    animation: dice-review-arrive 180ms var(--ease) both;
  }
  section#score .winner-strip {
    animation: winner-sheen 650ms var(--ease) both;
  }
  section#score .word-list li,
  section#score .extra-details li,
  section#score .rejected-details li {
    animation: score-tile-arrive var(--motion-tile) var(--ease) both;
    animation-delay: calc(var(--tile-index, 0) * var(--motion-tile));
  }
}

@keyframes dice-review-arrive {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes winner-sheen {
  from { background-position: -100% 0; }
  to { background-position: 200% 0; }
}

@keyframes score-tile-arrive {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  section#score {
    padding: 0.5rem;
  }
  section#score .score-card {
    max-height: calc(100dvh - 1rem);
  }
  section#score .score-header {
    gap: var(--s2);
    grid-template-columns: minmax(0, 1fr) auto;
    padding: var(--s3);
  }
  section#score .score-summary {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-end;
  }
  section#score .score-collapse {
    grid-column: 2;
    grid-row: 1;
  }
  section#score .score-content {
    grid-template-columns: 1fr;
    padding: var(--s3);
  }
  section#score .score-standings {
    order: -1;
  }
  section#score #score-actions {
    padding: var(--s3);
  }
  section#score .dice-review-bar {
    bottom: calc(var(--s2) + env(safe-area-inset-bottom));
    width: calc(100% - 1rem);
  }
}

/*************************** Shared design components **************************/
button {
  background: var(--brass);
  border: 1px solid var(--brass-deep);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-control);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  padding: 0.65rem 1rem;
  transition: background-color var(--motion-hover) ease, border-color var(--motion-hover) ease,
    transform var(--motion-press) ease, box-shadow var(--motion-press) ease;
}

button:hover:not(:disabled) {
  background: var(--brass-bright);
  color: var(--ink);
}

button:active:not(:disabled) {
  box-shadow: 0 1px 0 var(--brass-deep);
  transform: translateY(1px);
}

button:disabled,
button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
}

button.button-light,
button.secondary,
section#game #shuffle-dice,
section#game #clear-word {
  background: transparent;
  border-color: var(--hairline-strong);
  box-shadow: none;
  color: var(--cream);
}

button.button-light:hover:not(:disabled),
button.secondary:hover:not(:disabled),
section#game #shuffle-dice:hover:not(:disabled),
section#game #clear-word:hover:not(:disabled) {
  background: rgba(247, 241, 227, 0.08);
  color: var(--cream);
}

button.button-danger,
button.danger-ghost {
  background: transparent;
  border-color: var(--oxide);
  box-shadow: none;
  color: var(--oxide);
}

button.button-danger:hover:not(:disabled),
button.danger-ghost:hover:not(:disabled) {
  background: rgba(166, 64, 47, 0.12);
  color: var(--oxide);
}

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
  background: var(--paper-bright);
  border: 1px solid var(--input-edge);
  border-radius: var(--radius-md);
  color: var(--ink);
  min-height: 44px;
  padding: 0.65rem 0.75rem;
}

input:not([type="checkbox"]):not([type="radio"]):focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--brass-deep);
  box-shadow: 0 0 0 2px var(--brass);
  outline: none;
  outline-offset: 0;
}

.alert {
  background: transparent;
  border: 0;
  border-left: 2px solid var(--brass);
  border-radius: 0;
  color: var(--ink);
  font-size: var(--text-sm);
  margin: 0;
  padding: 0.35rem 0.75rem;
}

.alert.alert-danger,
.alert.alert-warning {
  border-left-color: var(--oxide);
  color: var(--oxide);
}

.alert.alert-success {
  border-left-color: var(--success);
  color: var(--success);
}

.alert.alert-info {
  border-left-color: var(--brass-deep);
  color: var(--ink-muted);
}

.alert a {
  color: inherit;
}

.alert:empty {
  display: none;
}

/* Shoelace theme layer.  The vendor stylesheet remains loaded for now; these
   overrides replace its white surfaces, blue actions, pastel alerts, and
   keycap treatment with the game's brass, oxide, deep green, cream, and ink
   semantics.  The utilities below are the small subset the app uses. */

body {
  background: var(--felt);
  color: var(--ink);
}

table {
  background: transparent;
  color: inherit;
}

a,
a:hover {
  color: var(--brass-deep);
}

button,
.button {
  background: var(--brass);
  border: 1px solid var(--brass-deep);
  border-radius: var(--radius-md);
  color: var(--ink);
  height: auto;
  line-height: 1.2;
  padding: 0.65rem 1rem;
}

button:hover:not(:disabled),
.button:hover:not(:disabled) {
  background: var(--brass-bright);
  border-color: var(--brass-deep);
  color: var(--ink);
}

button:focus,
.button:focus {
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

.alert {
  background: transparent;
  border: 1px solid transparent;
  border-left: 2px solid var(--brass);
  border-radius: 0;
  color: var(--ink);
  margin: 0;
  padding: 0.35rem 0.75rem;
}
.alert.alert-secondary,
.alert.alert-light,
.alert.alert-dark {
  background: transparent;
  border-color: var(--paper-edge);
  border-left-color: var(--brass);
  color: var(--ink);
}

.alert.alert-info {
  background: transparent;
  border-color: transparent;
  border-left-color: var(--brass-deep);
  color: var(--ink-muted);
}

.alert.alert-success {
  background: transparent;
  border-color: transparent;
  border-left-color: var(--success);
  color: var(--success);
}

.alert.alert-warning,
.alert.alert-danger {
  background: transparent;
  border-color: transparent;
  border-left-color: var(--oxide);
  color: var(--oxide);
}

kbd {
  background: var(--brass);
  border: 0;
  border-radius: var(--radius-sm);
  box-shadow: none;
  color: var(--ink);
  font: 600 var(--text-xs) var(--font-ui);
  padding: 0.15rem 0.4rem;
}

.loader {
  animation: loader 0.75s linear infinite;
  border-color: var(--hairline-strong);
  border-left-color: var(--brass);
  border-top-color: var(--brass);
  border-width: 0.2rem;
  display: inline-block;
  height: 2.25rem;
  margin: 0 0.5em;
  vertical-align: middle;
  width: 2.25rem;
}

.loader.loader-xl {
  border-width: 0.4rem;
  height: 3.25rem;
  width: 3.25rem;
}

.button-loader,
.button-loader:hover {
  min-width: 2em;
  position: relative;
}

.button-loader {
  color: transparent !important;
  overflow: hidden;
}

.button-loader::after {
  border: 0.15em solid rgba(22, 28, 25, 0.20);
  border-left-color: var(--ink);
  border-top-color: var(--ink);
  border-radius: 50%;
  content: "";
  display: inline-block;
  height: 1em;
  left: calc(50% - 0.5em);
  position: absolute;
  top: calc(50% - 0.5em);
  width: 1em;
  animation: theme-button-loader 0.75s linear infinite;
}

/* Keep the loader keyframe names separate from the ported Shoelace utility. */
@keyframes theme-button-loader {
  to { transform: rotate(360deg); }
}

@keyframes loader {
  to { transform: rotate(360deg); }
}

#messages {
  width: min(500px, calc(100% - 2rem));
}

#messages .alert {
  animation: message 7s ease-out forwards;
}

section#score .score-card {
  background: color-mix(in srgb, var(--paper) calc(var(--sheet-opacity) * 100%), transparent);
  -webkit-backdrop-filter: blur(var(--sheet-blur));
  backdrop-filter: blur(var(--sheet-blur));
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  color: var(--ink);
}
