:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #68635d;
  --paper: #f7f2e8;
  --panel: #fffaf0;
  --stone: #eee4d2;
  --stone-back: #b8d8df;
  --line: #d4c7b4;
  --blue: #7fb0c8;
  --blue-deep: #2f667d;
  --bad: #ad3b31;
  --good: #2d7854;
  --surface: rgba(255, 250, 240, .72);
  --surface-strong: rgba(255, 252, 246, .9);
  --shadow: 0 12px 28px rgba(45, 36, 23, .12);
  --lift: 0 5px 0 rgba(55, 45, 30, .12), 0 12px 22px rgba(45, 36, 23, .1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, #f5ead7 0%, #eef3f0 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#penrose {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1500px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 0 0 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 0 9px;
  background: transparent;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 calc((100vw - 100%) / -2);
  z-index: -1;
  background: transparent;
  border-bottom: 0;
  box-shadow: none;
}

.topbar > div:first-child {
  flex: 0 1 auto;
  min-width: 0;
  width: 100%;
  text-align: center;
}

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

h1 {
  color: #28677d;
  font-size: clamp(1.4rem, 2.4vw, 2.25rem);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

h2 {
  font-size: 1rem;
}

.topbar-actions,
.card-title,
.number-row,
.toggle-row,
.player-picker {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.primary-button,
.icon-button,
.tab,
.player-chip {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .76);
  background: var(--panel);
  color: var(--ink);
  box-shadow:
    0 3px 0 rgba(48, 72, 88, .1),
    0 10px 18px rgba(38, 76, 102, .1),
    inset 0 1px 0 rgba(255, 255, 255, .78);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease, filter .16s ease;
}

.primary-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 999px;
  border-color: rgba(86, 151, 178, .26);
  font-weight: 900;
  background:
    radial-gradient(circle at 48% 0%, rgba(255, 255, 255, .7), transparent 45%),
    linear-gradient(180deg, rgba(245, 253, 255, .62), rgba(222, 242, 250, .42));
  color: #111820;
  text-decoration: none;
  backdrop-filter: blur(10px) saturate(1.08);
  -webkit-backdrop-filter: blur(10px) saturate(1.08);
}

.icon-button {
  min-width: 38px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 900;
  border-color: rgba(86, 151, 178, .3);
  background:
    radial-gradient(circle at 48% 0%, rgba(255, 255, 255, .7), transparent 45%),
    linear-gradient(180deg, rgba(240, 252, 255, .64), rgba(204, 232, 244, .48));
  color: #111820;
  backdrop-filter: blur(10px) saturate(1.08);
  -webkit-backdrop-filter: blur(10px) saturate(1.08);
}

#settingsButton {
  border-color: rgba(86, 151, 178, .24);
  background:
    radial-gradient(circle at 48% 0%, rgba(255, 255, 255, .72), transparent 45%),
    linear-gradient(180deg, rgba(255, 255, 255, .66), rgba(235, 248, 252, .42));
  color: #111820;
}

#newGameButton {
  border-color: rgba(86, 151, 178, .22);
  background:
    radial-gradient(circle at 48% 0%, rgba(255, 255, 255, .72), transparent 45%),
    linear-gradient(180deg, rgba(255, 255, 255, .68), rgba(240, 250, 253, .4));
  color: #111820;
}

.topbar-actions .primary-button[href*="live-games"] {
  border-color: rgba(86, 151, 178, .28);
  background:
    radial-gradient(circle at 48% 0%, rgba(255, 255, 255, .7), transparent 45%),
    linear-gradient(180deg, rgba(246, 253, 255, .63), rgba(214, 238, 248, .46));
  color: #111820;
}

.primary-button:hover,
.icon-button:hover,
.difficulty-pill:hover {
  transform: translateY(-1px);
  filter: saturate(1.05);
  box-shadow:
    0 3px 0 rgba(55, 45, 30, .13),
    0 13px 22px rgba(45, 36, 23, .13),
    inset 0 1px 0 rgba(255, 255, 255, .56);
}

.primary-button:active,
.icon-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(55, 45, 30, .16), 0 5px 10px rgba(45, 36, 23, .08);
}

.premium-button {
  position: relative;
  overflow: hidden;
  text-align: center;
  border-color: rgba(197, 138, 37, .62);
  background:
    radial-gradient(circle at 48% 0%, rgba(255, 255, 255, .36), transparent 42%),
    linear-gradient(135deg, #b97815, #f4bd3f 58%, #d99420);
  color: #fff;
  text-shadow: 0 1px 0 rgba(90, 52, 7, .24);
  isolation: isolate;
}

.premium-button::after {
  content: "";
  position: absolute;
  top: -45%;
  left: -75%;
  width: 42px;
  height: 190%;
  z-index: 1;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .86), rgba(255, 246, 178, .98), transparent);
  opacity: .02;
  pointer-events: none;
  transform: rotate(22deg);
  animation: premium-coin-glint 180s ease-in-out infinite;
}

@keyframes premium-coin-glint {
  0%,
  96% {
    left: -75%;
    opacity: .02;
  }
  96.8% {
    opacity: .95;
  }
  98.2%,
  100% {
    left: 125%;
    opacity: .02;
  }
}

.flip-it-page .room-panel,
.flip-it-page .room-panel-show {
  display: none;
}

.settings-panel,
.score-card,
.word-card {
  border: 1px solid rgba(115, 100, 78, .3);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.settings-panel {
  padding: 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
  scroll-margin-top: 96px;
}

.mode-tabs {
  display: grid;
  width: min(540px, 100%);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eadfcd;
  margin: 0 auto 12px;
}

.tab {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  box-shadow: none;
  background: transparent;
  font-weight: 800;
}

.tab.is-active,
.player-chip.is-active {
  background: var(--blue-deep);
  color: white;
}

.tab:disabled {
  cursor: default;
  opacity: .55;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
}

.setting {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 5px 8px;
  align-items: center;
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(126, 111, 88, .28);
  border-radius: 8px;
  background: rgba(255, 255, 255, .36);
}

.setting span:not(.setting-icon) {
  color: var(--muted);
  font-size: .84rem;
  font-weight: 800;
}

.setting input,
.setting select,
.setting strong,
.number-row {
  grid-column: 2;
}

.setting-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  grid-row: 1 / span 3;
  border-radius: 50%;
  background: #efe3cd;
  color: var(--blue-deep);
  font-weight: 900;
  overflow: hidden;
}

.setting-icon img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue-deep);
}

input[type="number"],
select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf7;
  color: var(--ink);
  padding: 0 9px;
}

.number-row {
  gap: 6px;
}

.toggle-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 10px;
  padding-top: 12px;
  color: var(--muted);
  font-weight: 800;
}

.flip-switch-row {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(47, 102, 125, .2);
  border-radius: 10px;
  background:
    radial-gradient(circle at 10% 0%, rgba(244, 199, 93, .18), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, .6), rgba(234, 246, 250, .46));
  color: #44575f;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.65);
}

.flip-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex: 0 0 50px;
}

.flip-switch input {
  width: 0;
  height: 0;
  opacity: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 30px;
  background: linear-gradient(135deg, #c9c3b8, #aeb9bd);
  cursor: pointer;
  box-shadow: inset 0 2px 5px rgba(34, 29, 22, .18);
  transition: background .3s ease, box-shadow .3s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 4px;
  bottom: 4px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #f7f2e8);
  box-shadow: 0 2px 6px rgba(34, 29, 22, .22);
  transition: transform .3s ease;
}

.flip-switch input:checked + .slider,
.option-toggle.is-active .slider {
  background: linear-gradient(135deg, #31b76a, #65cf72);
  box-shadow:
    inset 0 2px 5px rgba(24, 90, 54, .18),
    0 0 0 3px rgba(101, 207, 114, .16);
}

.flip-switch input:checked + .slider::before,
.option-toggle.is-active .slider::before {
  transform: translateX(22px);
}

.option-toggle {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.option-toggle.is-active {
  border-color: rgba(47, 102, 125, .32);
  background:
    radial-gradient(circle at 10% 0%, rgba(244, 199, 93, .24), transparent 34%),
    linear-gradient(135deg, rgba(239, 250, 241, .7), rgba(222, 244, 235, .52));
  color: var(--ink);
}

.premium-hint-difficulty-row {
  border-color: rgba(197, 138, 37, .34);
  background:
    radial-gradient(circle at 10% 0%, rgba(244, 199, 93, .24), transparent 34%),
    linear-gradient(135deg, rgba(255, 253, 247, .68), rgba(247, 237, 211, .46));
}

.premium-hint-difficulty-row[hidden] {
  display: none;
}

.hint-difficulty-select {
  width: min(132px, 48%);
  min-width: 108px;
  flex: 0 0 auto;
  color: var(--blue-deep);
  font-weight: 900;
}

.hint-difficulty-select:disabled {
  cursor: default;
  color: rgba(47, 102, 125, .62);
}

.game-layout {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.game-layout.has-score {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
}

.board-stage {
  grid-column: 1;
  grid-row: 1;
}

.score-card {
  grid-column: 2;
  grid-row: 1;
}

.score-card[hidden] {
  display: none;
}

.game-layout:has(.score-details:not([open])) {
  grid-template-columns: 1fr;
}

.game-layout:has(.score-details:not([open])) .board-stage {
  grid-column: 1;
}

.game-layout:has(.score-details:not([open])) .score-card {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 5;
  width: min(190px, 44vw);
}

.score-details:not([open]) .card-title {
  margin: 0;
}

.score-details:not([open]) summary.card-title {
  min-height: 42px;
}

.score-card,
.word-card {
  border-radius: 8px;
  padding: 10px;
}

.card-title {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

summary.card-title {
  margin-bottom: 0;
  cursor: pointer;
  list-style: none;
}

summary.card-title::-webkit-details-marker {
  display: none;
}

summary.card-title h2::after {
  content: none;
}

.score-collapse-icon {
  position: relative;
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border: 1.5px solid rgba(47, 102, 125, .28);
  border-radius: 50%;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 3px 0 rgba(55, 45, 30, .1);
}

.score-collapse-icon::before,
.score-collapse-icon::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 2px;
  border-radius: 999px;
  background: var(--blue-deep);
}

.score-collapse-icon::before {
  transform: rotate(45deg);
}

.score-collapse-icon::after {
  transform: rotate(-45deg);
}

.score-details:not([open]) .score-collapse-icon::before {
  transform: rotate(0deg);
}

.score-details:not([open]) .score-collapse-icon::after {
  transform: rotate(90deg);
}

.score-content {
  margin-top: 12px;
}

.card-title span {
  border-radius: 999px;
  padding: 4px 9px;
  background: #e6f0f3;
  color: var(--blue-deep);
  font-size: .78rem;
  font-weight: 900;
}

.player-picker {
  gap: 6px;
  margin-bottom: 12px;
}

.player-chip {
  flex: 1;
  min-height: 34px;
  border-radius: 7px;
  font-weight: 800;
  box-shadow: none;
}

.score-row,
.meter-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid rgba(126, 111, 88, .22);
}

.score-row:first-child {
  border-top: 0;
}

.score-row span,
.meter-block span {
  color: var(--muted);
  font-weight: 800;
}

.score-row strong,
.meter-block strong {
  font-size: 1.14rem;
  text-align: right;
}

.score-row.is-current {
  margin: 8px -7px 0;
  padding: 10px 7px;
  border-radius: 8px;
  border-top: 0;
  background: rgba(127, 176, 200, .16);
}

.score-row.is-winner {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid rgba(45, 120, 84, .22);
  border-radius: 8px;
  background: rgba(45, 120, 84, .12);
}

#timerReadout {
  min-width: 4.4ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#timerReadout.is-running {
  color: var(--blue-deep);
}

#timerReadout.is-expired {
  color: var(--bad);
}

.result-card {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(126, 111, 88, .22);
}

.result-card h3 {
  margin: 0 0 8px;
  font-size: .9rem;
}

.result-card {
  border-radius: 8px;
  background: rgba(127, 176, 200, .18);
  padding: 12px;
}

.result-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 800;
  line-height: 1.35;
}

.board-stage {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(360px, min(66vw, 760px)) minmax(240px, 320px);
  gap: 10px;
  align-items: start;
  justify-content: center;
  justify-items: stretch;
}

.board-stage .word-card {
  grid-column: 2;
  grid-row: 2;
  width: 100%;
  margin: clamp(72px, 7vw, 118px) 0 0;
}

.play-hud {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-content: stretch;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 8px;
}

.difficulty-pill,
.guess-countdown-pill,
.countdown-pill {
  min-height: 36px;
  min-width: 0;
  display: flex;
  align-items: center;
  border: 1px solid rgba(126, 111, 88, .28);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 4px 12px rgba(45, 36, 23, .06);
  overflow: hidden;
}

.difficulty-pill {
  cursor: pointer;
}

.difficulty-pill:hover {
  border-color: rgba(47, 102, 125, .34);
  background: rgba(255, 255, 255, .78);
}

.difficulty-pill,
.guess-countdown-pill,
.countdown-pill {
  justify-content: space-between;
  gap: 10px;
  padding: 7px 11px;
  color: var(--muted);
  font-weight: 900;
}

.difficulty-pill span,
.guess-countdown-pill span,
.countdown-pill span {
  min-width: 0;
  font-size: .78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guess-countdown-pill span {
  flex: 0 0 auto;
  overflow: visible;
  text-overflow: clip;
}

.difficulty-pill strong,
.guess-countdown-pill strong,
.countdown-pill strong {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  color: var(--ink);
  font-size: clamp(.96rem, 1.6vw, 1.24rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  overflow: hidden;
  text-align: right;
  white-space: nowrap;
}

.guess-countdown-pill strong {
  flex: 0 0 auto;
}

.countdown-pill strong {
  font-size: clamp(1rem, 1.8vw, 1.2rem);
}

.guess-countdown-pill.is-low strong {
  color: var(--bad);
}

.countdown-pill.is-running strong {
  color: var(--blue-deep);
}

.countdown-pill.is-expired strong {
  color: var(--bad);
}

.board {
  position: relative;
  --grid-size: 6;
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
  gap: clamp(3px, .48vw, 6px);
  width: min(100%, calc(100svh - 250px), 760px);
  margin: 0 auto;
  padding: clamp(7px, 1.25vw, 12px);
  border: 1px solid rgba(91, 78, 58, .26);
  border-radius: 8px;
  background: rgba(71, 62, 47, .09);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5), 0 18px 34px rgba(45, 36, 23, .14);
}

.board[hidden] {
  display: none;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid rgba(104, 88, 62, .32);
  border-radius: 7px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.68), rgba(196,181,151,.2)),
    var(--stone);
  color: #121212;
  font-size: clamp(.95rem, 2.9vw, 2.05rem);
  font-weight: 900;
  box-shadow: 0 5px 0 rgba(79, 63, 39, .18), 0 10px 16px rgba(56, 45, 31, .14);
  padding: 0;
  text-transform: uppercase;
  transform-origin: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tile-letter {
  display: inline-block;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  pointer-events: none;
}

.tile.is-flip-animating,
.tile.is-unflipping {
  animation: tile-safe-flip .38s cubic-bezier(.2, .78, .16, 1) both;
}

.tile.is-flipped {
  border-color: rgba(47, 102, 125, .5);
  background:
    linear-gradient(145deg, rgba(255,255,255,.72), rgba(47,102,125,.16) 48%, rgba(47,102,125,.26)),
    var(--stone-back);
  color: var(--blue-deep);
  box-shadow: 0 5px 0 rgba(47, 102, 125, .22), 0 10px 16px rgba(34, 63, 73, .13);
}

@keyframes tile-safe-flip {
  0% {
    transform: scaleX(1);
    filter: brightness(1);
  }
  46% {
    transform: scaleX(.08);
    filter: brightness(1.16);
  }
  100% {
    transform: scaleX(1);
    filter: brightness(1);
  }
}

.tile.is-decoy {
  border-color: rgba(173, 59, 49, .68);
  background:
    linear-gradient(145deg, rgba(255,255,255,.72), rgba(173,59,49,.15) 48%, rgba(173,59,49,.28)),
    #e5c4b9;
  color: #121212;
  box-shadow: 0 7px 0 rgba(173, 59, 49, .26), 0 11px 18px rgba(74, 30, 24, .16);
}

.tile.is-dropped {
  background:
    linear-gradient(145deg, rgba(255,255,255,.58), rgba(127,176,200,.32)),
    rgba(127, 176, 200, .66);
  box-shadow: 0 2px 0 rgba(47, 102, 125, .26), 0 6px 10px rgba(56, 45, 31, .1);
}

.tile.is-loss-reveal {
  background:
    linear-gradient(145deg, rgba(255,255,255,.64), rgba(197,138,37,.22)),
    rgba(244, 199, 93, .48);
  box-shadow: 0 2px 0 rgba(104, 88, 62, .2), 0 6px 10px rgba(56, 45, 31, .1);
}

.tile.is-wrong {
  animation: nudge .26s ease;
}

.tile:disabled {
  cursor: default;
}

@keyframes nudge {
  20% { transform: translateX(-5px); }
  45% { transform: translateX(5px); }
  70% { transform: translateX(-3px); }
}

.word-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
}

.word-list li {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 7px 12px;
  border: 1px solid rgba(126, 111, 88, .18);
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255,255,255,.9), transparent 44%),
    rgba(255, 255, 255, .62);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .72),
    0 5px 12px rgba(45, 36, 23, .06);
  transition: transform .75s ease, background .45s ease, opacity .45s ease, border-color .45s ease;
}

.word-list li.is-found {
  order: 2;
  border-color: rgba(80, 128, 118, .16);
  background:
    linear-gradient(180deg, rgba(235, 244, 241, .84), rgba(218, 232, 228, .72));
  opacity: .72;
}

.word-list li.is-missed {
  border-color: rgba(197, 138, 37, .22);
  background: rgba(244, 199, 93, .16);
}

.word-list li.word-list-note {
  flex-basis: 100%;
  justify-content: center;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 900;
  text-align: center;
}

.word-list li.is-found .word-text {
  position: relative;
  text-decoration: none;
}

.word-list li.is-found .word-text::after {
  content: "";
  position: absolute;
  left: 0;
  top: 52%;
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left center;
  animation: word-cross-out 1.25s ease forwards;
}

@keyframes word-cross-out {
  to { transform: scaleX(1); }
}

.word-text {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #111312;
  font-weight: 900;
  letter-spacing: .02em;
  line-height: 1;
  text-align: center;
}

dialog {
  width: min(560px, calc(100vw - 30px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(34, 29, 22, .34);
}

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

.rules-copy {
  color: var(--muted);
  line-height: 1.52;
  font-weight: 650;
}

.difficulty-breakdown {
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}

.difficulty-summary {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(47, 102, 125, .18);
  border-radius: 8px;
  background: rgba(127, 176, 200, .14);
  color: var(--ink);
  font-weight: 900;
}

.difficulty-breakdown h3 {
  margin: 0 0 8px;
  font-size: .95rem;
}

.difficulty-breakdown ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.game-result-dialog {
  width: min(420px, calc(100vw - 30px));
  border: 1px solid rgba(126, 111, 88, .26);
  border-radius: 14px;
  background:
    radial-gradient(circle at 20% 0%, rgba(244, 199, 93, .3), transparent 36%),
    linear-gradient(135deg, rgba(255, 253, 247, .97), rgba(255, 245, 238, .94));
  text-align: center;
}

#gameResultDialog {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 20;
  margin: 0;
  width: min(420px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  transform: translate(-50%, -50%);
  overflow: auto;
}

.board:has(#gameResultDialog[open]) .tile {
  filter: brightness(.72);
}

.game-result-dialog::backdrop {
  background: rgba(34, 29, 22, .46);
  backdrop-filter: blur(3px);
}

.game-result-content {
  display: grid;
  gap: 12px;
  padding: 10px;
}

.game-result-kicker {
  margin: 0;
  color: var(--gold);
  font-size: .78rem;
  font-weight: 1000;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.game-result-dialog h2 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: clamp(2rem, 8vw, 3.2rem);
}

.game-result-dialog p {
  margin: 0;
}

#gameResultMessage {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
}

.game-result-score {
  width: min(360px, 100%);
  margin: 2px auto 0;
  padding: 10px 14px;
  border: 1px solid rgba(86, 151, 178, .28);
  border-radius: 8px;
  background: rgba(255, 255, 255, .62);
  color: var(--ink);
  font-size: clamp(1.2rem, 5vw, 1.7rem);
  font-weight: 1000;
  line-height: 1.1;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72);
}

.game-result-score[hidden] {
  display: none;
}

.game-result-dialog.is-loss h2 {
  color: var(--bad);
}

.game-result-dialog .primary-button {
  width: min(180px, 100%);
  margin: 8px auto 0;
}

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.dialog-actions .primary-button,
.secondary-dialog-button {
  min-width: 150px;
  min-height: 38px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.secondary-dialog-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .55);
  color: var(--muted);
  font-weight: 900;
}

@media (max-width: 820px) {
  .settings-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .game-layout {
    position: static;
    grid-template-columns: 1fr;
  }

  .game-layout.has-score {
    grid-template-columns: 1fr;
  }

  .score-card,
  .word-card {
    grid-column: auto;
    grid-row: auto;
    order: initial;
  }

  .board-stage {
    grid-column: auto;
    grid-row: auto;
    order: 1;
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .score-card {
    position: static;
    width: auto;
    order: 2;
  }

  .board-stage .word-card {
    grid-column: 1;
    grid-row: auto;
    width: min(100%, 680px);
    margin-top: 16px;
  }

  .word-list {
    display: flex;
    flex-wrap: wrap;
  }

  .word-list li {
    flex: 1 1 106px;
  }

  .board {
    grid-column: auto;
    grid-row: auto;
    width: min(100%, 680px);
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 18px, 1500px);
  }

  .topbar {
    align-items: center;
    flex-direction: column;
    gap: 8px;
    padding: 9px 0 8px;
  }

  h1 {
    width: 100%;
    overflow: visible;
    font-size: 1.24rem;
    line-height: 1.05;
    white-space: nowrap;
  }

  .topbar-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .primary-button,
  .icon-button {
    min-height: 38px;
    padding: 0 6px;
    font-size: .78rem;
    text-align: center;
  }

  .premium-button {
    line-height: 1.02;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .toggle-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tab {
    padding: 0 4px;
    font-size: .82rem;
  }

  .mode-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab[data-mode="versus"] {
    grid-column: 1 / -1;
    justify-self: center;
    width: min(220px, 100%);
  }

  .play-hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
  }

  .difficulty-pill,
  .guess-countdown-pill,
  .countdown-pill {
    min-height: 44px;
    gap: 6px;
    padding: 7px 8px;
  }

  .difficulty-pill strong,
  .guess-countdown-pill strong,
  .countdown-pill strong {
    min-width: 0;
    font-size: 1rem;
  }

  .board {
    display: grid;
    grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
    grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
    padding: 6px;
    width: min(100%, calc(100vw - 18px), 680px);
    aspect-ratio: 1;
    min-height: 0;
    justify-self: center;
  }

  .board[hidden] {
    display: none;
  }

  .tile-face {
    border-radius: 5px;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 1000px) {
  body {
    min-height: 100svh;
    overflow-x: hidden;
  }

  .app-shell {
    width: min(100vw - 12px, 1000px);
    padding-bottom: 8px;
  }

  .topbar {
    gap: 5px;
    margin-bottom: 6px;
    padding: 5px 0 6px;
  }

  h1 {
    max-width: 100%;
    font-size: clamp(.92rem, 3.4svh, 1.12rem);
    line-height: 1;
    text-align: center;
    white-space: nowrap;
  }

  .topbar-actions {
    display: grid;
    width: min(100%, 520px);
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .primary-button,
  .icon-button {
    min-height: 30px;
    padding: 0 5px;
    border-radius: 11px;
    font-size: .68rem;
    line-height: 1;
  }

  #newGameButton {
    line-height: .95;
  }

  .settings-panel {
    max-height: calc(100svh - 82px);
    margin-bottom: 8px;
    overflow: auto;
    scroll-margin-top: 82px;
  }

  .settings-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

  .toggle-row {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .game-layout {
    gap: 6px;
  }

  .game-layout.has-score {
    grid-template-columns: 1fr;
  }

  .board-stage {
    width: 100%;
    grid-template-columns: minmax(0, calc(100svh - 154px)) minmax(132px, 30vw);
    grid-template-columns: minmax(0, calc(100dvh - 154px)) minmax(132px, 30vw);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px 8px;
    align-items: start;
  }

  .play-hud {
    grid-column: 1 / -1;
    grid-row: 1;
    gap: 5px;
    margin-bottom: 0;
  }

  .difficulty-pill,
  .guess-countdown-pill,
  .countdown-pill {
    min-height: 31px;
    gap: 5px;
    padding: 4px 7px;
    border-radius: 7px;
  }

  .difficulty-pill span,
  .guess-countdown-pill span,
  .countdown-pill span {
    font-size: .62rem;
  }

  .guess-countdown-pill span {
    font-size: .66rem;
  }

  .difficulty-pill strong,
  .guess-countdown-pill strong,
  .countdown-pill strong {
    min-width: 0;
    font-size: .86rem;
  }

  .board {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
    grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
    width: min(100%, calc(100svh - 158px), 54vw);
    width: min(100%, calc(100dvh - 158px), 54vw);
    aspect-ratio: 1;
    min-height: 0;
    padding: 4px;
    gap: 3px;
  }

  .board[hidden] {
    display: none;
  }

  .tile {
    border-radius: 5px;
    font-size: clamp(.78rem, 5.2svh, 1.3rem);
    box-shadow: 0 3px 0 rgba(79, 63, 39, .16), 0 8px 13px rgba(56, 45, 31, .12);
  }

  .board-stage .word-card {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    width: 100%;
    max-height: calc(100svh - 158px);
    margin: 0;
    padding: 6px;
    overflow: auto;
  }

  .word-list {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 5px;
  }

  .word-list li {
    flex: 0 0 auto;
    min-height: 25px;
    padding: 4px 6px;
    font-size: .68rem;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 1.12rem;
  }
}

@media (max-width: 360px) {
  h1 {
    font-size: .98rem;
  }
}

@media (max-width: 330px) {
  h1 {
    font-size: .9rem;
  }
}

/* Keep the About guide readable and immediately visible on every screen size. */
#rulesDialog {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
#rulesDialog .dialog-head {
  position: sticky;
  top: -1px;
  z-index: 1;
  padding: 8px 0;
  background: var(--panel);
}
#rulesDialog h3 {
  margin: 1.2em 0 .4em;
  color: var(--ink);
  font-size: 1rem;
}
#rulesDialog .rules-copy > h3:first-child { margin-top: .5em; }
#rulesButton { white-space: normal; line-height: 1.15; }

/* Phone controls stay in document flow so scrolling never covers the tiles. */
@media (max-width: 640px), (orientation: landscape) and (max-height: 520px) and (max-width: 1000px) {
  .flip-it-page .topbar {
    position: static;
    top: auto;
  }
}

/* Use one stable scroll surface on phones, including the title and controls.
   Browser toolbar expansion must not strand the document below the header. */
@media (max-width: 640px), (orientation: landscape) and (max-height: 520px) and (max-width: 1000px) {
  html:has(body.flip-it-page) {
    height: 100%;
    overflow: hidden;
  }
  body.flip-it-page {
    height: 100svh;
    min-height: 0;
    overflow: hidden;
  }
  .flip-it-page .app-shell {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y pinch-zoom;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .flip-it-page .settings-panel,
  .flip-it-page .board-stage .word-card {
    max-height: none;
    overflow: visible;
  }
}
