:root {
  --bg: #f6f3ec;
  --paper: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #f59e0b;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.12);
  --radius: 22px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 32rem),
    linear-gradient(180deg, #fbfaf7 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 12px 14px 28px;
}

.hero {
  text-align: center;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 11vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: -0.08em;
}

.score-card,
.grid-wrap {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.score-card {
  display: grid;
  grid-template-columns: 1fr 0.9fr 1fr 1fr;
  gap: 7px;
  padding: 8px;
  margin-bottom: 8px;
}

.number-box,
.timer-box {
  text-align: center;
  border-radius: 15px;
  padding: 8px 4px;
  background: #f9fafb;
  border: 1px solid var(--line);
  min-width: 0;
}

.number-box span,
.timer-box span {
  display: block;
  color: var(--muted);
  font-size: clamp(0.55rem, 2.25vw, 0.72rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.number-box strong,
.timer-box strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.05rem, 5.1vw, 2rem);
  line-height: 1;
  letter-spacing: -0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.starter-box {
  background: #eef6ff;
}

.current-box {
  background: #eff6ff;
}

.current-box strong {
  color: var(--accent);
}

.target-box {
  background: #fff7ed;
}

.target-box.negative-target {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, 0.28);
}

.target-box.negative-target span {
  color: var(--danger);
}

.target-box.negative-target strong {
  color: var(--danger);
  font-weight: 1000;
  text-shadow: 0 0 0 rgba(220, 38, 38, 0.2);
}

.status-text {
  margin: 0 0 8px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.25;
  text-align: center;
  min-height: 1.2em;
}

.grid-wrap {
  padding: 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: #000000;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", Arial, Helvetica, sans-serif;
  font-size: clamp(0.82rem, 3.75vw, 1.28rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: -0.03em;
  cursor: pointer;
  user-select: none;
  transition:
    transform 140ms ease,
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease,
    opacity 140ms ease;
}

.cell:active {
  transform: scale(0.96);
}

.cell.active-row {
  border-color: rgba(37, 99, 235, 0.42);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1) inset;
}

.cell.locked-row {
  opacity: 0.48;
  cursor: not-allowed;
}

.cell.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.26);
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", Arial, Helvetica, sans-serif;
  font-size: clamp(0.76rem, 3.35vw, 1.12rem);
  font-weight: 1000;
  letter-spacing: -0.04em;
}

.cell.completed-row:not(.selected) {
  background: #f3f4f6;
  opacity: 0.38;
}

.cell.solution-flash {
  background: var(--good-soft);
  border-color: var(--good);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.new-puzzle-btn {
  background: #fff7ed;
  border-color: rgba(245, 158, 11, 0.35);
}

.primary-btn,
.secondary-btn {
  border: 0;
  border-radius: 999px;
  padding: 13px 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.primary-btn {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.26);
}

.secondary-btn {
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary-btn:active,
.secondary-btn:active {
  transform: scale(0.98);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(31, 41, 55, 0.48);
  backdrop-filter: blur(7px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  position: relative;
  width: min(100%, 420px);
  max-height: 88vh;
  overflow: auto;
  padding: 24px;
  border-radius: 28px;
  background: #ffffff;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.24);
  text-align: center;
}

.overlay-card h2 {
  margin: 0 0 10px;
  font-size: 2rem;
  letter-spacing: -0.05em;
}

.overlay-card p {
  margin: 10px 0;
  color: var(--muted);
  line-height: 1.48;
}

.small-note {
  font-size: 0.9rem;
}

.toggle-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  margin: 16px 0 12px;
  padding: 14px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 18px;
  background: #f8fbff;
  text-align: left;
  cursor: pointer;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.toggle-row strong {
  display: block;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.2;
}

.toggle-row em {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-style: normal;
  font-size: 0.88rem;
  line-height: 1.35;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.solution-summary {
  margin: 16px 0;
  padding: 14px;
  border-radius: 18px;
  background: #f9fafb;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.5;
  text-align: left;
}

.solution-summary .result-line {
  display: block;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #eff6ff;
  border: 1px solid rgba(37, 99, 235, 0.14);
  text-align: center;
  font-weight: 900;
}

.solution-summary .result-line.perfect {
  background: var(--good-soft);
  border-color: rgba(22, 163, 74, 0.22);
  color: #166534;
}

.solution-summary .result-line.near-miss {
  background: #fff7ed;
  border-color: rgba(245, 158, 11, 0.24);
  color: #9a3412;
}

.solution-summary .path-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed #e5e7eb;
}

.solution-summary .path-row:last-child {
  border-bottom: 0;
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 10px;
  }

  .score-card {
    gap: 5px;
    padding: 7px;
  }

  .number-box,
  .timer-box {
    padding: 7px 3px;
    border-radius: 13px;
  }

  .grid {
    gap: 4px;
  }

  .cell {
    border-radius: 8px;
    font-size: clamp(0.78rem, 3.95vw, 1.05rem);
  }

  .cell.selected {
    font-size: clamp(0.72rem, 3.55vw, 0.98rem);
  }

  .controls {
    gap: 6px;
  }

  .primary-btn,
  .secondary-btn {
    padding: 12px 8px;
    font-size: 0.88rem;
  }
}

@media (max-width: 340px) {
  .score-card {
    gap: 4px;
  }

  .number-box span,
  .timer-box span {
    font-size: 0.52rem;
    letter-spacing: 0.03em;
  }

  .number-box strong,
  .timer-box strong {
    font-size: 0.98rem;
  }

  .cell {
    font-size: 0.7rem;
    border-radius: 7px;
  }

  .cell.selected {
    font-size: 0.66rem;
  }
}