/* Side B — twilight sky, a unicorn in the corner, a pearl puzzle card. */

:root {
  --bg: #241e3a;
  --bg-2: #2e2749;
  --shell: #342c52;
  --shell-edge: #4b4073;
  --paper: #fcf9fd;
  --paper-shade: #f1eaf7;
  --paper-same: #fbe2ee;
  --line: #d3c7e0;
  --line-bold: #5b4b7d;
  --amber: #4f2a74;          /* given digits: deep plum ink on pearl */
  --amber-bright: #f4b8d8;   /* soft pink accent on the night sky */
  --cream: #f3edf8;          /* text on the night sky */
  --ink: #1d6b8a;            /* player digits on pearl: teal-blue */
  --note: #8a7fa0;
  --magenta: #c2508b;
  --magenta-soft: #f8dbea;
  --red: #c23b22;
  --red-soft: #f6d9cf;
  --muted-text: #ada2c6;
  --rainbow: linear-gradient(135deg, #f6a8cf, #c7a6f2 35%, #9fd3f0 70%, #a8e8cf);

  --ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --label: "Avenir Next", Avenir, -apple-system, "Helvetica Neue", sans-serif;
  --script: "Snell Roundhand", "Apple Chancery", "Brush Script MT", cursive;

  --board: min(calc(100dvh - 196px), calc(100vw - 480px), 640px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: relative;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(ellipse 60% 45% at 12% 0%, rgba(246, 168, 207, 0.20) 0%, transparent 70%),
    radial-gradient(ellipse 55% 50% at 92% 18%, rgba(159, 211, 240, 0.16) 0%, transparent 70%),
    radial-gradient(ellipse 70% 50% at 70% 100%, rgba(199, 166, 242, 0.22) 0%, transparent 70%),
    linear-gradient(180deg, #2a2245 0%, var(--bg) 100%);
  background-attachment: fixed;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--amber-bright); outline-offset: 2px; }

/* ---------- Sky ---------- */

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: #fff4fb;
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}

.big-unicorn {
  position: fixed;
  right: max(-40px, -3vw);
  bottom: 0;
  width: min(40vw, 44vh, 460px);
  height: min(40vw, 44vh, 460px);
  opacity: 0.32;
  pointer-events: none;
  z-index: 0;
}

.top, .deck { position: relative; z-index: 1; }

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto 12px;
}

.station { display: flex; align-items: center; gap: 10px; }

.title-unicorn { width: 40px; height: 40px; flex: none; }

.title {
  margin: 0;
  font-family: var(--script);
  font-weight: 700;
  font-size: 36px;
  line-height: 1.1;
  color: var(--cream);
}

/* ---------- Layout ---------- */

.deck {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 28px;
  max-width: 1180px;
  margin: 0 auto;
}

/* ---------- Puzzle card (rainbow-edged) ---------- */

.cassette {
  position: relative;
  flex: none;
  padding: 14px 20px 20px;
  border-radius: 22px;
  border: 2px solid transparent;
  background:
    linear-gradient(180deg, #3a3160 0%, var(--shell) 100%) padding-box,
    var(--rainbow) border-box;
  box-shadow: 0 14px 34px rgba(10, 6, 30, 0.45), 0 0 40px rgba(199, 166, 242, 0.12);
}

.label-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 34px;
  margin: 0 6px 12px;
  padding: 0 12px 0 8px;
  border-radius: 17px;
  background: #f6f0fa;
  color: #4f2a74;
  font-family: var(--label);
}
.label-side {
  width: 28px;
  height: 28px;
  flex: none;
  --uni-coat: #ffffff;
}
.label-lines {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--rainbow);
  opacity: 0.8;
}
.label-level { font-size: 16px; font-weight: 600; letter-spacing: 0.03em; }

.window {
  padding: 8px;
  border-radius: 12px;
  background: #1d1832;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.cassette.solved { box-shadow: 0 14px 34px rgba(10, 6, 30, 0.45), 0 0 0 3px rgba(246, 168, 207, 0.35), 0 0 60px rgba(246, 168, 207, 0.35); }
.cassette.solved .label-strip { background: var(--magenta-soft); }

/* ---------- Board ---------- */

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: max(var(--board), 450px);
  height: max(var(--board), 450px);
  background: var(--paper);
  border: 2px solid var(--line-bold);
  border-radius: 3px;
  overflow: hidden;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  font-size: calc(max(var(--board), 450px) / 9 * 0.56);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink);
  transition: background-color 120ms ease;
}
.cell.c8 { border-right: 0; }
.cell.r8 { border-bottom: 0; }
.cell.bx { border-right: 2px solid var(--line-bold); }
.cell.by { border-bottom: 2px solid var(--line-bold); }

.cell.given { color: var(--amber); font-weight: 600; }
.cell.player { font-weight: 400; }

.cell.peer { background: var(--paper-shade); }
.cell.same { background: var(--paper-same); }
.cell.selected { background: var(--magenta-soft); }
.cell.selected::after {
  content: "";
  position: absolute; inset: 1px;
  border: 2px solid var(--magenta);
  border-radius: 2px;
  pointer-events: none;
}

.cell.conflict { color: var(--red); background: var(--red-soft); }
.cell.conflict.selected { background: #f0cbc4; }
.cell.given.conflict { background: var(--paper); color: var(--amber); text-decoration: underline wavy var(--red) 1px; text-underline-offset: 4px; }
.cell.given.conflict.peer { background: var(--paper-shade); }

.cell.pointed::before {
  content: "";
  position: absolute; inset: 3px;
  border-radius: 50%;
  border: 2px solid var(--magenta);
  animation: point 2.6s ease-out forwards;
  pointer-events: none;
}
@keyframes point {
  0% { opacity: 0; transform: scale(1.25); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0.0; }
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px 3px;
  font-size: calc(max(var(--board), 450px) / 9 * 0.24);
  color: var(--note);
  font-weight: 400;
}
.notes span { display: grid; place-items: center; }
.notes span.hot { color: var(--amber); font-weight: 600; }

/* ---------- Desk (controls) ---------- */

.desk {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 360px;
  flex: none;
}

.howto {
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--paper);
  color: #3a2f55;
  font-size: 17px;
  line-height: 1.45;
}
.howto h2 { margin: 0 0 6px; font-family: var(--label); font-weight: 600; font-size: 20px; }
.howto ul { margin: 0 0 8px; padding-left: 20px; }
.howto p { margin: 0 0 8px; }
.howto .btn.quiet { margin-top: 4px; background: #ece2f4; color: #3a2f55; border-color: #d8c9e6; }

.status {
  min-height: 24px;
  margin: 0;
  font-size: 17px;
  color: var(--amber-bright);
  transition: opacity 400ms ease;
}
.status.fade { opacity: 0; }
.status.done { color: #f7c9e0; }

.btn {
  min-height: 52px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--shell-edge);
  background: var(--shell);
  font-size: 17px;
}
.btn:active { background: #40366a; }
.btn:disabled { color: #6d6390; border-color: #3d3463; cursor: default; }

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.digit {
  height: 68px;
  border-radius: 12px;
  border: 1px solid var(--shell-edge);
  background: var(--bg-2);
  color: var(--cream);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}
.digit:active { background: #3a3160; }
.digit.used { color: #6d6390; }
.pad.notes-on .digit { color: var(--note); font-size: 24px; border-style: dashed; }
.pad.notes-on .digit.used { color: #5d5480; }

.tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.tool { font-size: 16px; }
.tool .state { color: var(--muted-text); font-size: 14px; margin-left: 2px; }
#notes[aria-pressed="true"] { border-color: var(--amber-bright); color: #fbe4f0; }
#notes[aria-pressed="true"] .state { color: var(--amber-bright); }

.newgame { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; border-top: 1px solid #3a3160; }
.newgame-label { font-size: 14px; color: var(--muted-text); letter-spacing: 0.04em; padding-top: 10px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.level.confirm { border-color: var(--amber-bright); color: var(--amber-bright); font-size: 14px; line-height: 1.15; }

/* ---------- Narrow screens / portrait ---------- */

@media (max-width: 900px) {
  :root { --board: min(calc(100vw - 80px), calc(100dvh - 490px), 640px); }
  .deck { flex-direction: column; align-items: center; }
  .big-unicorn { opacity: 0.2; }
  .desk { width: min(100%, calc(max(var(--board), 450px) + 44px)); }
  .pad { grid-template-columns: repeat(9, 1fr); gap: 6px; }
  .digit { height: 56px; font-size: 24px; }
  .tools { grid-template-columns: repeat(6, 1fr); }
  .tool { font-size: 14px; padding: 0 6px; }
}

@media (max-width: 540px) {
  :root { --board: calc(100vw - 72px); }
  .board { width: var(--board); height: var(--board); }
  .cell { font-size: calc(var(--board) / 9 * 0.56); }
  .notes { font-size: calc(var(--board) / 9 * 0.24); }
  .tools { grid-template-columns: repeat(3, 1fr); }
  .pad { grid-template-columns: repeat(5, 1fr); }
  .title { font-size: 24px; }
  .title-unicorn { width: 32px; height: 32px; }
  .big-unicorn { opacity: 0.22; }
}

@media (prefers-reduced-motion: reduce) {
  .cell.pointed::before { animation: none; }
  .cell { transition: none; }
}
