:root {
  --color-bg-parchment: #FAF6F0;
  --color-bg-deep: #E7D4B5;
  --color-text-main: #2C2623;
  --color-text-muted: #7A6F68;
  --color-gold-accent: #D4AF37;
  --color-gold-hover: #E5C158;
  --color-card-bg: #FFFFFF;
  --color-overlay-dim: rgba(44, 38, 35, 0.45);
  --color-cell-idle: #FFFFFF;
  --color-cell-selected: #FFE89E;
  --color-cell-hinted-border: #D4AF37;
  --color-success: #567A54;
  --color-warning: #9A6422;
  --color-error: #964B45;
  --shadow-button-25d: 0 4px 0 #9E7D1E, 0 6px 12px rgba(44, 38, 35, 0.15);
  --shadow-card-soft: 0 4px 16px rgba(44, 38, 35, 0.08);
  --radius-cell: 12px;
  --radius-card: 20px;
  --page-padding: clamp(16px, 4vw, 24px);
}

* {
  box-sizing: border-box;
}

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

body {
  background: #E7D4B5;
  color: var(--color-text-main);
  font-family: Georgia, "Times New Roman", serif;
}

button {
  font: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #2C2623;
  outline-offset: 3px;
}

.app-shell {
  position: relative;
  display: grid;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  background:
    linear-gradient(rgba(250, 246, 240, 0.92), rgba(250, 246, 240, 0.92)),
    repeating-linear-gradient(20deg, rgba(145, 111, 78, 0.05) 0 1px, transparent 1px 7px);
}

.game-page {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  gap: 18px;
  padding: var(--page-padding);
}

.game-page--menu {
  gap: 16px;
}

.menu-content {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 32px;
}

.top-bar {
  display: grid;
  min-height: 48px;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.top-bar__center {
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
}

.top-bar__action,
.icon-button,
.button,
.mode-card,
.store-option,
.conflict-option,
.hint-button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
}

.top-bar__action,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--color-text-main);
  background: transparent;
  border-radius: 12px;
  font-family: Arial, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
}

.top-bar__action {
  justify-self: start;
  padding: 3px 6px;
}

.icon-button {
  min-width: 44px;
  width: 44px;
  height: 44px;
  justify-self: end;
  padding: 4px;
}

.top-bar__action:hover,
.icon-button:hover {
  background: rgba(212, 175, 55, 0.16);
}

.top-bar__action .button__label {
  min-width: 26px;
  padding: 3px 7px;
  color: #60462E;
  background: #F5E7BA;
  border: 1px solid rgba(158, 125, 30, 0.35);
  border-radius: 999px;
  font-size: 0.85rem;
  line-height: 1.1;
  text-align: center;
}

.top-bar__action .game-icon {
  width: 38px;
  height: 38px;
  flex-basis: 38px;
}

.game-icon {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.game-icon svg,
.game-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.menu-hero {
  padding: 0 8px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: #8C6540;
  font-family: Arial, sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.game-title {
  margin: 0;
  color: #5F3A24;
  font-size: clamp(2rem, 9vw, 3rem);
  line-height: 0.98;
  text-shadow: 0 2px 0 #FFFDF8, 0 4px 8px rgba(79, 49, 30, 0.18);
}

.mode-list {
  display: grid;
  gap: 16px;
  margin-top: 0;
}

.mode-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 112px;
  padding: 18px 20px;
  color: var(--color-text-main);
  text-align: left;
  background: linear-gradient(145deg, #FFFDF8 0%, #F5E4BB 100%);
  border: 1px solid rgba(158, 125, 30, 0.32);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 0 rgba(158, 125, 30, 0.3), 0 9px 20px rgba(92, 62, 27, 0.12);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.mode-card:hover {
  background: linear-gradient(145deg, #FFFFFF 0%, #F8E9C8 100%);
  box-shadow: 0 6px 0 rgba(158, 125, 30, 0.34), 0 12px 22px rgba(92, 62, 27, 0.16);
  transform: translateY(-2px);
}

.mode-card:active {
  box-shadow: var(--shadow-card-soft);
  transform: translateY(2px);
}

.mode-card:disabled,
.mode-card:disabled:hover {
  cursor: not-allowed;
  opacity: 0.58;
  box-shadow: var(--shadow-card-soft);
  transform: none;
}

.mode-card .game-icon {
  width: 72px;
  height: 72px;
  flex-basis: 72px;
}

.mode-card__content {
  display: grid;
  gap: 5px;
  min-width: 0;
  align-content: center;
}

.mode-card__title {
  font-size: 1.32rem;
  font-weight: 700;
}

.mode-card__subtitle {
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  font-size: 0.95rem;
  line-height: 1.3;
}

.mode-card__progress {
  min-width: 76px;
  padding: 8px 10px;
  color: #6B4817;
  background: #F8D76A;
  border: 1px solid rgba(158, 112, 16, 0.35);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 0 rgba(158, 125, 30, 0.16);
  font-family: Arial, sans-serif;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}

.game-page--play {
  justify-content: flex-start;
  gap: 12px;
}

.game-heading {
  padding-top: 4px;
  text-align: center;
}

.game-heading__title {
  margin: 0;
  color: #5F3A24;
  font-size: clamp(1.55rem, 7vw, 2.15rem);
}

.game-heading__reference {
  margin: 2px 0 0;
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  font-size: 0.84rem;
}

.game-board-stage {
  display: grid;
  width: 100%;
  min-height: 0;
  flex: 1;
  place-items: center;
}

.word-board {
  display: grid;
  width: min(100%, 420px);
  aspect-ratio: 1;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  gap: clamp(5px, 1.8vw, 9px);
  align-self: center;
  margin: 0;
  padding: clamp(8px, 2vw, 12px);
  background: rgba(181, 122, 73, 0.1);
  border: 1px solid rgba(140, 101, 64, 0.25);
  border-radius: 22px;
  touch-action: none;
  user-select: none;
}

.cell {
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  color: var(--color-text-main);
  background: var(--color-cell-idle);
  border: 1px solid rgba(140, 101, 64, 0.25);
  border-radius: var(--radius-cell);
  box-shadow: 0 2px 0 rgba(140, 101, 64, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  cursor: pointer;
  font-size: clamp(1rem, 6vw, 1.65rem);
  font-weight: 700;
  place-items: center;
  transition: transform 60ms ease, background 120ms ease, border-color 120ms ease;
}

.cell--selected {
  background: var(--color-cell-selected);
  border-color: #D4AF37;
  box-shadow: 0 1px 0 #C69A1D, inset 0 1px 0 rgba(255, 255, 255, 0.65);
  transform: scale(0.94);
}

.cell--hinted {
  border: 2px solid var(--color-cell-hinted-border);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.17), 0 2px 0 rgba(140, 101, 64, 0.2);
}

.cell--found {
  background: var(--word-color);
  border-color: rgba(44, 38, 35, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  cursor: default;
}

.cell--found-pop {
  animation: found-pop 450ms ease both;
}

.cell--shake {
  animation: cell-shake 200ms ease;
}

.cell--guide-pulse {
  animation: guide-pulse 400ms ease 2;
}

.cell--correct-path {
  position: relative;
  z-index: 1;
  background: #FFF0A8;
  border-color: #B88A18;
  box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.24), 0 3px 0 rgba(158, 125, 30, 0.35);
  animation: correct-path-pulse 620ms ease both;
}

.game-actions {
  display: grid;
  justify-items: center;
  gap: 9px;
  margin-top: auto;
  padding-top: 6px;
}

.game-page--play .game-actions {
  margin-top: 0;
}

.hint-button {
  display: inline-flex;
  min-width: 176px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  color: #4A351F;
  background: #F3DFA2;
  border-radius: 999px;
  box-shadow: var(--shadow-button-25d);
  font-family: Arial, sans-serif;
  font-weight: 800;
}

.hint-button:hover {
  background: #F8E9B8;
}

.hint-button:active {
  box-shadow: 0 1px 0 #9E7D1E, 0 3px 7px rgba(44, 38, 35, 0.14);
  transform: translateY(3px);
}

.hint-button .game-icon {
  width: 29px;
  height: 29px;
  flex-basis: 29px;
}

.hint-button__balance {
  display: inline-grid;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  color: #FFFFFF;
  background: #6B5134;
  border-radius: 999px;
  font-size: 0.8rem;
  place-items: center;
}

#keyboard-help {
  margin: 0;
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: center;
}

.state-card {
  display: grid;
  width: min(100% - 32px, 390px);
  align-self: center;
  justify-items: center;
  gap: 14px;
  margin: auto;
  padding: 30px 24px;
  text-align: center;
  background: var(--color-card-bg);
  border: 1px solid rgba(158, 125, 30, 0.25);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card-soft);
}

.state-card__title {
  margin: 0;
  color: #5F3A24;
  font-size: 1.55rem;
}

.state-card__text {
  margin: 0;
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  line-height: 1.45;
}

.loading-orbit {
  width: 46px;
  height: 46px;
  border: 5px solid #F3DFA2;
  border-top-color: #B88A18;
  border-radius: 50%;
  animation: orbit 900ms linear infinite;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 15px;
  border-radius: 13px;
  font-family: Arial, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
}

.button .game-icon {
  width: 25px;
  height: 25px;
  flex-basis: 25px;
}

.button--primary {
  color: #3E2A15;
  background: #E5C158;
  box-shadow: var(--shadow-button-25d);
}

.button--primary:hover {
  background: #F0D373;
}

.button--secondary {
  color: #60462E;
  background: #F7EDD8;
  border: 1px solid rgba(158, 125, 30, 0.45);
  box-shadow: 0 2px 0 rgba(158, 125, 30, 0.32);
}

.modal-overlay {
  position: absolute;
  z-index: 20;
  display: grid;
  inset: 0;
  padding: 18px;
  background: var(--color-overlay-dim);
  place-items: center;
}

.modal-dialog {
  display: grid;
  width: min(100%, 410px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  overflow-x: hidden;
  padding: 19px;
  background: #FFFDF8;
  border: 1px solid rgba(158, 125, 30, 0.45);
  border-radius: var(--radius-card);
  box-shadow: 0 20px 46px rgba(44, 38, 35, 0.28);
}

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

.modal-title {
  margin: 0;
  color: #5F3A24;
  font-size: 1.35rem;
}

.modal-dialog--quote .modal-header {
  justify-content: center;
}

.modal-dialog--quote .modal-title {
  width: 100%;
  font-size: clamp(1.2rem, 5vw, 1.55rem);
  text-align: center;
}

.modal-dialog--store .modal-header {
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-close-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  color: #FFFFFF;
  background: #B94D4A;
  border-radius: 50%;
  font-size: 1.75rem;
  line-height: 1;
}

.modal-close-button:hover {
  color: #FFFFFF;
  background: #D0635F;
}

.store-content,
.quote-reward,
.mode-completed,
.conflict-content {
  display: grid;
  gap: 12px;
}

.store-balance {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 0;
  color: #60462E;
  font-family: Arial, sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
}

.store-balance .game-icon {
  width: 62px;
  height: 62px;
  flex-basis: 62px;
}

.store-balance .js-store-balance {
  min-width: 42px;
  color: #60462E;
  font-size: 1.5rem;
  font-weight: 900;
}

.conflict-option {
  display: grid;
  width: 100%;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  color: var(--color-text-main);
  text-align: left;
  background: #F9F1E0;
  border: 1px solid rgba(158, 125, 30, 0.32);
  border-radius: 13px;
  font-family: Arial, sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
}

.store-option {
  display: grid;
  width: 100%;
  min-height: 78px;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  min-width: 0;
  padding: 12px 14px;
  color: var(--color-text-main);
  text-align: left;
  background: linear-gradient(145deg, #FFF8E9, #F5E4BB);
  border: 1px solid rgba(158, 125, 30, 0.4);
  border-radius: 15px;
  box-shadow: 0 3px 0 rgba(129, 91, 38, 0.24), 0 8px 16px rgba(92, 62, 27, 0.1);
  font-family: Arial, sans-serif;
}

.store-option:hover,
.conflict-option:hover {
  background: #FFF8E7;
}

.store-option:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 rgba(129, 91, 38, 0.24), 0 10px 18px rgba(92, 62, 27, 0.14);
}

.store-option:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(129, 91, 38, 0.24), 0 4px 9px rgba(92, 62, 27, 0.1);
}

.store-option:disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
  opacity: 0.65;
}

.conflict-option .game-icon {
  width: 31px;
  height: 31px;
  flex-basis: 31px;
}

.store-option .game-icon {
  width: 54px;
  height: 54px;
  flex-basis: 54px;
}

.store-option__details {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.store-option__title {
  color: #60462E;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
}

.store-option__price {
  padding: 7px 10px;
  color: #7B4C1E;
  background: #F8D76A;
  border: 1px solid rgba(158, 112, 16, 0.35);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  font-size: 1rem;
  font-weight: 900;
  white-space: nowrap;
}

.quote-reward > .game-icon,
.mode-completed > .game-icon {
  width: 74px;
  height: 74px;
  justify-self: center;
}

.quote-reward__text {
  margin: 0;
  color: #433224;
  font-size: clamp(1.22rem, 4.8vw, 1.45rem);
  line-height: 1.6;
  text-align: center;
}

.quote-reward__reference {
  margin: 0;
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  font-size: 0.84rem;
  text-align: center;
}

.verse-word-highlight {
  color: #785518;
  font-weight: 800;
  text-shadow: 0 1px 0 #FFF7D5;
}

.modal-actions {
  display: grid;
  gap: 9px;
  margin-top: 5px;
}

.mode-completed__text,
.modal-description {
  margin: 0;
  color: var(--color-text-muted);
  font-family: Arial, sans-serif;
  line-height: 1.45;
  text-align: center;
}

.toast {
  position: absolute;
  z-index: 30;
  right: 16px;
  bottom: 20px;
  left: 16px;
  padding: 12px 14px;
  color: #FFFFFF;
  border-radius: 13px;
  box-shadow: 0 8px 22px rgba(44, 38, 35, 0.24);
  font-family: Arial, sans-serif;
  font-size: 0.86rem;
  line-height: 1.35;
  animation: toast-in 220ms ease both;
}

.toast--info {
  background: #5F715E;
}

.toast--success {
  background: #567A54;
}

.toast--warning {
  background: #8B6534;
}

.is-loading {
  cursor: wait;
  opacity: 0.72;
}

@keyframes orbit {
  to {
    transform: rotate(1turn);
  }
}

@keyframes found-pop {
  0% {
    transform: scale(0.9);
  }
  45% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

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

@keyframes guide-pulse {
  0%,
  100% {
    box-shadow: 0 2px 0 rgba(140, 101, 64, 0.25);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(212, 175, 55, 0.42);
  }
}

@keyframes correct-path-pulse {
  0% {
    opacity: 0.65;
    transform: scale(0.88);
  }
  45% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 640px) {
  body {
    padding: 22px 0;
  }

  .app-shell {
    min-height: min(900px, calc(100dvh - 44px));
    border: 1px solid rgba(140, 101, 64, 0.3);
    border-radius: 28px;
    box-shadow: 0 18px 54px rgba(44, 38, 35, 0.18);
  }
}

@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;
  }
}
