:root {
  --bg0: #15202b;
  --bg1: #1a2433;
  --panel: #243044;
  --line: #3a4d66;
  --thick: #8fa3bf;
  --text: #f2f4f7;
  --muted: #9aabbf;
  --accent: #3d8bfd;
  --accent-soft: rgba(61, 139, 253, 0.22);
  --given: #e8eef7;
  --user: #3d8bfd;
  --note: #7d91aa;
  --danger: #e85d5d;
  --ok: #3ecf8e;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 50% -10%, #2a3d58 0%, transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color: var(--text);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
}

#app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 14px calc(12px + var(--safe-bottom));
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 8px 12px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(48px, 14vw, 72px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.home-actions {
  display: grid;
  gap: 12px;
  padding-bottom: 8px;
}

.diff-label {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.diff-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.install-tip {
  margin: 8px 4px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.install-tip strong {
  color: var(--text);
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  padding: 8px 12px;
  font-size: 22px;
  line-height: 1;
}

.btn.diff {
  min-height: 52px;
}

.btn.tool {
  padding: 12px 10px;
  font-size: 14px;
}

.btn.tool[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #cfe2ff;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta.right {
  text-align: right;
}

.meta strong {
  font-family: var(--font-display);
  font-size: 18px;
}

.meta span {
  color: var(--muted);
  font-size: 13px;
}

.board-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}

.board {
  width: min(100%, 92vw, 420px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--thick);
  border: 3px solid var(--thick);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  gap: 1px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: #1e2b3d;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--user);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(18px, 5.2vw, 26px);
  cursor: pointer;
  user-select: none;
}

.cell:nth-child(9n + 1),
.cell:nth-child(9n + 2),
.cell:nth-child(9n + 3),
.cell:nth-child(9n + 7),
.cell:nth-child(9n + 8),
.cell:nth-child(9n + 9) {
  /* visual rhythm via thick borders handled below */
}

.cell.block-r {
  box-shadow: inset -2px 0 0 var(--thick);
}

.cell.block-b {
  box-shadow: inset 0 -2px 0 var(--thick);
}

.cell.block-r.block-b {
  box-shadow: inset -2px 0 0 var(--thick), inset 0 -2px 0 var(--thick);
}

.cell.given {
  color: var(--given);
}

.cell.selected {
  background: #2b4570;
}

.cell.related {
  background: #243852;
}

.cell.same {
  background: #2f4a6e;
}

.cell.error {
  color: var(--danger);
  animation: flash 0.35s ease;
}

.cell.hinted {
  color: var(--ok);
}

.notes {
  position: absolute;
  inset: 3px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.notes span {
  display: grid;
  place-items: center;
  font-size: clamp(8px, 2.4vw, 11px);
  font-weight: 600;
  color: var(--note);
  line-height: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0 10px;
}

.pad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.pad button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  min-height: 48px;
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.pad button:active {
  background: var(--accent-soft);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}

.modal-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
}

.modal-card p {
  margin: 0;
  color: var(--muted);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

@keyframes flash {
  0% { background: rgba(232, 93, 93, 0.35); }
  100% { background: inherit; }
}

@media (min-width: 720px) {
  #app {
    padding-top: 24px;
  }

  .pad button {
    min-height: 54px;
  }
}
