:root {
  --bg: #0e1220;
  --panel: #161b2e;
  --panel-2: #1d2440;
  --line: #2b3458;
  --text: #e6e8f2;
  --muted: #8d94b3;
  --accent: #f4c24e;
  --small: #3fd4ff;
  --hidden: #262e4d;
  --floor: #11152a;
  --cell: min(56px, calc((100vw - 48px) / 11));
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header { padding: 18px 24px 4px; }
h1 { margin: 0; font-size: 22px; letter-spacing: .02em; }
.sub { margin: 2px 0 0; color: var(--muted); }

main {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 16px 24px 32px;
  align-items: flex-start;
}

.board-wrap { flex: 0 0 auto; }

.board-head { display: flex; gap: 12px; margin-bottom: 12px; width: calc(var(--cell) * 11 + 20px); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; min-width: 0; }
.stat.grow { flex: 1; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.big-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
#status { font-size: 13px; padding-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.board {
  display: grid;
  grid-template-columns: repeat(11, var(--cell));
  grid-auto-rows: var(--cell);
  gap: 2px;
  padding: 8px;
  background: radial-gradient(circle at 50% 45%, #2a3470 0%, #161b36 70%);
  border-radius: 28px;
  width: max-content;
  user-select: none;
}

.cell {
  position: relative;
  border-radius: 5px;
  background: var(--hidden);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * .24);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, .92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  overflow: hidden;
}
.cell.off { visibility: hidden; }
.cell.hidden { cursor: pointer; }
.cell.hidden:hover { outline: 2px solid #fff; outline-offset: -2px; z-index: 2; }
.cell.hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .75); }
.cell.floor { background: var(--floor); }
.cell.piece { border-radius: 2px; }
.cell.piece.partial { opacity: .72; background-image: repeating-linear-gradient(135deg, rgba(0,0,0,.18) 0 4px, transparent 4px 8px); }
.cell.is-best::after {
  content: "";
  position: absolute;
  inset: 1px;
  border: 3px solid #fff;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #0b0d18, inset 0 0 0 2px #0b0d18, 0 0 14px rgba(255, 255, 255, .8);
}
.cell.is-best::before {
  content: "★";
  position: absolute;
  top: 4px;
  right: 6px;
  z-index: 1;
  font-size: 12px;
  line-height: 12px;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 2px #000;
}
.cell.is-best-small::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 3px solid var(--small);
  border-radius: 6px;
  box-shadow: 0 0 12px var(--small);
  animation: pulse 1.1s ease-in-out infinite;
}
.cell.is-best-small::before {
  content: "1×1";
  position: absolute;
  top: 3px;
  left: 4px;
  z-index: 1;
  font-size: 9px;
  line-height: 12px;
  padding: 0 3px;
  border-radius: 3px;
  background: var(--small);
  color: #04202b;
  text-shadow: none;
}
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .cell.is-best-small::after { animation: none; } }

.board-stack { position: relative; width: max-content; }
.overlay { position: absolute; inset: 0; pointer-events: none; }
.outline {
  position: absolute;
  border: 3px solid var(--c);
  border-radius: 7px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), 0 0 12px var(--c);
}
.outline.done { border-width: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .4); }
/* Peeked (hidden) pieces look like found ones: see .outline. */
.outline.mine {
  border: 3px solid #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 2px #0b0d18, inset 0 0 0 2px #0b0d18, 0 0 12px rgba(255, 255, 255, .6);
}
.outline.mine .chip { background: #fff; }
.outline .chip {
  position: absolute;
  top: -10px;
  left: 6px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--c);
  color: #10131f;
  white-space: nowrap;
}

.cell.coarse { color: rgba(255, 255, 255, .5); font-weight: 500; }
.cell.peek { color: rgba(255, 255, 255, .55); font-weight: 500; }
.cell .tag { font-size: calc(var(--cell) * .2); line-height: 1.05; text-align: center; padding: 1px; }
.cell.done .tag::after { content: " ✓"; }

.best { margin-top: 12px; min-height: 42px; color: var(--muted); width: calc(var(--cell) * 11 + 20px); }
.best strong { color: var(--accent); }
.best.small-alert { color: var(--text); background: rgba(63, 212, 255, .1); border: 1px solid var(--small); border-radius: 10px; padding: 8px 12px; }
.best.small-alert strong { color: var(--small); }
.alert-tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 0 5px; margin-right: 4px; border-radius: 4px; background: var(--small); color: #04202b; }
.best .alts { font-size: 12px; }

.legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); width: calc(var(--cell) * 11 + 20px); }
.ramp { width: 120px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #1f2a4c, #583f81, #a84e77, #dc8152, #eed06f); }
.legend-note { flex-basis: 100%; }

.panel { flex: 1 1 280px; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.group { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
h2 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }

button, select, input[type=number] {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: #4a578f; }
button.link { background: none; border: none; color: var(--muted); padding: 6px 0 0; text-decoration: underline; }
kbd { font: 10px ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; margin-left: 4px; }

.seg { display: flex; margin-bottom: 10px; }
.seg button { flex: 1; border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button + button { border-left: none; }
.seg button.on { background: var(--accent); color: #1a1500; border-color: var(--accent); font-weight: 600; }
.seg button.on kbd, button.primary kbd { color: #5a4a10; border-color: #b8922e; }

button.run { display: block; width: 100%; margin-top: 2px; padding: 12px; font-size: 16px; font-weight: 700; }
button.run kbd { vertical-align: 2px; }
.check + .buttons { margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.values { display: grid; grid-template-columns: 1fr 90px; gap: 6px 10px; align-items: center; }
.values label { display: flex; align-items: center; gap: 8px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.values input { width: 90px; text-align: right; }

.collected { margin: 0; padding: 0; list-style: none; }
.collected li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid var(--line); }
.collected li:last-child { border-bottom: none; }
.collected .neg { color: #ff8a8a; }
.muted { color: var(--muted); }

@media (max-width: 720px) {
  header, main { padding-left: 16px; padding-right: 16px; }
  .panel { max-width: none; }
}

/* Solve progress, in the empty top-right corner of the board. */
.progress {
  position: absolute;
  top: 10px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  pointer-events: none;
}
.progress .ring {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .15);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.progress.done .ring {
  animation: none;
  border-color: #4cc38a;
  display: grid;
  place-items: center;
  color: #4cc38a;
  font-size: 14px;
  line-height: 1;
}
.progress.done { color: #4cc38a; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .progress .ring { animation-duration: 2.4s; } }

/* Practice mode */
.small-note { font-size: 12px; margin: 6px 0 0; }
button.primary { background: var(--accent); color: #1a1500; border-color: var(--accent); font-weight: 600; }
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(5, 7, 15, .45); }
dialog h3 { margin: 0 0 4px; font-size: 20px; }
dialog .buttons { margin-top: 16px; justify-content: flex-end; }
.rating { display: inline-flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 800; color: var(--r); }
.rating .sym {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border-radius: 17px;
  background: var(--r);
  color: #10131f;
  font-size: 16px;
}
.grade-line { margin: 10px 0 0; color: var(--muted); }
.grade-line strong { color: var(--text); }
#report { width: min(520px, calc(100vw - 32px)); }
.nowrap { white-space: nowrap; }
.report-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; font-variant-numeric: tabular-nums; }
.report-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 4px 6px; }
.report-table td { padding: 5px 6px; border-top: 1px solid var(--line); }
.report-table td.num { text-align: right; }
.report-table .r { font-weight: 700; color: var(--r); }
.report-total { display: flex; gap: 12px; margin-top: 12px; }
.report-total .stat { flex: 1; }

/* Live mode */
.live { width: calc(var(--cell) * 11 + 20px); margin-top: 12px; display: flex; flex-direction: column; gap: 10px; user-select: none; }
.live[hidden], .live [hidden] { display: none; }
.live-hint { margin: 0; color: var(--muted); }
.live-hint strong { color: var(--text); }
.live-hint.bad { color: #ff8a8a; }
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.pal-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.pal-item:hover { border-color: #4a578f; }
.pal-item.empty { opacity: .35; cursor: not-allowed; }
.pal-shape { display: grid; grid-auto-rows: 12px; gap: 1px; min-height: 38px; align-content: center; }
.pal-shape span { width: 12px; height: 12px; border-radius: 2px; }
.pal-label { font-size: 11px; font-weight: 600; white-space: nowrap; }
.pal-left { color: var(--muted); font-weight: 500; margin-left: 4px; font-variant-numeric: tabular-nums; }
.board.placing .cell.hidden { cursor: default; }
.board.placing .cell.hidden:hover { outline: none; }
.board .cell.grab { cursor: grab; touch-action: none; }
.cell.fresh { background: #1b2140; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }
.cell.drop-ok { box-shadow: inset 0 0 0 3px #4cc38a !important; }
.cell.drop-bad { box-shadow: inset 0 0 0 3px #ef5b5b !important; }
body.dragging, body.dragging * { cursor: grabbing !important; }
.drag-ghost {
  position: fixed;
  z-index: 50;
  display: grid;
  gap: 2px;
  opacity: .75;
  pointer-events: none;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .6));
}
.drag-ghost div { border-radius: 3px; }
.drag-ghost.bad { opacity: .45; }
.ghost-tag {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}
