/* Prime Cutter: a craft-desk palette. Cutting mat, white card, yellow cutter. */
:root {
  --mat: #1e5a45;
  --mat-deep: #164536;
  --mat-shade: #0d2e24;
  --line-minor: rgba(236, 232, 190, 0.07);
  --line-major: rgba(236, 232, 190, 0.16);
  --print: #ece8be;
  --print-dim: rgba(236, 232, 190, 0.62);
  --card: #fbfaf6;
  --card-edge: #d4ceb9;
  --hole: #184c3a;
  --handle: #ffc52e;
  --handle-deep: #c98f00;
  --ink: #10271e;
  --miss: #ff6450;

  --f-stencil: "Big Shoulders Stencil Display", Impact, "Arial Narrow", sans-serif;
  --f-ui: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;

  --spring: cubic-bezier(0.3, 1.5, 0.5, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background-color: var(--mat);
  background-image:
    linear-gradient(var(--line-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-major) 1px, transparent 1px),
    linear-gradient(var(--line-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-minor) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  background-position: center -1px;
  color: var(--print);
  font-family: var(--f-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* soft lamp over the desk */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 85% at 50% 32%, transparent 35%, rgba(4, 22, 16, 0.55) 100%);
}

button { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--handle); outline-offset: 3px; }

/* ---------- layout ---------- */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
  overflow: clip;
}

.top, .controls { width: min(100%, 520px); }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}

.brand {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-weight: 400;
}

.wordmark {
  font-family: var(--f-stencil);
  font-weight: 900;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--card);
}

.dayno {
  font-size: 14px;
  font-weight: 600;
  color: var(--print-dim);
  font-variant-numeric: tabular-nums;
}

.tools { display: flex; gap: 10px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 13px;
  background: var(--mat-deep);
  color: var(--print);
  box-shadow: inset 0 1px 0 rgba(236, 232, 190, 0.08), 0 4px 0 var(--mat-shade);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 70ms ease-out, box-shadow 70ms ease-out;
}
.icon-btn:active, .icon-btn.is-down {
  transform: translateY(4px);
  box-shadow: inset 0 1px 0 rgba(236, 232, 190, 0.08), 0 0 0 var(--mat-shade);
}
.icon-btn svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn .i-off { display: none; }
.icon-btn[aria-pressed="false"] .i-on { display: none; }
.icon-btn[aria-pressed="false"] .i-off { display: block; }
.icon-btn.help {
  font-family: var(--f-stencil);
  font-weight: 900;
  font-size: 24px;
  line-height: 1;
  padding-top: 2px;
}

/* ---------- lives: a snap-off cutter ---------- */
.knife {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  margin-top: 8px;
  filter: drop-shadow(0 4px 4px rgba(2, 18, 12, 0.35));
}
.knife-handle {
  position: relative;
  width: 70px;
  height: 26px;
  border-radius: 13px 5px 5px 13px;
  background: var(--handle);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), inset 0 -4px 0 var(--handle-deep);
}
.knife-handle::after {
  content: "";
  position: absolute;
  left: 12px; top: 7px;
  width: 34px; height: 10px;
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, rgba(16, 39, 30, 0.22) 0 2px, transparent 2px 6px);
}
.knife-blade { display: flex; margin-left: -1px; }
.seg {
  display: block;
  width: 30px;
  height: 17px;
  margin-left: -7px;
  background: linear-gradient(180deg, #f1f5f7 0%, #c3ccd1 45%, #8e9ba3 88%, #e9eef0 100%);
  clip-path: polygon(9px 0, 100% 0, calc(100% - 9px) 100%, 0 100%);
}
.seg:first-child { margin-left: 0; clip-path: polygon(0 0, 100% 0, calc(100% - 9px) 100%, 0 100%); }
.seg.gone { visibility: hidden; }

/* ---------- the number ---------- */
.stage {
  position: relative;
  z-index: 3;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 0 10px;
}

.slab-wrap {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}

.slab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1em 0.19em 0.07em;
  border-radius: 18px;
  background: var(--card);
  box-shadow:
    inset 0 1px 0 #fff,
    inset 0 -2px 0 rgba(16, 39, 30, 0.05),
    0 8px 0 var(--card-edge),
    0 9px 0 rgba(4, 22, 16, 0.2),
    0 30px 38px -12px rgba(3, 18, 12, 0.6);
  font-size: min(26.5vw, 19vh, 190px);
  font-size: min(26.5vw, 19dvh, 190px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  cursor: default;
  transition: background-color 0.45s ease, box-shadow 0.45s ease;
}

.digits {
  display: block;
  font-family: var(--f-stencil);
  font-weight: 900;
  line-height: 0.86;
  letter-spacing: 0.01em;
  color: var(--hole);
  font-variant-numeric: tabular-nums;
  transition: color 0.45s ease;
}

.slab.is-prime {
  background: var(--handle);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 -2px 0 rgba(16, 39, 30, 0.06),
    0 8px 0 var(--handle-deep),
    0 9px 0 rgba(4, 22, 16, 0.2),
    0 30px 38px -12px rgba(3, 18, 12, 0.6);
}
.slab.is-prime .digits { color: var(--ink); }

.slab.is-dead { background: #cdc8b6; transform: rotate(-2.5deg); }
.slab.is-dead .digits { color: #66786d; }

/* cut lines drawn by the blade */
.cutlines {
  position: absolute;
  top: -14px;
  bottom: -18px;
  left: 0;
  right: 0;
  pointer-events: none;
}
.cutlines i {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 6px 1px rgba(255, 255, 255, 0.9), 0 0 18px 4px rgba(255, 197, 46, 0.55);
  transform: scaleY(0);
  transform-origin: 50% 0;
}
.cutlines i.miss {
  background: var(--miss);
  box-shadow: 0 0 10px 2px rgba(255, 100, 80, 0.75);
}

/* the pieces after a cut */
.pieces { position: absolute; z-index: 20; pointer-events: none; }
.slab.piece {
  position: absolute;
  inset: 0;
  will-change: transform;
}
.pieces.many .slab.piece {
  box-shadow: 0 8px 0 var(--card-edge), 0 9px 0 rgba(4, 22, 16, 0.2);
}
.pieces .cutlines { animation: kerf 0.5s ease-out 0.1s forwards; }
@keyframes kerf { to { opacity: 0; } }

/* history of moves */
.trail {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  min-height: 32px;
  max-width: 100%;
  margin: 26px 0 0;
  padding: 0;
}
.trail li {
  font-family: var(--f-stencil);
  font-weight: 800;
  font-size: 21px;
  line-height: 1;
  padding: 6px 9px 4px;
  border-radius: 9px;
  background: var(--card);
  color: var(--hole);
  box-shadow: 0 3px 0 var(--card-edge);
}
.trail li.miss {
  background: transparent;
  color: var(--miss);
  box-shadow: inset 0 0 0 2px rgba(255, 100, 80, 0.75);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

/* ---------- controls ---------- */
.controls {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 6px;
}

.entry { display: flex; gap: 10px; align-items: stretch; }

.guess {
  width: 172px;
  height: 64px;
  border: 0;
  border-radius: 16px;
  padding: 4px 8px 0;
  background: var(--card);
  color: var(--hole);
  box-shadow: inset 0 3px 0 rgba(16, 39, 30, 0.08), 0 4px 0 var(--card-edge);
  font-family: var(--f-stencil);
  font-weight: 900;
  font-size: 46px;
  line-height: 1;
  text-align: center;
  caret-color: var(--handle-deep);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.guess::placeholder {
  font-family: var(--f-ui);
  font-weight: 500;
  font-size: 18px;
  color: rgba(24, 76, 58, 0.45);
}
.guess:focus-visible { box-shadow: inset 0 3px 0 rgba(16, 39, 30, 0.08), 0 4px 0 var(--card-edge), 0 0 0 3px var(--handle); }
.touch .guess { caret-color: transparent; }
html:not(.touch) .guess:focus::placeholder { color: transparent; }

/* desktop: keep knife, card and input together in the middle */
html:not(.touch) .knife { margin-top: auto; }
html:not(.touch) .stage { flex: 0 1 auto; padding: 36px 0 26px; }
html:not(.touch) .slab { font-size: min(26.5vw, 23dvh, 190px); }
html:not(.touch) .controls { margin-bottom: auto; padding-bottom: 5vh; }

.keycap {
  border: 0;
  border-radius: 16px;
  background: var(--handle);
  color: var(--ink);
  font-family: var(--f-ui);
  font-weight: 700;
  font-size: 20px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 5px 0 var(--handle-deep), 0 10px 14px -6px rgba(2, 18, 12, 0.5);
  transition: transform 70ms ease-out, box-shadow 70ms ease-out;
}
.keycap:active, .keycap.is-down {
  transform: translateY(4px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 1px 0 var(--handle-deep), 0 3px 5px -2px rgba(2, 18, 12, 0.5);
}
.cut-btn { height: 64px; padding: 0 28px; }

.see-result { display: none; height: 58px; padding: 0 30px; }
.finished .entry, .finished .pad { display: none; }
.finished .see-result { display: inline-block; }

.msg {
  margin: 0;
  min-height: 1.45em;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.45;
  text-align: center;
  text-wrap: balance;
  color: var(--print);
}
.msg[data-tone="bad"] { color: #ffb2a6; }
.msg[data-tone="good"] { color: var(--handle); }

/* on-screen keys, touch only */
.pad {
  display: none;
  width: 100%;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}
.touch .pad { display: grid; }
.touch .entry .cut-btn { display: none; }

.pad button {
  height: clamp(44px, 7.4dvh, 60px);
  border: 0;
  border-radius: 14px;
  background: var(--card);
  color: var(--hole);
  font-family: var(--f-stencil);
  font-weight: 800;
  font-size: 30px;
  line-height: 1;
  padding-top: 3px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 1px 0 #fff, 0 4px 0 var(--card-edge), 0 8px 12px -6px rgba(2, 18, 12, 0.5);
  transition: transform 60ms ease-out, box-shadow 60ms ease-out;
}
.pad button.is-down {
  transform: translateY(4px);
  box-shadow: inset 0 1px 0 #fff, 0 0 0 var(--card-edge), 0 2px 4px -2px rgba(2, 18, 12, 0.5);
}
.pad .pad-del {
  background: var(--mat-deep);
  color: var(--print);
  box-shadow: inset 0 1px 0 rgba(236, 232, 190, 0.08), 0 4px 0 var(--mat-shade), 0 8px 12px -6px rgba(2, 18, 12, 0.5);
  display: grid;
  place-items: center;
  padding-top: 0;
}
.pad .pad-del.is-down { box-shadow: inset 0 1px 0 rgba(236, 232, 190, 0.08), 0 0 0 var(--mat-shade); }
.pad .pad-del svg {
  width: 28px; height: 28px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.pad .pad-cut {
  background: var(--handle);
  color: var(--ink);
  font-family: var(--f-ui);
  font-weight: 700;
  font-size: 20px;
  padding-top: 0;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 4px 0 var(--handle-deep), 0 8px 12px -6px rgba(2, 18, 12, 0.5);
}
.pad .pad-cut.is-down { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 0 0 var(--handle-deep); }
.touch .finished .pad { display: none; }

/* ---------- flying guess chip, scraps, flash, toast ---------- */
.fly-chip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  pointer-events: none;
  padding: 7px 11px 5px;
  border-radius: 10px;
  background: var(--handle);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--handle-deep), 0 10px 16px -6px rgba(2, 18, 12, 0.5);
  font-family: var(--f-stencil);
  font-weight: 900;
  font-size: 28px;
  line-height: 1;
  white-space: nowrap;
}
.fly-chip.bad { background: var(--miss); color: #fff; box-shadow: 0 4px 0 #b8382a; }

.scrap {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  border-radius: 1px;
}

.flash {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 120px 20px rgba(255, 90, 70, 0.55);
}

.toast {
  position: fixed;
  left: 50%;
  top: env(safe-area-inset-top, 0px);
  z-index: 70;
  transform: translate(-50%, -130%);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 4px 0 var(--card-edge), 0 14px 24px -8px rgba(2, 18, 12, 0.5);
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(5, 24, 17, 0.58);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: min(100%, 460px);
  max-height: 92dvh;
  overflow: auto;
  padding: 28px 22px calc(22px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 -12px 40px rgba(2, 18, 12, 0.35);
}
@media (min-width: 620px) and (min-height: 620px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet {
    border-radius: 26px;
    padding-bottom: 24px;
    box-shadow: 0 8px 0 var(--card-edge), 0 34px 60px -10px rgba(2, 18, 12, 0.6);
  }
}

.sheet h2 {
  margin: 0 0 10px;
  font-family: var(--f-stencil);
  font-weight: 900;
  font-size: 54px;
  line-height: 0.92;
  letter-spacing: 0.005em;
  color: var(--ink);
}
.sheet p { margin: 0 0 12px; font-size: 17px; line-height: 1.45; }

.rules {
  list-style: none;
  display: grid;
  gap: 12px;
  margin: 16px 0 18px;
  padding: 0;
}
.rules li {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 14px;
  font-size: 17px;
  line-height: 1.42;
}
.mark {
  width: 18px;
  height: 18px;
  margin-top: 3px;
  border-radius: 5px;
  background: var(--card-edge);
}
.mark.hit { background: var(--mat); }
.mark.miss { background: var(--miss); }
.mark.prime { background: var(--handle); }

.example {
  padding: 13px 15px;
  border-radius: 14px;
  background: #f0ede2;
  box-shadow: inset 0 0 0 1.5px rgba(16, 39, 30, 0.08);
}
.fine { color: rgba(16, 39, 30, 0.65); font-size: 15px !important; }

.equation {
  font-family: var(--f-stencil);
  font-weight: 800;
  font-size: 30px !important;
  line-height: 1.1 !important;
  color: var(--hole);
  margin-top: 4px !important;
}
.equation sup { font-size: 0.55em; vertical-align: 0.75em; line-height: 0; }

.moves { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 20px; }
.moves i {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--mat);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}
.moves i.miss { background: var(--miss); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 0 20px;
  padding: 14px 0;
  border-top: 2px dashed rgba(16, 39, 30, 0.16);
  border-bottom: 2px dashed rgba(16, 39, 30, 0.16);
}
.stats div { display: flex; flex-direction: column-reverse; align-items: center; }
.stats dd {
  margin: 0;
  font-family: var(--f-stencil);
  font-weight: 900;
  font-size: 36px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stats dt { margin-top: 4px; font-size: 13px; font-weight: 600; color: rgba(16, 39, 30, 0.62); }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .keycap { flex: 1; height: 58px; font-size: 18px; }
.ghost {
  height: 58px;
  padding: 0 22px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(16, 39, 30, 0.18);
  touch-action: manipulation;
}
.ghost:active { background: rgba(16, 39, 30, 0.06); }

.next {
  margin: 18px 0 0 !important;
  text-align: center;
  font-size: 15px !important;
  color: rgba(16, 39, 30, 0.66);
}
#countdown { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

.noscript { text-align: center; padding: 40px 16px; }

/* short screens: tighten the stack */
@media (max-height: 640px) {
  .top { min-height: 44px; }
  .wordmark { font-size: 26px; }
  .knife { margin-top: 2px; transform: scale(0.85); }
  .stage { padding: 8px 0 4px; }
  .trail { margin-top: 18px; }
  .controls { gap: 9px; }
  .guess, .cut-btn { height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .slab, .digits, .keycap, .icon-btn, .pad button { transition: none; }
}
