:root {
  --background: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #eef1f5;
  --text: #2a374e;
  --text-muted: #56637a;
  --primary: #e1251b;
  --primary-dark: #ad1711;
  --primary-soft: #fbe3e1;
  --accent: #2a374e;
  --border: #c5ccd8;
  --shadow: 0 14px 35px rgba(42, 55, 78, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 5% 5%, rgba(225, 37, 27, 0.06), transparent 28%),
    radial-gradient(circle at 96% 92%, rgba(42, 55, 78, 0.08), transparent 25%),
    var(--background);
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 20px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

button,
.letter-cell {
  user-select: none;
  -webkit-user-select: none;
}

.game-shell {
  width: 100%;
  max-width: 720px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(18px, var(--safe-top))
    max(18px, env(safe-area-inset-right, 0px))
    max(24px, var(--safe-bottom))
    max(18px, env(safe-area-inset-left, 0px));
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(225, 37, 27, 0.24);
  font-family: Georgia, serif;
  font-size: 30px;
  font-weight: 700;
  font-style: italic;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(27px, 7vw, 34px);
  line-height: 1;
  letter-spacing: -0.03em;
}

.icon-button {
  display: flex;
  min-width: 108px;
  min-height: 52px;
  padding: 0 15px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid var(--primary);
  border-radius: 14px;
  color: var(--primary);
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
}

.icon-button svg {
  width: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-off-icon {
  display: none;
}

.icon-button[aria-pressed="false"] .sound-on-icon {
  display: none;
}

.icon-button[aria-pressed="false"] .sound-off-icon {
  display: block;
}

.status-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px 18px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 2px solid rgba(225, 37, 27, 0.24);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 24px rgba(42, 55, 78, 0.07);
  backdrop-filter: blur(10px);
}

.level-info {
  display: flex;
  flex-direction: column;
}

.status-label {
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.level-info strong {
  max-width: 240px;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.difficulty-label {
  width: fit-content;
  margin-top: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 14px;
  font-weight: 800;
}

.progress-area {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 12px;
}

.progress-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe3ea;
}

.progress-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 300ms ease;
}

.progress-text {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 17px;
  font-weight: 700;
}

.timer {
  display: flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  font-size: 21px;
  font-weight: 750;
}

.timer svg {
  width: 22px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.game-instructions {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 2px solid #aeb7c6;
  border-radius: 16px;
  color: var(--text);
  background: #f1f4f8;
}

.instruction-icon {
  display: grid;
  width: 45px;
  height: 45px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.instruction-icon svg {
  width: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.game-instructions p {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.game-instructions strong {
  display: block;
  margin-bottom: 2px;
  font-size: 20px;
}

.level-rule {
  display: block;
  margin-top: 5px;
  color: var(--primary-dark);
  font-weight: 800;
}

.board-section {
  display: flex;
  justify-content: center;
}

.letter-board {
  display: grid;
  width: min(100%, 620px);
  height: auto;
  aspect-ratio: 1;
  padding: clamp(9px, 2.7vw, 15px);
  overflow: hidden;
  border: 3px solid var(--primary);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
  touch-action: none;
  -webkit-touch-callout: none;
}

.letter-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border-radius: 50%;
  color: var(--text);
  font-size: clamp(23px, 7vw, 34px);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition:
    color 120ms ease,
    background 120ms ease,
    transform 120ms ease;
}

.letter-cell::before {
  position: absolute;
  inset: 10%;
  z-index: 0;
  border-radius: inherit;
  background: transparent;
  content: "";
  transform: scale(0.65);
  transition:
    transform 140ms ease,
    background 140ms ease;
}

.letter-cell span {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.letter-cell.is-selecting {
  color: var(--text);
}

.letter-cell.is-selecting::before {
  background: #dde3ec;
  transform: scale(1);
}

.letter-cell.is-hint {
  color: #ffffff;
  animation: hint-pulse 900ms ease-in-out infinite alternate;
}

.letter-cell.is-hint::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(42, 55, 78, 0.24);
  transform: scale(1);
}

.letter-cell.is-found {
  color: #fff;
  animation: cell-pop 260ms ease both;
}

.letter-cell.is-found::before {
  background: var(--primary);
  transform: scale(1);
}

@keyframes cell-pop {
  50% {
    transform: scale(1.13);
  }
}

@keyframes hint-pulse {
  to {
    transform: scale(1.12);
  }
}

.words-section {
  margin-top: 26px;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 13px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.02em;
}

.word-count {
  color: var(--text-muted);
  font-size: 17px;
  font-weight: 800;
}

.word-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.word-item {
  display: flex;
  min-width: 0;
  align-items: center;
  min-height: 60px;
  gap: 11px;
  padding: 13px 15px;
  border: 2px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.84);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition:
    opacity 180ms ease,
    background 180ms ease,
    color 180ms ease;
}

.word-item::before {
  display: block;
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 1.5px solid #7d8798;
  border-radius: 50%;
  content: "";
}

.word-item.is-found {
  color: var(--primary);
  background: var(--primary-soft);
  opacity: 1;
  text-decoration: line-through;
}

.word-item.is-found::before {
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: inset 0 0 0 1.5px var(--primary-soft);
}

.word-item.is-hinted {
  border-color: var(--accent);
  color: var(--text);
  background: #e8edf4;
}

.word-item.is-hinted::before {
  border-color: var(--accent);
  background: var(--accent);
}

.hint-button,
.new-game-button,
.primary-button,
.text-button {
  border: 0;
  cursor: pointer;
}

.hint-button {
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 22px;
  padding: 14px;
  border: 2px solid var(--accent);
  border-radius: 16px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(42, 55, 78, 0.2);
  font-size: 20px;
  font-weight: 850;
}

.hint-button svg {
  width: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.new-game-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  margin-top: 12px;
  padding: 14px;
  border: 2px solid var(--primary);
  border-radius: 16px;
  color: #fff;
  background: var(--primary);
  font-size: 19px;
  font-weight: 800;
}

.new-game-button svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toast {
  position: fixed;
  z-index: 20;
  top: max(16px, var(--safe-top));
  left: 50%;
  display: flex;
  width: min(calc(100% - 28px), 520px);
  min-height: 54px;
  padding: 12px 18px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: #fff;
  background: var(--text);
  box-shadow: 0 8px 25px rgba(42, 55, 78, 0.25);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -16px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  padding:
    max(20px, var(--safe-top))
    20px
    max(20px, var(--safe-bottom));
  place-items: center;
  visibility: hidden;
  opacity: 0;
  transition:
    opacity 240ms ease,
    visibility 240ms;
}

.modal.is-visible {
  visibility: visible;
  opacity: 1;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(42, 55, 78, 0.68);
  backdrop-filter: blur(5px);
}

.modal-card {
  position: relative;
  width: min(100%, 370px);
  padding: 34px 28px 24px;
  border-radius: 28px;
  text-align: center;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(42, 55, 78, 0.34);
  transform: translateY(20px) scale(0.97);
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal.is-visible .modal-card {
  transform: translateY(0) scale(1);
}

.celebration-icon {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 20px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(42, 55, 78, 0.3);
  transform: rotate(-5deg);
}

.celebration-icon svg {
  width: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.modal-card h2 {
  margin-bottom: 9px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 29px;
}

.modal-copy {
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 19px;
}

.final-time {
  display: block;
  color: var(--primary);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.record-message {
  min-height: 18px;
  margin: 5px 0 20px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 800;
}

.primary-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 15px 18px;
  border-radius: 15px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(225, 37, 27, 0.24);
  font-weight: 800;
}

.primary-button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-button {
  min-height: 48px;
  margin-top: 10px;
  padding: 10px 14px;
  color: var(--text-muted);
  background: transparent;
  font-size: 18px;
  font-weight: 750;
}

button:focus-visible,
.letter-cell:focus-visible {
  outline: 3px solid rgba(42, 55, 78, 0.65);
  outline-offset: 3px;
}

button:active {
  transform: scale(0.98);
}

.configuration-error {
  display: flex;
  width: min(calc(100% - 36px), 520px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 32px 20px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.configuration-error-icon {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--primary);
  font-size: 38px;
  font-weight: 900;
}

.configuration-error h1 {
  margin-bottom: 15px;
  font-size: 30px;
  line-height: 1.15;
}

.configuration-error p {
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 18px;
}

.configuration-error-message {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--primary);
  border-radius: 14px;
  color: #8e1610 !important;
  background: var(--primary-soft);
  font-weight: 800;
}

@media (max-height: 690px) {
  .game-shell {
    padding-top: max(12px, var(--safe-top));
  }

  .top-bar {
    margin-bottom: 12px;
  }

  .words-section {
    margin-top: 20px;
  }
}

@media (max-width: 600px) {
  .top-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .brand,
  .brand > div {
    min-width: 0;
  }

  .icon-button {
    align-self: flex-end;
  }
}

@media (max-width: 440px) {
  .icon-button {
    min-width: 52px;
    padding-inline: 13px;
  }

  .sound-label {
    display: none;
  }

  .timer-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 340px) {
  .game-shell {
    padding-inline: 12px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    font-size: 25px;
  }

  .brand {
    gap: 8px;
  }

  h1 {
    font-size: 23px;
  }

  .brand .eyebrow {
    font-size: 9px;
  }

  .status-card {
    gap: 10px;
    padding-inline: 13px;
  }

  .level-info strong {
    max-width: 180px;
    font-size: 20px;
  }

  .letter-cell {
    font-size: clamp(22px, 7.2vw, 26px);
  }

  .game-instructions p {
    font-size: 17px;
  }
}

@media (max-width: 360px) {
  .word-list {
    grid-template-columns: 1fr;
  }

  .word-item {
    font-size: 20px;
  }
}

@media (max-width: 300px) {
  .brand-mark {
    display: none;
  }
}

@media (min-width: 900px) {
  .game-shell {
    display: grid;
    width: 100%;
    max-width: none;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-columns: minmax(340px, 0.78fr) minmax(480px, 1.22fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    column-gap: clamp(32px, 4vw, 72px);
    row-gap: 14px;
    padding:
      max(24px, var(--safe-top))
      max(28px, env(safe-area-inset-right, 0px))
      max(24px, var(--safe-bottom))
      max(28px, env(safe-area-inset-left, 0px));
  }

  .top-bar,
  .status-card,
  .game-instructions,
  .words-section,
  .hint-button,
  .new-game-button {
    grid-column: 1;
    margin-block: 0;
  }

  .top-bar {
    grid-row: 1;
  }

  .status-card {
    grid-row: 2;
  }

  .game-instructions {
    grid-row: 3;
  }

  .words-section {
    grid-row: 4;
    align-self: start;
  }

  .hint-button {
    grid-row: 5;
  }

  .new-game-button {
    grid-row: 6;
  }

  .board-section {
    grid-column: 2;
    grid-row: 1 / -1;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
  }

  .letter-board {
    width: min(100%, calc(100dvh - 48px));
    max-width: none;
    padding: clamp(12px, 1.2vw, 20px);
  }

  .letter-cell {
    font-size: clamp(30px, 2.6vw, 48px);
  }

  .level-info strong {
    max-width: none;
  }
}

@media (min-width: 1280px) {
  .letter-board {
    width: 100%;
    height: calc(100dvh - 48px);
    aspect-ratio: auto;
  }
}

@media (prefers-contrast: more) {
  :root {
    --text: #111a2b;
    --text-muted: #35425a;
    --primary: #b11912;
    --primary-dark: #85100b;
    --border: #606b7e;
  }

  .letter-board,
  .status-card,
  .word-item,
  .new-game-button {
    box-shadow: none;
  }
}

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