:root {
  --bg-top: #f6dcc3;
  --bg-bottom: #f1f5f0;
  --card: rgba(255, 250, 244, 0.9);
  --card-border: rgba(151, 89, 46, 0.18);
  --text-main: #2f241f;
  --text-muted: #68544a;
  --accent: #d2683f;
  --accent-soft: rgba(210, 104, 63, 0.14);
  --accent-strong: #b8522e;
  --teal: #1f7d77;
  --teal-soft: rgba(31, 125, 119, 0.14);
  --danger: #bf4b4b;
  --danger-soft: rgba(191, 75, 75, 0.16);
  --board-line: #5a4033;
  --board-thin: rgba(90, 64, 51, 0.25);
  --shadow-soft: 0 24px 70px rgba(75, 38, 16, 0.16);
  --radius-xl: 28px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 36%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

button {
  font: inherit;
}

.page-shell {
  position: relative;
  min-height: 100vh;
  padding: 16px;
  overflow: hidden;
}

.ambient {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 999px;
  filter: blur(8px);
  opacity: 0.55;
  pointer-events: none;
}

.ambient-left {
  left: -110px;
  top: -120px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0));
}

.ambient-right {
  right: -140px;
  bottom: -150px;
  background: radial-gradient(circle, rgba(31, 125, 119, 0.24), rgba(31, 125, 119, 0));
}

.game-card {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: calc(100vh - 32px);
  padding: 16px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  background: var(--card);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.app-view.hidden {
  display: none;
}

.panel-block,
.selection-hero,
.play-topbar {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(151, 89, 46, 0.12);
}

.eyebrow,
.section-kicker {
  margin: 0 0 10px;
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--teal);
}

.selection-view {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 64px);
}

.selection-shell {
  display: grid;
  gap: 18px;
  width: min(100%, 980px);
}

.selection-hero h1 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(2.4rem, 4vw, 4rem);
  line-height: 1;
}

.selection-intro,
.compact-note,
.panel-block p,
.secondary-note,
.play-tier {
  margin: 12px 0 0;
  line-height: 1.7;
  color: var(--text-muted);
}

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

.status-chip {
  padding: 14px 16px;
  border-radius: 16px;
  background: white;
  border: 1px solid rgba(151, 89, 46, 0.1);
}

.status-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.status-chip strong {
  font-size: 1.04rem;
}

.selection-card h2,
.panel-block h2,
.play-heading h2 {
  margin: 0;
}

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

.batch-switch,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.compact-button {
  padding: 8px 12px;
}

.compact-level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.play-view {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
  min-height: calc(100vh - 64px);
}

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

.play-heading {
  flex: 1;
}

.play-tier {
  margin-top: 6px;
}

.play-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 10px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  min-height: 0;
}

.play-sidebar {
  display: grid;
  gap: 12px;
  align-content: start;
  overflow: auto;
  padding-right: 4px;
}

.rail-actions > * {
  flex: 1 1 calc(50% - 10px);
}

.primary-button,
.secondary-button,
.pad-button,
.cell,
.level-button {
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    opacity 160ms ease;
}

.primary-button,
.secondary-button {
  padding: 11px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.primary-button {
  color: white;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 14px 28px rgba(210, 104, 63, 0.24);
}

.secondary-button {
  color: var(--text-main);
  background: white;
  border: 1px solid rgba(90, 64, 51, 0.14);
}

.primary-button:hover,
.secondary-button:hover,
.pad-button:hover,
.cell:hover,
.level-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.pad-button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.level-button {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid rgba(90, 64, 51, 0.1);
  background: white;
  color: var(--text-main);
  cursor: pointer;
  font-weight: 700;
}

.level-button.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 12px 20px rgba(210, 104, 63, 0.2);
}

.level-button.completed:not(.active) {
  background: rgba(227, 244, 242, 0.94);
  border-color: rgba(31, 125, 119, 0.16);
  color: var(--teal);
}

.level-button.locked {
  background: rgba(90, 64, 51, 0.06);
  color: rgba(47, 36, 31, 0.42);
  border-style: dashed;
}

.board-stage {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.board-stage-head {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 36px;
}

.star-meter {
  display: flex;
  justify-content: center;
  width: 100%;
  pointer-events: none;
}

.life-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.life-star {
  color: rgba(90, 64, 51, 0.24);
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  line-height: 1;
  transition:
    color 180ms ease,
    transform 180ms ease,
    filter 180ms ease;
}

.life-star.active {
  color: #d84b5d;
  transform: scale(1.05);
  filter: drop-shadow(0 4px 8px rgba(216, 75, 93, 0.26));
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 16px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 239, 231, 0.86)),
    repeating-linear-gradient(
      45deg,
      rgba(210, 104, 63, 0.03) 0,
      rgba(210, 104, 63, 0.03) 10px,
      transparent 10px,
      transparent 20px
    );
  border: 1px solid rgba(151, 89, 46, 0.12);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: min(100%, 76vh);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 22px;
  overflow: hidden;
  border: 3px solid var(--board-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: none;
  border-right: 1px solid var(--board-thin);
  border-bottom: 1px solid var(--board-thin);
  background: rgba(255, 254, 251, 0.96);
  color: var(--text-main);
  font-size: clamp(1.25rem, 2vw, 2rem);
  font-weight: 700;
  cursor: pointer;
}

.cell:nth-child(9n) {
  border-right: none;
}

.cell[data-box-right="true"] {
  box-shadow: inset -2px 0 0 var(--board-line);
}

.cell[data-box-bottom="true"] {
  box-shadow: inset 0 -2px 0 var(--board-line);
}

.cell[data-box-right="true"][data-box-bottom="true"] {
  box-shadow:
    inset -2px 0 0 var(--board-line),
    inset 0 -2px 0 var(--board-line);
}

.cell.fixed {
  color: var(--teal);
  background: rgba(227, 244, 242, 0.94);
}

.cell.selected {
  background: rgba(210, 104, 63, 0.22);
  color: var(--accent-strong);
}

.cell.related {
  background: rgba(210, 104, 63, 0.11);
}

.cell.same-number {
  background: rgba(31, 125, 119, 0.14);
}

.cell.conflict {
  background: var(--danger-soft);
  color: var(--danger);
}

.cell.hint-cell {
  animation: pop-in 320ms ease;
  outline: 3px solid rgba(31, 125, 119, 0.35);
  outline-offset: -3px;
}

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

.board-overlay,
.level-start-overlay,
.game-over-overlay {
  position: absolute;
  inset: 16px;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  background: rgba(248, 240, 232, 0.9);
  border-radius: 22px;
  backdrop-filter: blur(4px);
}

.board-overlay.hidden,
.level-start-overlay.hidden,
.game-over-overlay.hidden {
  display: none;
}

.start-card {
  max-width: 420px;
  padding: 26px 24px;
  border-radius: 22px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(247, 238, 229, 0.92)),
    repeating-linear-gradient(
      45deg,
      rgba(210, 104, 63, 0.03) 0,
      rgba(210, 104, 63, 0.03) 10px,
      transparent 10px,
      transparent 20px
    );
  border: 1px solid rgba(151, 89, 46, 0.14);
  box-shadow: 0 18px 40px rgba(75, 38, 16, 0.12);
}

.game-over-card {
  background:
    linear-gradient(180deg, rgba(255, 249, 249, 0.98), rgba(250, 235, 235, 0.94)),
    repeating-linear-gradient(
      45deg,
      rgba(191, 75, 75, 0.04) 0,
      rgba(191, 75, 75, 0.04) 10px,
      transparent 10px,
      transparent 20px
    );
  border-color: rgba(191, 75, 75, 0.18);
}

.start-card h2 {
  margin: 0;
  font-size: clamp(1.6rem, 2.4vw, 2.2rem);
}

.start-card p:last-of-type {
  margin: 12px 0 18px;
  line-height: 1.7;
  color: var(--text-muted);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(90, 64, 51, 0.12);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 1s linear infinite;
}

kbd {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(90, 64, 51, 0.08);
  font-size: 0.92em;
}

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

.pad-button {
  min-height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(90, 64, 51, 0.12);
  background: white;
  color: var(--text-main);
  cursor: pointer;
}

.pad-button.wide {
  grid-column: span 2;
}

.pad-button.danger {
  color: var(--danger);
}

.flash-success {
  animation: celebrate 900ms ease;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pop-in {
  from {
    transform: scale(0.92);
  }

  to {
    transform: scale(1);
  }
}

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

  20% {
    transform: translateX(-5px);
  }

  40% {
    transform: translateX(5px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(4px);
  }
}

@keyframes celebrate {
  0%,
  100% {
    box-shadow: inset 0 0 0 transparent;
  }

  30% {
    box-shadow: inset 0 0 0 999px rgba(31, 125, 119, 0.08);
  }

  60% {
    box-shadow: inset 0 0 0 999px rgba(210, 104, 63, 0.08);
  }
}

@media (max-width: 1100px) {
  .selection-summary,
  .play-layout {
    grid-template-columns: 1fr;
  }

  .play-topbar {
    flex-direction: column;
    align-items: stretch;
  }

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

  .play-sidebar {
    overflow: visible;
    padding-right: 0;
  }

  .board {
    width: min(100%, 82vw);
  }
}

@media (max-width: 760px) {
  .page-shell {
    padding: 10px;
  }

  .game-card {
    min-height: auto;
    padding: 12px;
  }

  .selection-summary,
  .play-stats {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .batch-switch,
  .action-row {
    width: 100%;
  }

  .compact-level-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .board {
    width: min(100%, 92vw);
  }

  .number-pad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .pad-button.wide {
    grid-column: span 3;
  }
}
