:root {
  --paper: #f6f1e8;
  --paper-deep: #ece3d3;
  --paper-soft: #fbf7ef;
  --ink: #1d2129;
  --ink-soft: #445064;
  --navy: #11233a;
  --navy-soft: #1a3254;
  --gold: #b89147;
  --gold-soft: #d6bf83;
  --success: #3f7a5c;
  --success-soft: #dceddf;
  --danger: #8a4a46;
  --danger-soft: #f3dfdc;
  --shadow-lg: 0 26px 60px rgba(17, 35, 58, 0.13);
  --shadow-md: 0 14px 34px rgba(17, 35, 58, 0.12);
  --shadow-sm: 0 8px 18px rgba(17, 35, 58, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --grid-cell: 3.4rem;
  --transition: 180ms ease;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(214, 191, 131, 0.22), transparent 28%),
    radial-gradient(circle at bottom right, rgba(17, 35, 58, 0.08), transparent 30%),
    linear-gradient(180deg, #faf6ee 0%, #f2eadf 100%);
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background-color: var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
.cell:focus-visible,
.clue-button:focus-visible,
.connection-tile:focus-visible {
  outline: 3px solid rgba(184, 145, 71, 0.5);
  outline-offset: 2px;
}

.app-shell {
  width: min(1440px, calc(100% - 1.2rem));
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 1rem) 0 1rem;
}

.topbar,
.play-surface,
.panel-card,
.controls,
.modal-card {
  border: 1px solid rgba(17, 35, 58, 0.1);
  background: rgba(251, 247, 239, 0.88);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-md);
}

.topbar {
  display: grid;
  gap: 1rem;
  padding: 1.2rem;
  border-radius: var(--radius-xl);
}

.edition-kicker,
.surface-kicker,
.modal-kicker,
.eyebrow {
  margin: 0 0 0.35rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
}

.brand-block h1,
.play-surface-head h2,
.connections-head h2,
.modal-card h2 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.8rem);
  font-weight: 700;
  line-height: 1.04;
  color: var(--navy);
}

.edition-note,
.surface-meta,
#install-copy {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  line-height: 1.55;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.status-card,
.rank-line,
.stats-grid div,
.achievement-item,
.recent-item,
.connections-group {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(17, 35, 58, 0.08);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.status-card {
  padding: 0.8rem 0.95rem;
}

.status-card .label {
  display: block;
  margin-bottom: 0.18rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.status-card strong {
  color: var(--navy);
  font-size: 1.15rem;
}

.topbar-actions,
.control-group,
.modal-actions,
.panel-title-row,
.connections-head,
.play-surface-head,
.clue-header,
.connections-footer {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.85fr);
  gap: 1rem;
  margin-top: 1rem;
}

.main-stack {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.play-surface {
  padding: 1.2rem;
  border-radius: var(--radius-xl);
}

.mode-view {
  display: none;
}

.mode-view.active {
  display: block;
}

.crossword-stage {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.board-frame {
  display: flex;
  justify-content: center;
  padding: 1.25rem;
  overflow-x: auto;
  border-radius: calc(var(--radius-xl) - 8px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(248, 241, 229, 0.98));
  border: 1px solid rgba(17, 35, 58, 0.12);
}

.board-frame-crossword {
  min-height: 420px;
  align-items: center;
}

.crossword-board {
  display: grid;
  gap: 2px;
  width: fit-content;
  max-width: 100%;
}

.cell,
.block-cell {
  width: var(--cell-size, var(--grid-cell));
  height: var(--cell-size, var(--grid-cell));
}

.cell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 2px solid #18212d;
  background: #fffdf9;
  color: var(--ink);
  font-size: clamp(1rem, 3vw, 1.55rem);
  font-weight: 700;
  text-transform: uppercase;
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
}

.cell:hover {
  transform: translateY(-1px);
}

.cell.active-word {
  background: #fdf2d7;
}

.cell.crossing-word {
  background: #edf4fc;
}

.cell.active-cell {
  background: #ffd36a;
  box-shadow: inset 0 0 0 3px rgba(17, 35, 58, 0.18);
}

.cell.incorrect {
  background: var(--danger-soft);
  animation: shake 260ms linear 1;
}

.cell-number {
  position: absolute;
  top: 0.08rem;
  left: 0.18rem;
  font-size: 0.58rem;
  line-height: 1;
  color: var(--ink-soft);
  font-weight: 700;
}

.block-cell {
  background: #111;
  border-radius: 2px;
}

.word-banner {
  min-height: 3.4rem;
  padding: 0.95rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(17, 35, 58, 0.06);
  color: var(--navy);
  box-shadow: none;
  border: 1px solid rgba(17, 35, 58, 0.08);
}

.word-banner strong {
  color: var(--navy);
}

.clue-panel {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border-radius: calc(var(--radius-xl) - 6px);
  background: rgba(255, 251, 244, 0.88);
  border: 1px solid rgba(17, 35, 58, 0.08);
}

.clue-header h3,
.clue-group h4,
.panel-title-row h3 {
  margin: 0;
  color: var(--navy);
}

.clue-columns {
  display: grid;
  gap: 0.8rem;
  overflow: auto;
  max-height: 56vh;
  padding-right: 0.2rem;
}

.clue-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

.clue-button {
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(17, 35, 58, 0.08);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.clue-button:hover {
  background: rgba(255, 248, 229, 0.9);
}

.clue-button.active {
  background: rgba(253, 242, 215, 0.95);
  border-color: rgba(184, 145, 71, 0.45);
  transform: translateX(2px);
}

.clue-number {
  font-weight: 700;
  color: var(--navy);
  margin-right: 0.45rem;
}

.clue-status {
  color: var(--gold);
  margin-left: 0.35rem;
}

.panel-card {
  padding: 1rem;
  border-radius: var(--radius-xl);
}

.detail-surface {
  padding: 0.9rem;
  border: 1px solid rgba(17, 35, 58, 0.1);
  background: rgba(251, 247, 239, 0.88);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-xl);
}

.detail-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.detail-tab {
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(17, 35, 58, 0.1);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink-soft);
}

.detail-tab.active {
  background: var(--navy);
  color: #fff8eb;
  border-color: var(--navy);
}

.detail-panel {
  display: none;
}

.detail-panel.active {
  display: block;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(0, 1.28fr);
  gap: 1rem;
}

.hero-card {
  background: linear-gradient(180deg, rgba(17, 35, 58, 0.96), rgba(22, 42, 70, 0.94));
  color: #fbf7ef;
}

.hero-card #rank-label,
.hero-card #rank-note {
  color: #fbf7ef;
}

.progress-track {
  height: 0.7rem;
  margin-top: 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), #f4d48a);
  transition: width 320ms ease;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
}

.stats-grid div {
  padding: 0.8rem;
}

.stats-grid dt {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.stats-grid dd {
  margin: 0.25rem 0 0;
  color: var(--navy);
  font-size: 1.12rem;
  font-weight: 700;
}

.achievement-list,
.recent-list,
.connections-solved {
  display: grid;
  gap: 0.75rem;
}

.achievement-item,
.recent-item,
.connections-group {
  padding: 0.9rem;
}

.achievement-item.locked {
  opacity: 0.55;
}

.achievement-item strong,
.recent-item strong,
.connections-group strong {
  display: block;
  color: var(--navy);
}

.achievement-item span,
.recent-item span,
.connections-group span {
  color: var(--ink-soft);
  line-height: 1.45;
}

.connections-tier {
  display: inline-block;
  margin: 0.3rem 0 0.4rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: rgba(17, 35, 58, 0.08);
  color: var(--navy) !important;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.75rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--navy);
  background: rgba(184, 145, 71, 0.14);
}

.hidden {
  display: none !important;
}

.controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-xl);
}

.segmented {
  padding: 0.25rem;
  border-radius: 999px;
  background: rgba(17, 35, 58, 0.06);
}

.segment,
.ghost-button,
.primary-button {
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

.segment {
  padding: 0.6rem 1rem;
  background: transparent;
  color: var(--navy);
}

.segment.active {
  background: var(--navy);
  color: #fff8eb;
  box-shadow: var(--shadow-sm);
}

.ghost-button,
.primary-button {
  padding: 0.72rem 1.15rem;
  min-height: 2.8rem;
}

.ghost-button {
  color: var(--navy);
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(17, 35, 58, 0.12);
}

.ghost-button.danger {
  color: var(--danger);
  background: #fff7f5;
  border-color: rgba(138, 74, 70, 0.2);
}

.primary-button {
  color: #fff8eb;
  background: linear-gradient(135deg, var(--navy), var(--navy-soft));
  box-shadow: var(--shadow-sm);
}

.connections-shell {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.connections-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  min-height: 12rem;
}

.connections-empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 10rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(17, 35, 58, 0.08);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink-soft);
}

.connection-tile {
  min-height: 5.1rem;
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(17, 35, 58, 0.1);
  background: rgba(255, 255, 255, 0.8);
  color: var(--navy);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  box-shadow: var(--shadow-sm);
}

.connection-tile.selected {
  background: rgba(253, 242, 215, 0.96);
  border-color: rgba(184, 145, 71, 0.45);
}

.connection-tile.solved-0,
.connections-group.tier-0 {
  background: #f8ebca;
}

.connection-tile.solved-1,
.connections-group.tier-1 {
  background: #dbeadf;
}

.connection-tile.solved-2,
.connections-group.tier-2 {
  background: #dae6f5;
}

.connection-tile.solved-3,
.connections-group.tier-3 {
  background: #e8deef;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(14, 22, 33, 0.45);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  padding: 1.4rem;
  border-radius: var(--radius-xl);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: none;
  background: rgba(17, 35, 58, 0.06);
  color: var(--navy);
}

.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  z-index: 40;
  display: grid;
  gap: 0.7rem;
  width: min(360px, calc(100vw - 2rem));
}

.toast {
  padding: 0.95rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(17, 35, 58, 0.95);
  color: #fff8eb;
  box-shadow: var(--shadow-lg);
  animation: toast-in 240ms ease;
}

.keyboard-proxy {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
  width: 2rem;
  height: 2rem;
  transform: translateX(-50%);
  opacity: 0.01;
  pointer-events: none;
  border: 0;
  padding: 0;
  background: transparent;
}

.celebration-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.sparkle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  opacity: 0;
  animation: sparkle 1.8s ease forwards;
}

@keyframes sparkle {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.4);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-120px) scale(1.05);
  }
}

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

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

@media (max-width: 1120px) {
  .clue-columns {
    max-height: none;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100% - 0.8rem);
  }

  .controls {
    justify-content: center;
  }

  .topbar,
  .play-surface,
  .panel-card,
  .controls,
  .modal-card {
    border-radius: 22px;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-frame {
    padding: 0.65rem;
  }

  .clue-panel {
    padding: 0.8rem;
  }

  .detail-surface {
    padding: 0.75rem;
  }

  .connections-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: calc(100% - 0.5rem);
    padding-top: calc(env(safe-area-inset-top, 0px) + 0.5rem);
  }

  .topbar,
  .play-surface,
  .panel-card,
  .controls,
  .detail-surface {
    padding: 0.8rem;
  }

  .status-strip,
  .stats-grid,
  .connections-grid {
    grid-template-columns: 1fr 1fr;
  }

  .connection-tile {
    min-height: 4.2rem;
    font-size: 0.92rem;
  }

  .ghost-button,
  .primary-button,
  .segment,
  .detail-tab {
    padding-inline: 0.9rem;
  }
}

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