:root {
  color-scheme: light;
  --ms-page: #f5efe2;
  --ms-page-edge: #fbf7ef;
  --ms-card: rgba(255, 251, 245, 0.8);
  --ms-line: rgba(113, 101, 82, 0.22);
  --ms-line-strong: rgba(113, 101, 82, 0.38);
  --ms-text: #17130f;
  --ms-muted: #625a4f;
  --ms-soft: #8b8378;
  --ms-focus: #587fa4;
  --ms-active: #dbe8f4;
  --ms-found: #d6e4ef;
  --ms-spangram: #eed377;
  --ms-hint: rgba(222, 191, 92, 0.18);
  --ms-active-line: #6e96b8;
  --ms-found-line: #94b5cb;
  --ms-spangram-line: #c8a539;
  --ms-danger: #9f5648;
  --ms-ok: #446854;
  --ms-shadow: 0 14px 34px rgba(41, 34, 24, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(255, 251, 243, 0.96) 0, rgba(255, 251, 243, 0.7) 24%, transparent 52%),
    linear-gradient(180deg, var(--ms-page-edge) 0%, var(--ms-page) 52%, #f1e9d9 100%);
  color: var(--ms-text);
  font-family: 'Source Sans 3', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow-x: hidden;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ms-focus);
  outline-offset: 3px;
}

.ms-app {
  width: min(820px, calc(100% - 28px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 22px 0 calc(38px + env(safe-area-inset-bottom));
}

.ms-shell {
  display: grid;
  gap: clamp(14px, 2.2vw, 20px);
  justify-items: center;
}

.ms-page-header {
  width: min(100%, 620px);
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
}

.ms-page-kicker {
  margin: 0;
  color: var(--ms-soft);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.ms-page-title {
  margin: 0;
  font-family: 'Newsreader', Georgia, serif;
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.ms-game-head {
  width: min(100%, 620px);
  display: grid;
  gap: 12px;
}

.ms-theme-card {
  display: grid;
  gap: 8px;
  padding: 15px 18px 16px;
  border: 1px solid var(--ms-line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.9) 0%, rgba(255, 249, 241, 0.72) 100%);
  box-shadow: var(--ms-shadow);
}

.ms-theme-label,
.ms-found-label,
.ms-share-label {
  margin: 0;
  color: var(--ms-soft);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.ms-theme-title {
  margin: 0;
  font-family: 'Newsreader', Georgia, serif;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.ms-theme-clue {
  margin: 0;
  color: var(--ms-muted);
  font-size: 0.98rem;
  line-height: 1.42;
}

.ms-status-cluster {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.ms-status-primary,
.ms-status-secondary {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 18px;
  text-align: center;
}

.ms-progress-line,
.ms-refresh-line,
.ms-hint-copy,
.ms-hint-stock,
.ms-dialog-note,
.ms-dialog-stats,
.ms-explain {
  margin: 0;
  line-height: 1.4;
}

.ms-progress-line {
  color: var(--ms-text);
  font-size: 0.97rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.ms-hint-copy,
.ms-refresh-line,
.ms-hint-stock {
  color: var(--ms-muted);
  font-size: 0.87rem;
}

.ms-refresh-line {
  color: var(--ms-soft);
}

.ms-hint-panel {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.ms-hint-btn,
.ms-btn,
.ms-icon-btn {
  border: 1px solid var(--ms-line);
  border-radius: 999px;
  background: rgba(255, 251, 245, 0.58);
  color: var(--ms-text);
  transition:
    border-color 120ms ease,
    background 120ms ease,
    color 120ms ease,
    transform 120ms ease,
    opacity 120ms ease;
}

.ms-hint-btn {
  width: fit-content;
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 700;
}

.ms-hint-btn:hover,
.ms-hint-btn:focus-visible,
.ms-btn:hover,
.ms-btn:focus-visible,
.ms-icon-btn:hover,
.ms-icon-btn:focus-visible {
  border-color: var(--ms-line-strong);
  background: rgba(255, 252, 247, 0.9);
}

.ms-hint-btn:active,
.ms-btn:active,
.ms-icon-btn:active {
  transform: scale(0.98);
}

.ms-hint-btn[disabled] {
  cursor: default;
  opacity: 0.58;
}

.ms-hint-btn.is-ready {
  border-color: rgba(200, 165, 57, 0.78);
  background: rgba(238, 211, 119, 0.22);
}

.ms-hint-text {
  display: inline-flex;
  align-items: center;
}

.ms-hint-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.ms-hint-dot {
  width: 7px;
  height: 7px;
  border: 1.4px solid var(--ms-line-strong);
  border-radius: 999px;
  background: transparent;
  transition: background 120ms ease, border-color 120ms ease;
}

.ms-hint-dot.is-filled {
  background: var(--ms-text);
  border-color: var(--ms-text);
}

.ms-hint-btn.is-ready .ms-hint-dot {
  border-color: rgba(200, 165, 57, 0.8);
}

.ms-hint-btn.is-ready .ms-hint-dot.is-filled {
  background: var(--ms-spangram-line);
  border-color: var(--ms-spangram-line);
}

.ms-board-stage {
  width: min(100%, 700px);
  display: grid;
  gap: 8px;
  justify-items: center;
}

.ms-selection-overlay {
  width: min(100%, 620px);
  min-height: 38px;
  display: grid;
  gap: 3px;
  justify-items: center;
  align-content: start;
  text-align: center;
  pointer-events: none;
}

.ms-current-word,
.ms-message {
  margin: 0;
  min-height: 1.15em;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-3px);
  transition:
    visibility 0ms linear 140ms,
    opacity 140ms ease,
    transform 140ms ease;
}

.ms-current-word {
  color: var(--ms-text);
  font-size: clamp(1.02rem, 2.1vw, 1.24rem);
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.ms-current-word.is-invalid-feedback {
  color: var(--ms-danger);
  animation: ms-feedback-shake 220ms ease;
}

.ms-message {
  color: var(--ms-muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.ms-message.is-visible,
.ms-current-word.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0ms;
}

.ms-message.is-fading {
  opacity: 0;
}

.ms-message.is-invalid-feedback {
  animation: ms-feedback-shake 220ms ease;
}

.ms-message[data-type='ok'] {
  color: var(--ms-ok);
}

.ms-message[data-type='warn'] {
  color: #8a6a17;
}

.ms-message[data-type='error'] {
  color: var(--ms-danger);
}

.ms-board-panel {
  width: 100%;
  display: grid;
  place-items: center;
}

.ms-board-shell {
  position: relative;
  width: min(100%, 680px);
  padding: 10px 8px 6px;
  overflow: visible;
  touch-action: none;
  user-select: none;
  isolation: isolate;
}

.ms-board-shell.is-invalid-feedback {
  animation: ms-feedback-shake 220ms ease;
}

.ms-board-shell.is-valid-feedback .ms-conn-active,
.ms-board-shell.is-bonus-feedback .ms-conn-active,
.ms-board-shell.is-spangram-feedback .ms-conn-active {
  opacity: 0.96;
}

.ms-board-connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.ms-conn {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  shape-rendering: geometricPrecision;
  transition:
    opacity 120ms ease,
    stroke 120ms ease,
    stroke-width 120ms ease;
}

.ms-conn-found {
  stroke: var(--ms-found-line);
  stroke-width: 14px;
  opacity: 0.94;
}

.ms-conn-spangram {
  stroke: var(--ms-spangram-line);
  stroke-width: 15.5px;
  opacity: 0.98;
}

.ms-conn-active {
  stroke: var(--ms-active-line);
  stroke-width: 12.5px;
  opacity: 0.96;
}

.ms-conn-active-tail {
  stroke: var(--ms-active-line);
  stroke-width: 9.5px;
  opacity: 0.55;
}

.ms-conn-hint {
  stroke: rgba(200, 165, 57, 0.74);
  stroke-width: 12px;
  stroke-dasharray: 5 7;
  opacity: 0.76;
}

.ms-board {
  position: relative;
  z-index: 2;
  width: min(100%, 640px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(3px, 0.7vw, 6px);
  justify-content: center;
  align-items: center;
}

.ms-tile {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: transparent;
  color: var(--ms-text);
  font-family: 'Source Sans 3', system-ui, sans-serif;
  font-size: clamp(1.18rem, 3vw, 1.95rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  display: grid;
  place-items: center;
  cursor: pointer;
  isolation: isolate;
  transition: transform 120ms ease, color 120ms ease;
}

.ms-tile::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 72%;
  height: 72%;
  border-radius: 999px;
  background: rgba(255, 251, 245, 0.56);
  box-shadow: inset 0 0 0 1px rgba(113, 101, 82, 0.08);
  transform: translate(-50%, -50%);
  transition:
    background 120ms ease,
    box-shadow 120ms ease,
    transform 120ms ease;
  z-index: -1;
}

.ms-tile:hover::before {
  background: rgba(255, 252, 246, 0.9);
  box-shadow: inset 0 0 0 1px rgba(113, 101, 82, 0.18);
}

.ms-tile:active {
  transform: scale(0.985);
}

.ms-tile.active {
  transform: scale(0.988);
}

.ms-tile.active::before {
  background: var(--ms-active);
  box-shadow: inset 0 0 0 1px rgba(110, 150, 184, 0.26);
  transform: translate(-50%, -50%) scale(1.04);
}

.ms-tile.found::before,
.ms-tile.found-0::before,
.ms-tile.found-1::before,
.ms-tile.found-2::before,
.ms-tile.found-3::before,
.ms-tile.found-4::before,
.ms-tile.found-5::before {
  background: var(--ms-found);
  box-shadow: inset 0 0 0 1px rgba(148, 181, 203, 0.22);
}

.ms-tile.spangram::before {
  background: var(--ms-spangram);
  box-shadow: inset 0 0 0 1px rgba(200, 165, 57, 0.2);
}

.ms-tile.hint::before {
  background: var(--ms-hint);
  box-shadow: inset 0 0 0 1.5px rgba(200, 165, 57, 0.54);
}

.ms-tile.reject {
  animation: ms-feedback-shake 220ms ease;
}

.ms-tile.accept {
  animation: ms-accept 260ms ease;
}

.ms-tile.accept-bonus {
  animation: ms-accept-bonus 240ms ease;
}

.ms-board.is-complete-wave .ms-tile {
  animation: ms-complete-wave 480ms ease both;
  animation-delay: calc(var(--wave-order) * 22ms);
}

.ms-found-section {
  width: min(100%, 620px);
  display: grid;
  gap: 8px;
  padding-top: 6px;
  justify-items: center;
  text-align: center;
}

.ms-found-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
}

.ms-found-chip {
  color: #3e372e;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ms-summary-link {
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ms-muted);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(98, 90, 79, 0.4);
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.ms-summary-link:hover,
.ms-summary-link:focus-visible {
  color: var(--ms-text);
  text-decoration-color: currentColor;
  outline: none;
}

.ms-btn {
  min-height: 38px;
  padding: 0 15px;
  cursor: pointer;
  font-weight: 700;
}

.ms-icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  font-size: 1rem;
}

.ms-dialog {
  width: min(460px, calc(100vw - 24px));
  max-height: min(90dvh, 760px);
  padding: 0;
  border: 1px solid var(--ms-line);
  border-radius: 20px;
  background: rgba(255, 251, 245, 0.97);
  color: var(--ms-text);
  box-shadow: 0 22px 48px rgba(36, 30, 21, 0.18);
}

.ms-dialog::backdrop {
  background: rgba(62, 53, 39, 0.22);
}

.ms-dialog article {
  display: grid;
  gap: 14px;
  max-height: inherit;
  overflow: auto;
  padding: 18px;
}

.ms-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ms-dialog h2,
.ms-dialog-summary {
  margin: 0;
}

.ms-dialog h2 {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.ms-dialog-summary {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.14rem;
  line-height: 1.3;
  color: var(--ms-text);
}

.ms-share-block {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.ms-explain {
  padding-left: 12px;
  border-left: 2px solid rgba(113, 101, 82, 0.34);
  color: var(--ms-muted);
}

.ms-share-preview {
  margin: 0;
  padding: 12px 14px;
  border: 1px dashed var(--ms-line-strong);
  border-radius: 14px;
  background: #fffaf2;
  color: #3d352c;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ms-dialog-actions {
  display: flex;
  justify-content: flex-start;
}

@keyframes ms-feedback-shake {
  0% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  50% {
    transform: translateX(3px);
  }
  75% {
    transform: translateX(-2px);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes ms-accept {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes ms-accept-bonus {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.025);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes ms-complete-wave {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 760px) {
  .ms-app {
    width: min(100%, calc(100% - 22px));
    padding-top: 18px;
  }

  .ms-theme-card {
    padding: 14px 16px 15px;
  }

  .ms-board-shell {
    padding: 8px 2px 4px;
  }
}

@media (max-width: 520px) {
  .ms-status-primary,
  .ms-status-secondary {
    gap: 8px 12px;
  }

  .ms-hint-panel {
    gap: 8px;
  }

  .ms-hint-stock,
  .ms-refresh-line {
    width: 100%;
  }

  .ms-board {
    gap: 4px;
  }
}

@media (max-width: 420px) {
  .ms-app {
    width: calc(100% - 16px);
    padding-top: 14px;
  }

  .ms-page-kicker {
    font-size: 0.62rem;
  }

  .ms-page-title {
    font-size: clamp(2rem, 8.8vw, 2.4rem);
  }

  .ms-theme-title {
    font-size: 1.42rem;
  }

  .ms-theme-clue {
    font-size: 0.94rem;
  }

  .ms-hint-btn {
    min-height: 34px;
    padding: 0 11px;
    font-size: 0.89rem;
  }

  .ms-selection-overlay {
    min-height: 40px;
  }

  .ms-current-word {
    letter-spacing: 0.18em;
  }

  .ms-tile {
    font-size: clamp(1.05rem, 5.5vw, 1.34rem);
  }

  .ms-tile::before {
    width: 76%;
    height: 76%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
