:root {
  --page: #f5f0e7;
  --ink: #15212a;
  --muted: #68737d;
  --panel: #fffdf7;
  --line: #d8d1c4;
  --teal: #187d75;
  --teal-dark: #105d58;
  --coral: #d95f45;
  --blue: #315f9d;
  --yellow: #f0b93f;
  --green: #2f8a5f;
  --shadow: 0 18px 45px rgba(21, 33, 42, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(24, 125, 117, .13), transparent 34%),
    linear-gradient(315deg, rgba(217, 95, 69, .12), transparent 38%),
    var(--page);
}

button,
input,
textarea {
  font: inherit;
}

input,
textarea {
  font-size: 16px;
}

button,
input,
textarea,
summary {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  color: #fff;
  background: #4e5b66;
  font-weight: 800;
  line-height: 1.25;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(21, 33, 42, .14);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: default;
  opacity: .45;
  transform: none;
  box-shadow: none;
}

.primary {
  background: var(--teal);
}

.primary:hover {
  background: var(--teal-dark);
}

.quiet {
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: #ece5d7;
}

.quiet:hover {
  background: #dfd5c5;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin-bottom: 20px;
}

.brand-mark {
  width: 86px;
  height: 86px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 900;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 42px;
  line-height: 1.05;
}

h2 {
  font-size: 22px;
}

.status-strip {
  min-width: 156px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, .72);
  text-align: right;
}

.status-strip span,
.status-strip strong {
  display: block;
}

.status-strip span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-strip strong {
  margin-top: 2px;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

.topbar > *,
.game-grid > *,
.word-stage > *,
.player-card > * {
  min-width: 0;
}

.word-stage,
.scoreboard,
.word-bank-panel {
  border: 1px solid rgba(216, 209, 196, .9);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.word-stage {
  min-height: 470px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  align-items: center;
  justify-items: center;
  padding: 34px;
}

.category {
  grid-row: 1;
  justify-self: start;
  max-width: 100%;
  min-height: 32px;
  border-radius: 8px;
  padding: 6px 10px;
  color: #f9fffb;
  background: var(--blue);
  font-size: 14px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.word {
  grid-row: 2;
  width: 100%;
  color: var(--ink);
  font-size: 82px;
  font-weight: 950;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.word.long-word {
  font-size: 66px;
}

.word.extra-long-word {
  font-size: 54px;
}

.meaning {
  grid-row: 3;
  max-width: 100%;
  min-height: 58px;
  margin-top: 8px;
  padding: 8px 18px;
  border-radius: 8px;
  color: #171d22;
  background: rgba(240, 185, 63, .28);
  font-size: 36px;
  font-weight: 900;
  text-align: center;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.word-actions {
  grid-row: 4;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 24px;
}

.scoreboard {
  padding: 16px;
}

.scoreboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.player-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name score"
    "actions actions";
  align-items: center;
  gap: 12px;
  min-height: 128px;
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  color: #fff;
}

.player-one {
  background: var(--teal);
}

.player-two {
  background: var(--coral);
}

.player-three {
  background: var(--blue);
}

.player-card input {
  grid-area: name;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  color: #fff;
  background: rgba(255, 255, 255, .18);
  font-size: 18px;
  font-weight: 900;
  outline: 2px solid transparent;
}

.player-card input:focus {
  outline-color: rgba(255, 255, 255, .75);
}

.player-card input::selection {
  background: rgba(255, 255, 255, .3);
}

.player-card strong {
  grid-area: score;
  min-width: 70px;
  max-width: 4ch;
  font-size: 54px;
  line-height: .9;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.score-actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.icon-button {
  min-height: 44px;
  padding: 0;
  color: #15212a;
  background: rgba(255, 255, 255, .86);
  font-size: 26px;
  line-height: 1;
}

.word-bank-panel {
  margin-top: 18px;
  padding: 0;
  overflow: hidden;
}

.word-bank-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  padding: 16px 18px;
  cursor: pointer;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.word-bank-panel summary:focus-visible {
  outline-offset: -4px;
}

.word-bank-panel summary::marker {
  color: var(--teal);
}

.word-bank-panel summary strong {
  color: var(--muted);
  font-size: 14px;
}

textarea {
  display: block;
  width: calc(100% - 36px);
  min-height: 230px;
  margin: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fffaf1;
  resize: vertical;
  line-height: 1.45;
}

.bank-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 18px;
}

.bank-actions span {
  min-width: 0;
  min-height: 24px;
  color: var(--muted);
  font-weight: 700;
  overflow-wrap: anywhere;
}

@media (max-width: 860px), (orientation: landscape) and (max-height: 500px) {
  .app-shell {
    width: min(calc(100% - 20px), 680px);
    padding: 12px 0;
  }

  .topbar {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    gap: 10px;
    margin-bottom: 12px;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 12px;
  }

  h1 {
    font-size: clamp(22px, 4vw, 32px);
  }

  .status-strip {
    min-width: 0;
    padding: 6px 8px;
  }

  .status-strip span {
    font-size: 11px;
  }

  .status-strip strong {
    font-size: 20px;
  }

  .game-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .word-stage {
    min-height: 240px;
    grid-template-rows: auto minmax(64px, 1fr) auto auto;
    row-gap: 10px;
    padding: 16px;
  }

  .category {
    font-size: 12px;
  }

  .word {
    font-size: clamp(36px, 9vw, 56px);
  }

  .word.long-word {
    font-size: clamp(30px, 7.5vw, 46px);
  }

  .word.extra-long-word {
    font-size: clamp(26px, 6.5vw, 38px);
  }

  .meaning {
    min-height: 0;
    margin-top: 0;
    padding: 6px 10px;
    font-size: clamp(22px, 5.5vw, 28px);
  }

  .word-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 0;
  }

  .word-actions button {
    padding: 8px 4px;
    font-size: 14px;
  }

  .scoreboard {
    padding: 10px;
  }

  .scoreboard-head {
    margin-bottom: 8px;
  }

  .player-card {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "name score actions";
    gap: 8px;
    min-height: 60px;
    margin-top: 8px;
    padding: 8px;
  }

  .player-card input {
    padding: 8px;
    font-size: 16px;
  }

  .player-card strong {
    min-width: 2ch;
    font-size: 30px;
    line-height: 1;
  }

  .score-actions {
    grid-template-columns: repeat(2, 44px);
    gap: 8px;
  }

  .word-bank-panel {
    margin-top: 12px;
  }

  .word-bank-panel summary {
    padding: 12px;
  }

  textarea {
    width: calc(100% - 24px);
    margin: 0 12px;
  }

  .bank-actions {
    padding: 12px;
  }

  .bank-actions span {
    flex-basis: 100%;
  }
}

@media (max-width: 360px) {
  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .word-stage {
    min-height: 220px;
    padding: 12px;
  }

  .player-card {
    gap: 6px;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (min-width: 560px) {
  .app-shell {
    width: calc(100% - 20px);
    padding: 8px 0;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 10px;
    margin-bottom: 8px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 24px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 12px;
  }

  .status-strip {
    min-width: 0;
    padding: 4px 10px;
  }

  .status-strip strong {
    font-size: 20px;
  }

  .game-grid {
    grid-template-columns: minmax(0, 1fr) minmax(260px, .9fr);
    align-items: start;
    gap: 10px;
  }

  .word-stage {
    min-height: 250px;
    row-gap: 8px;
    padding: 12px;
  }

  .word {
    font-size: clamp(36px, 5.5vw, 48px);
  }

  .word.long-word {
    font-size: clamp(32px, 4.7vw, 42px);
  }

  .word.extra-long-word {
    font-size: clamp(26px, 4vw, 34px);
  }

  .meaning {
    font-size: 24px;
  }

  .scoreboard {
    padding: 8px;
  }

  .scoreboard-head {
    margin-bottom: 4px;
  }

  .player-card {
    min-height: 56px;
    margin-top: 6px;
    padding: 6px;
  }

  .word-bank-panel {
    margin-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }

  button:hover,
  button:active {
    transform: none;
  }
}
