:root {
  color-scheme: light;
  --bg: #fbf9f4;
  --bg-wash: #f4f1ea;
  --panel: #fffdf7;
  --panel-soft: #f6f1e7;
  --tile: #efefea;
  --tile-hover: #e8e3d8;
  --tile-selected: #3f4f32;
  --tile-border: #d4cec0;
  --text: #201c16;
  --muted: #766f64;
  --line: #d8d1c4;
  --cream: #201c16;
  --button: #fbf9f4;
  --button-text: #2b251d;
  --button-border: #bcb3a3;
  --button-hover: #efe9dc;
  --primary: #201c16;
  --primary-text: #fbf9f4;
  --modal-bg: #fffdf7;
  --backdrop: rgba(32, 28, 22, 0.34);
  --yellow: #d7bc62;
  --yellow-line: #9c7b18;
  --green: #8aa268;
  --green-line: #58763b;
  --blue: #7da0bd;
  --blue-line: #3d6f94;
  --purple: #b08bbf;
  --purple-line: #765487;
  --danger: #b55463;
  --shadow: 0 24px 70px rgba(73, 58, 35, 0.14);
}

body.theme-cozy {
  color-scheme: dark;
  --bg: #121212;
  --bg-wash: #1e1e1e;
  --panel: #1b1b1b;
  --panel-soft: #222222;
  --tile: #2a2a2a;
  --tile-hover: #343434;
  --tile-selected: #506438;
  --tile-border: #454545;
  --text: #f3f4f6;
  --muted: #b8bbc2;
  --line: #303030;
  --cream: #f3f4f6;
  --button: #1f1f1f;
  --button-text: #f3f4f6;
  --button-border: #4a4a4a;
  --button-hover: #2a2a2a;
  --primary: #f3f4f6;
  --primary-text: #161616;
  --modal-bg: #1b1b1b;
  --backdrop: rgba(0, 0, 0, 0.68);
  --yellow: #a58128;
  --yellow-line: #efc85e;
  --green: #66783d;
  --green-line: #c8d879;
  --blue: #255d86;
  --blue-line: #66a9d9;
  --purple: #704f83;
  --purple-line: #c89dde;
  --danger: #d67182;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.36);
}

body.theme-slate {
  color-scheme: light;
  --bg: #f8fafc;
  --bg-wash: #edf2f7;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --tile: #e2e8f0;
  --tile-hover: #d6dee9;
  --tile-selected: #334155;
  --tile-border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d7dee8;
  --cream: #0f172a;
  --button: #ffffff;
  --button-text: #0f172a;
  --button-border: #cbd5e1;
  --button-hover: #f1f5f9;
  --primary: #0f172a;
  --primary-text: #f8fafc;
  --modal-bg: #ffffff;
  --backdrop: rgba(15, 23, 42, 0.36);
  --yellow: #d7b84f;
  --yellow-line: #a57a09;
  --green: #7aa66a;
  --green-line: #3f7b45;
  --blue: #70a2c8;
  --blue-line: #256f9e;
  --purple: #a78bca;
  --purple-line: #7154a5;
  --danger: #c8586a;
  --shadow: 0 24px 70px rgba(51, 65, 85, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-wash) 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--yellow-line);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  border-inline: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel), transparent 5%);
  box-shadow: var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 92px;
  padding: 18px 34px;
  border-bottom: 1px solid var(--line);
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 26px;
  min-width: 0;
}

h1,
h2,
.word-tile,
.category-name,
.secondary-button,
.primary-button,
.mode-button,
.link-button {
  font-family: Georgia, "Times New Roman", serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1.05;
}

.brand-block p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  white-space: nowrap;
}

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

.icon-button {
  display: inline-grid;
  place-items: center;
  width: auto;
  min-width: 42px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  color: var(--button-text);
  background: var(--button);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.icon-button--round {
  width: 42px;
  min-width: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  letter-spacing: 0;
}

.icon-button:hover,
.secondary-button:hover,
.mode-button:hover {
  border-color: var(--primary);
  background: var(--button-hover);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  min-height: calc(100vh - 92px);
}

.play-area {
  padding: 34px 50px 32px;
  border-right: 1px solid var(--line);
}

.mode-row,
.modal-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.mode-button {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 800;
}

.mode-button.active {
  color: var(--primary-text);
  border-color: var(--primary);
  background: var(--primary);
}

.prompt-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}

.prompt-row h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: inherit;
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.1rem;
  font-weight: 500;
}

.prompt-row p,
.footer-note,
.remaining-row {
  margin: 0;
  color: var(--muted);
}

.history-squares span,
.share-squares span {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.solved-list {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.85fr) 1.4fr;
  align-items: center;
  gap: 16px;
  min-height: 70px;
  padding: 14px 20px;
  border: 1px solid color-mix(in srgb, var(--row-line), white 12%);
  border-radius: 6px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--row), black 2%), color-mix(in srgb, var(--row), black 24%));
}

.category-name {
  font-weight: 800;
  font-size: 1rem;
}

.category-words {
  color: #fffaf0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.9rem;
}

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

.word-tile {
  min-height: 112px;
  border: 1px solid var(--tile-border);
  border-radius: 6px;
  color: var(--text);
  background: var(--tile);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.04);
  cursor: pointer;
  font-weight: 800;
  font-size: clamp(0.82rem, 1.35rem, 1.28rem);
  overflow-wrap: anywhere;
}

.word-tile:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  background: var(--tile-hover);
}

.word-tile.selected {
  color: #f7f0df;
  border-color: var(--green-line);
  background: var(--tile-selected);
}

.word-tile.shake {
  animation: shake 240ms ease-in-out;
}

.remaining-row {
  display: grid;
  place-items: center;
  min-height: 72px;
  font-size: 1rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr auto;
  align-items: center;
  gap: 18px;
  padding-top: 30px;
  border-top: 1px solid var(--line);
}

.secondary-button,
.primary-button,
.link-button {
  min-height: 58px;
  border-radius: 6px;
  padding: 0 22px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 800;
}

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

.primary-button {
  border: 1px solid var(--primary);
  color: var(--primary-text);
  background: var(--primary);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.link-button {
  display: none;
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--button-text);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.link-button.visible {
  display: inline;
}

.mistakes {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 88px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}

.mistake-dots {
  display: flex;
  gap: 6px;
}

.mistake-dots span {
  width: 16px;
  height: 16px;
  border: 1px solid var(--button-border);
  border-radius: 50%;
}

.mistake-dots span.used {
  border-color: var(--danger);
  background: var(--danger);
}

.footer-note {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  min-height: 76px;
  border-top: 1px solid var(--line);
  margin: 30px -50px -32px;
}

.side-panel {
  padding: 42px 36px;
  background: var(--panel-soft);
}

.side-panel section + section {
  margin-top: 42px;
  padding-top: 36px;
  border-top: 1px solid var(--line);
}

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

.section-heading span {
  color: var(--yellow-line);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
}

.side-panel h2 {
  margin: 0 0 26px;
  font-size: 1.1rem;
}

.stats-grid {
  display: grid;
  gap: 18px;
  margin: 0;
}

.stats-grid div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.stats-grid dt {
  color: var(--text);
}

.stats-grid dd {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 18px;
}

.history-item {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.history-date {
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-squares,
.share-squares {
  display: flex;
  gap: 7px;
}

.history-squares span {
  border: 1px solid var(--button-border);
}

.history-score {
  color: var(--text);
  font-weight: 800;
}

.product-section {
  display: grid;
  gap: 30px;
  padding: 58px 50px;
  border-top: 1px solid var(--line);
}

.intro-section {
  grid-template-columns: minmax(0, 0.9fr) minmax(260px, 0.8fr);
  align-items: center;
}

.product-section h2 {
  margin: 0 0 16px;
  font-size: clamp(1.2rem, 2.4vw, 1.8rem);
}

.product-section p {
  max-width: 68ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.intro-section img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.info-grid {
  grid-template-columns: repeat(3, 1fr);
}

.info-grid article {
  min-height: 186px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.faq-section {
  gap: 14px;
}

.faq-section details {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.faq-section summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
}

.faq-section p {
  margin-top: 10px;
}

.modal {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--modal-bg);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: var(--backdrop);
}

.modal form {
  margin: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.modal-header h2 {
  margin: 0;
}

.rules-list {
  display: grid;
  gap: 18px;
  padding: 20px 0 24px;
  margin: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  list-style: none;
}

.rules-list li {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: start;
  gap: 12px;
}

.rules-list span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--primary-text);
  background: var(--primary);
  font-size: 0.86rem;
  font-weight: 900;
}

.rules-list p {
  margin: 2px 0 0;
  color: var(--text);
  line-height: 1.45;
}

.example-box {
  margin-top: 20px;
  padding: 16px 14px 18px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.example-box p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.example-box div {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.example-box span {
  display: grid;
  place-items: center;
  min-height: 36px;
  border-radius: 5px;
  color: var(--primary-text);
  background: var(--primary);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

.modal-stats div {
  display: grid;
  gap: 6px;
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.modal-stats dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.modal-stats dd {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 900;
}

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

.dist-row {
  display: grid;
  grid-template-columns: 28px 1fr 34px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.dist-bar {
  height: 12px;
  border-radius: 99px;
  background: var(--panel-soft);
  overflow: hidden;
}

.dist-bar span {
  display: block;
  height: 100%;
  width: var(--bar);
  background: var(--yellow-line);
}

.theme-field {
  padding: 0;
  margin: 0;
  border: 0;
}

.theme-field legend {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.theme-option {
  position: relative;
  display: grid;
  min-height: 92px;
  cursor: pointer;
}

.theme-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.theme-option span {
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--button-border);
  border-radius: 7px;
  color: var(--button-text);
  background: var(--button);
}

.theme-option strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.86rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.theme-option small {
  color: var(--muted);
  font-size: 0.78rem;
}

.theme-option input:checked + span {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary);
}

.theme-option input:checked + span small {
  color: color-mix(in srgb, var(--primary-text), transparent 24%);
}

.full-button {
  width: 100%;
  margin-top: 22px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 120%);
  max-width: min(92vw, 440px);
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary-text);
  background: var(--primary);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 10;
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (max-width: 900px) {
  .app-shell {
    border-inline: 0;
  }

  .topbar {
    grid-template-columns: 40px 1fr auto;
    min-height: 78px;
    padding: 14px 16px;
    gap: 10px;
  }

  .brand-block {
    display: block;
  }

  .brand-block p {
    margin-top: 5px;
    font-size: 0.72rem;
  }

  .top-actions {
    gap: 7px;
  }

  .icon-button {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: 0.68rem;
  }

  .icon-button--round {
    width: 36px;
    min-width: 36px;
    padding: 0;
    font-size: 0.92rem;
  }

  .game-layout {
    display: block;
  }

  .play-area {
    padding: 26px 14px 24px;
    border-right: 0;
  }

  .word-grid {
    gap: 7px;
  }

  .word-tile {
    min-height: 76px;
    padding: 4px;
    font-size: 0.82rem;
  }

  .category-row {
    grid-template-columns: 1fr;
    gap: 7px;
    min-height: auto;
    padding: 13px 14px;
  }

  .category-words {
    justify-content: flex-start;
    gap: 9px;
    font-size: 0.76rem;
  }

  .controls {
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
    padding-top: 20px;
  }

  .secondary-button,
  .primary-button {
    min-height: 50px;
    padding: 0 8px;
    font-size: 0.82rem;
  }

  .mistakes {
    grid-column: 1 / -1;
    grid-template-columns: auto auto auto;
    justify-content: center;
    gap: 12px;
  }

  .footer-note {
    margin: 24px -14px -24px;
  }

  .side-panel {
    padding: 32px 18px;
    border-top: 1px solid var(--line);
  }

  .product-section {
    padding: 40px 18px;
  }

  .intro-section,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .modal-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .example-box div {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .prompt-row {
    display: block;
  }

  .word-tile {
    min-height: 68px;
    font-size: 0.68rem;
  }

  .mode-row {
    width: 100%;
  }

  .modal-stats {
    grid-template-columns: 1fr;
  }

  .theme-options {
    grid-template-columns: 1fr;
  }
}
