:root {
  --bg: #15111b;
  --bg-soft: #1e1826;
  --card: #241d2e;
  --line: #372c45;
  --ink: #f6f1ef;
  --ink-dim: #b3a7bd;
  --accent: #ff5c7a;
  --accent-ink: #2a0b13;
  --ok: #5ad1a5;
  --warn: #ffb020;
  --radius: 18px;
  --bar-h: 84px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% 0%, #2a1f36 0%, transparent 60%),
    var(--bg);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
}

.topbar { text-align: center; padding: 10px 0 14px; }
.topbar h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 800;
}
.topbar p { margin: 6px 0 0; color: var(--ink-dim); font-size: 14px; }

/* ---------------------------------------------------------------- preview */

.stage { display: flex; flex-direction: column; align-items: center; }

.paper-shadow {
  position: relative;
  padding: 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff10, #ffffff05);
  box-shadow: 0 18px 40px -18px #000, 0 0 0 1px var(--line);
}

#preview {
  display: block;
  max-width: min(78vw, 300px);
  max-height: 46vh;
  width: auto;
  height: auto;
  border-radius: 4px;
  background: #fff;
}

.paper-note { color: var(--ink-dim); font-size: 12px; margin: 10px 0 2px; letter-spacing: 0.08em; text-transform: uppercase; }

/* ---------------------------------------------------------------- panels */

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: 0.12em; }
.sub { margin: 16px 0 8px; font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }
.hint { color: var(--ink-dim); font-size: 13px; line-height: 1.45; margin: 12px 0 0; }

.pill {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: #ffffff12;
  color: var(--ink);
}
.pill.quiet { background: transparent; border: 1px solid var(--line); color: var(--ink-dim); font-weight: 500; }
.pill.good { background: #5ad1a520; color: var(--ok); }
.pill.bad { background: #ff5c7a20; color: var(--accent); }

/* ---------------------------------------------------------------- slots */

.pick { margin-top: 16px; }
.hint.problem { color: var(--accent); }

/* The one button lives on top of the print itself, so there is never an empty
   grid sitting next to a button asking to fill it. */
.pick-overlay {
  position: absolute;
  inset: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-radius: 4px;
  background: #15111ba6;
  backdrop-filter: blur(1.5px);
  transition: background 0.18s ease;
}
.btn-pick {
  max-width: 100%;
  padding: 15px 22px;
  font-size: 16px;
  white-space: nowrap;
  box-shadow: 0 8px 22px -10px #000c;
}

/* Once the print is full, get out of the way of it. */
.pick-overlay.compact {
  align-items: flex-end;
  justify-content: center;
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}
.pick-overlay.compact .btn-pick {
  pointer-events: auto;
  padding: 9px 15px;
  font-size: 13px;
  border-radius: 999px;
  background: #15111bd9;
  color: var(--ink);
  backdrop-filter: blur(6px);
}

.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }

.slot {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: var(--bg-soft);
  color: var(--ink-dim);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  opacity: 0.7;
  -webkit-tap-highlight-color: transparent;
}
.slot.filled { opacity: 1; }
.slot canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot:disabled { cursor: default; font-size: 13px; font-weight: 700; opacity: 0.45; }
.slot.filled { border-style: solid; border-color: transparent; }
.slot .num {
  position: absolute;
  left: 5px;
  top: 4px;
  font-size: 10px;
  font-weight: 800;
  background: #00000090;
  color: #fff;
  border-radius: 6px;
  padding: 2px 5px;
}

/* ------------------------------------------------------- forms (host page) */

.text-input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  padding: 13px 14px;
  font-size: 16px;
  font-family: inherit;
}
.text-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  border: 0;
  border-radius: 14px;
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: #ffffff12; color: var(--ink); }
.btn-ghost.danger { color: var(--accent); }
.btn-add { width: 100%; margin-top: 14px; background: #ffffff12; color: var(--ink); }
.btn-icon { font-weight: 800; }
.wide { width: 100%; margin-top: 12px; }

.version {
  text-align: center;
  color: var(--ink-dim);
  opacity: 0.5;
  font-size: 11px;
  letter-spacing: 0.08em;
  margin: 20px 0 0;
}

.spacer { height: calc(var(--bar-h) + env(safe-area-inset-bottom) + 20px); }

.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #15111b00, #15111be6 22%, var(--bg) 60%);
  backdrop-filter: blur(8px);
}
.actionbar .btn-primary { flex: 1; }
.actionbar .btn-ghost { flex: 0 0 96px; }

/* ---------------------------------------------------------------- sheet */

.sheet, .overlay {
  position: fixed;
  inset: 0;
  background: #0b0810cc;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  backdrop-filter: blur(6px);
}
.overlay { align-items: center; padding: 20px; }
.hidden { display: none !important; }

.sheet-card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line);
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh;
  overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 16px; text-transform: uppercase; letter-spacing: 0.1em; }
.icon-btn { border: 0; background: #ffffff12; color: var(--ink); width: 36px; height: 36px; border-radius: 50%; font-size: 16px; cursor: pointer; }

.crop-wrap { display: flex; flex-direction: column; align-items: center; margin: 14px 0 6px; }
#cropCanvas {
  max-width: min(74vw, 320px);
  max-height: 44dvh;
  border-radius: 10px;
  background: #000;
  touch-action: none;
  cursor: grab;
}
.crop-hint { color: var(--ink-dim); font-size: 12px; margin: 10px 0 0; }

.slider { width: 100%; margin: 10px 0 14px; accent-color: var(--accent); height: 30px; }

.sheet-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.sheet-actions .btn { flex: 1; padding: 13px 8px; font-size: 14px; }

/* ---------------------------------------------------------------- result */

.save-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px 20px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.save-card h2 { margin: 0 0 6px; font-size: 20px; }
.save-how { margin: 0 0 16px; color: var(--ink-dim); font-size: 14px; line-height: 1.5; }
.save-how strong { color: var(--ink); }
.save-image {
  display: block;
  width: 100%;
  max-width: 260px;
  margin: 0 auto 20px;
  border-radius: 8px;
  box-shadow: 0 12px 30px -14px #000;
  /* let the OS offer its image context menu, and never hijack the long press */
  -webkit-touch-callout: default;
  touch-action: manipulation;
  user-select: none;
}

.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 26px 20px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.result-emoji { font-size: 44px; }
.result-card h2 { margin: 10px 0 6px; font-size: 21px; }
.result-card p { margin: 0; color: var(--ink-dim); font-size: 15px; line-height: 1.5; }
.result-image { max-width: 150px; margin: 16px auto 0; display: block; border-radius: 6px; box-shadow: 0 10px 24px -12px #000; }
.result-actions { display: flex; gap: 10px; margin-top: 22px; }
.result-actions .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  background: #000000d9;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 40;
  max-width: 88vw;
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 0.18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
}
