:root {
  color-scheme: light;
  --ink: #2b2421;
  --muted: #726964;
  --paper: #f6f0e5;
  --surface: #fffdf8;
  --line: #d9cdbd;
  --soft-line: #e9e0d4;
  --maroon: #7b2f34;
  --maroon-dark: #5d2025;
  --gold: #c79431;
  --gold-soft: #f3e6c5;
  --correct: #2f7656;
  --present: #c48618;
  --absent: #77736e;
  --shadow: 0 24px 60px rgb(72 48 35 / 12%);
  font-family: "Noto Sans Tamil", "Nirmala UI", Latha, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgb(199 148 49 / 13%) 0 90px, transparent 91px),
    linear-gradient(180deg, #fbf7ef 0%, var(--paper) 48%, #eee4d5 100%);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(123 47 52 / 30%);
  outline-offset: 3px;
}

.page-shell {
  width: min(100%, 1080px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: white;
  font-size: 1.35rem;
  font-weight: 800;
  background: var(--maroon);
  border-radius: 10px 10px 10px 3px;
  box-shadow: 4px 4px 0 var(--gold);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1rem;
  line-height: 1.15;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.69rem;
  letter-spacing: 0.04em;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  color: var(--maroon);
  font-weight: 800;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.header-actions {
  display: flex;
  gap: 8px;
}

main {
  width: 100%;
}

.hero {
  padding: 34px 2px 24px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--maroon);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: Georgia, "Noto Serif Tamil", serif;
  font-size: clamp(2rem, 10vw, 3.45rem);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.04em;
}

.hero > p:last-child {
  max-width: 620px;
  margin: 15px auto 0;
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.7;
}

.game-card {
  overflow: hidden;
  background: rgb(255 253 248 / 94%);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.game-toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  border-bottom: 1px solid var(--soft-line);
}

.mode-switch {
  display: flex;
  justify-self: start;
  padding: 3px;
  background: #eee4d5;
  border-radius: 999px;
}

.mode-switch button {
  padding: 5px 8px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.mode-switch button.active {
  color: white;
  background: var(--maroon);
}

.text-button {
  justify-self: end;
  padding: 7px 0 7px 8px;
  color: var(--maroon);
  font-size: 0.7rem;
  font-weight: 800;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.game-message {
  min-height: 43px;
  margin: 0;
  padding: 13px 16px 9px;
  color: var(--maroon-dark);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.result-actions {
  display: flex;
  max-width: 360px;
  gap: 9px;
  margin: 2px auto 14px;
  padding: 0 14px;
}

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

.result-actions button {
  flex: 1;
}

.game-stage {
  padding: 8px 14px 18px;
}

.board-panel,
.letters-panel {
  min-width: 0;
}

.letters-panel {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--soft-line);
}

.section-heading {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.section-number {
  color: var(--gold);
  font-family: Georgia, serif;
  font-size: 0.72rem;
  font-weight: 700;
}

.guess-board {
  display: grid;
  gap: 5px;
  width: min(100%, 244px);
  margin: 0 auto;
}

.guess-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.guess-cell {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  color: var(--ink);
  font-size: clamp(1rem, 5vw, 1.3rem);
  font-weight: 800;
  background: #fffefa;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  transition: transform 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.guess-row.current .guess-cell.filled {
  background: #fffaf0;
  border-color: var(--gold);
  transform: translateY(-1px);
  animation: tile-pop 180ms ease-out;
}

.guess-cell.correct,
.guess-cell.present,
.guess-cell.absent {
  color: white;
  border-color: transparent;
}

.guess-cell.correct {
  background: var(--correct);
}

.guess-cell.present {
  background: var(--present);
}

.guess-cell.absent {
  background: var(--absent);
}

.guess-cell.correct::after,
.guess-cell.present::after,
.guess-cell.absent::after {
  position: absolute;
  right: 4px;
  bottom: 1px;
  font-size: 0.5rem;
  opacity: 0.75;
}

.guess-cell.correct::after {
  content: "●";
}

.guess-cell.present::after {
  content: "◆";
}

.guess-cell.absent::after {
  content: "—";
}

.guess-row.invalid {
  animation: row-shake 320ms ease-in-out;
}

.letter-bank {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.letter-key {
  min-width: 0;
  min-height: 46px;
  padding: 5px 2px;
  color: var(--ink);
  font-size: clamp(0.92rem, 4.3vw, 1.12rem);
  font-weight: 800;
  background: #f3ecdf;
  border: 1px solid #d8cbb9;
  border-radius: 9px;
  box-shadow: 0 2px 0 #cabba6;
  cursor: pointer;
  transition: transform 120ms ease, background-color 160ms ease, color 160ms ease;
}

.letter-key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.letter-key:disabled {
  cursor: default;
  opacity: 0.64;
}

.letter-key.correct,
.letter-key.present,
.letter-key.absent {
  color: white;
  border-color: transparent;
  box-shadow: none;
}

.letter-key.correct {
  background: var(--correct);
}

.letter-key.present {
  background: var(--present);
}

.letter-key.absent {
  background: var(--absent);
}

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 9px;
  margin-top: 12px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 14px;
  font-size: 0.78rem;
  font-weight: 800;
  border-radius: 11px;
  cursor: pointer;
}

.primary-button {
  color: white;
  background: var(--maroon);
  border: 1px solid var(--maroon);
  box-shadow: 0 4px 0 var(--maroon-dark);
}

.primary-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--maroon-dark);
}

.secondary-button {
  color: var(--maroon);
  background: transparent;
  border: 1px solid var(--line);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: default;
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

.prototype-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.5;
  text-align: center;
}

.help-dialog {
  width: min(calc(100% - 28px), 480px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgb(43 36 33 / 58%);
  backdrop-filter: blur(4px);
}

.help-dialog form {
  padding: 22px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-heading h2 {
  margin: 0;
  font-family: Georgia, "Noto Serif Tamil", serif;
  font-size: 1.55rem;
}

.rules-list {
  display: grid;
  gap: 10px;
  margin: 24px 0;
  padding-left: 24px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

.legend {
  display: grid;
  gap: 9px;
  padding: 15px;
  background: #f7f0e5;
  border-radius: 14px;
}

.legend p {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.legend-tile {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  color: white;
  font-weight: 800;
  border-radius: 8px;
}

.legend-tile.correct {
  background: var(--correct);
}

.legend-tile.present {
  background: var(--present);
}

.legend-tile.absent {
  background: var(--absent);
}

.dialog-action {
  width: 100%;
  margin-top: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin: 24px 0;
}

.stats-grid div {
  min-width: 0;
  padding: 12px 4px;
  text-align: center;
  background: #f7f0e5;
  border-radius: 11px;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid strong {
  color: var(--maroon);
  font-family: Georgia, serif;
  font-size: 1.35rem;
}

.stats-grid span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.58rem;
  line-height: 1.35;
}

.distribution-title {
  margin: 0 0 12px;
  font-size: 0.77rem;
}

.distribution {
  display: grid;
  gap: 6px;
}

.distribution-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.distribution-bar {
  min-width: 28px;
  padding: 5px 7px;
  color: white;
  text-align: right;
  background: var(--maroon);
  border-radius: 5px;
}

.toast {
  position: fixed;
  z-index: 10;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 11px 15px;
  color: white;
  font-size: 0.75rem;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  background: var(--ink);
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, 18px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

@keyframes tile-pop {
  50% {
    transform: scale(1.08);
  }
}

@keyframes row-shake {
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}

@media (max-width: 759px) {
  .page-shell {
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .site-header {
    min-height: 54px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark,
  .icon-button {
    width: 34px;
    height: 34px;
  }

  .brand-mark {
    font-size: 1.05rem;
    border-radius: 8px 8px 8px 3px;
    box-shadow: 3px 3px 0 var(--gold);
  }

  .brand small,
  .hero .eyebrow,
  .hero > p:last-child,
  .prototype-note {
    display: none;
  }

  .hero {
    padding: 10px 2px 9px;
  }

  .hero h1 {
    font-size: 1.22rem;
    line-height: 1.3;
    letter-spacing: -0.02em;
  }

  .hero h1 br {
    display: none;
  }

  .game-card {
    border-radius: 16px;
  }

  .game-toolbar {
    padding: 7px 9px;
  }

  .game-message {
    min-height: 34px;
    padding: 8px 10px 6px;
    font-size: 0.72rem;
  }

  .game-stage {
    padding: 4px 9px 10px;
  }

  .section-heading {
    margin-bottom: 6px;
  }

  .section-number {
    display: none;
  }

  .guess-board {
    width: min(100%, 180px);
    gap: 3px;
  }

  .guess-row {
    gap: 3px;
  }

  .guess-cell {
    height: 38px;
    aspect-ratio: auto;
    font-size: 0.98rem;
    border-radius: 6px;
  }

  .letters-panel {
    margin-top: 10px;
    padding-top: 9px;
  }

  .letter-bank {
    gap: 4px;
  }

  .letter-key {
    min-height: 36px;
    padding: 2px;
    font-size: 0.9rem;
    border-radius: 7px;
  }

  .action-row {
    gap: 7px;
    margin-top: 8px;
  }

  .primary-button,
  .secondary-button {
    min-height: 40px;
    padding: 7px 10px;
  }
}

@media (max-width: 759px) and (max-height: 810px) {
  .site-header {
    min-height: 48px;
  }

  .hero {
    padding: 5px 2px;
  }

  .game-message {
    min-height: 30px;
    padding: 6px 8px 4px;
  }

  .game-stage {
    padding-top: 2px;
  }

  .letters-panel {
    margin-top: 6px;
    padding-top: 6px;
  }
}

@media (min-width: 760px) {
  .page-shell {
    padding-right: 28px;
    padding-left: 28px;
  }

  .site-header {
    min-height: 82px;
  }

  .hero {
    padding-top: 48px;
    padding-bottom: 34px;
  }

  .game-toolbar {
    padding-right: 22px;
    padding-left: 22px;
    font-size: 0.76rem;
  }

  .game-stage {
    display: grid;
    grid-template-columns: minmax(280px, 0.82fr) minmax(380px, 1.18fr);
    gap: 28px;
    padding: 18px 28px 28px;
  }

  .letters-panel {
    margin-top: 0;
    padding-top: 0;
    padding-left: 28px;
    border-top: 0;
    border-left: 1px solid var(--soft-line);
  }

  .guess-board {
    width: min(100%, 304px);
    gap: 7px;
  }

  .guess-row {
    gap: 7px;
  }

  .guess-cell {
    border-radius: 11px;
  }

  .letter-bank {
    gap: 8px;
  }

  .letter-key {
    min-height: 52px;
    font-size: 1.12rem;
  }
}

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