:root {
  --bg: #f1ebdf; --card: #fbf7ef; --ink: #1d1b18; --dim: #6e675d; --line: #dcd2c1; --accent: #8a4b2a;
  --dark: #121110; --dtext: #f3eee4; --ddim: rgba(243,238,228,.68); --glass: rgba(18,17,15,.6); --dline: rgba(239,232,218,.22);
  --paper: #efe4cf;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #171614; --card: #201e1b; --ink: #f1ece2; --dim: #a39b8e; --line: #34302b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--dark); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* camera */
#cam { position: fixed; inset: 0; background: #000; color: var(--dtext); overflow: hidden; }
#camBox { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#video, #live, #liveNext { position: absolute; inset: 0; width: 100%; height: 100%; }
#live, #liveNext { background: var(--paper); transition: opacity .45s; }
#camBox:not(.live) #live, #camBox:not(.live) #liveNext { display: none; }
#camMsg { position: absolute; left: 20px; right: 20px; top: 40%; text-align: center; color: var(--ddim); }
.top { position: fixed; top: calc(var(--safe-t) + 10px); left: 12px; right: 12px; display: flex; justify-content: space-between; }
.pill { padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--glass); border: 1px solid var(--dline); color: var(--dtext); }
.pill.on { background: var(--dtext); color: var(--dark); }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 30px 0 calc(var(--safe-b) + 14px); background: linear-gradient(to top, rgba(0,0,0,.8), transparent); }
.hands { display: flex; gap: 8px; overflow-x: auto; padding: 0 12px 12px; scrollbar-width: none; }
.hands::-webkit-scrollbar { display: none; }
.hand { flex: none; width: 92px; padding: 6px; border-radius: 12px; background: var(--glass); border: 1px solid var(--dline); text-align: left; color: var(--dtext); }
.hand canvas { width: 100%; height: 30px; display: block; border-radius: 6px; }
.hand b { display: block; font-size: 12.5px; margin-top: 4px; }
.hand small { display: block; font-size: 10.5px; color: var(--ddim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hand.on { border-color: var(--dtext); box-shadow: 0 0 0 1px var(--dtext); }
.hands.light .hand { background: var(--card); border-color: var(--line); color: var(--ink); }
.hands.light .hand small { color: var(--dim); }
.hands.light .hand.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.shootRow { display: flex; align-items: center; justify-content: space-between; padding: 0 22px; }
.side { width: 80px; font-size: 12.5px; color: var(--ddim); text-align: center; cursor: pointer; }
#shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--dtext); display: grid; place-items: center; }
#shutter span { width: 56px; height: 56px; border-radius: 50%; background: var(--dtext); transition: transform .1s; }
#shutter:active span { transform: scale(.88); }

/* pages */
.screen.page { min-height: 100%; background: var(--bg); padding: calc(var(--safe-t) + 6px) 14px calc(var(--safe-b) + 24px); }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 0 12px; }
.bar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 28px; line-height: 1; padding: 0 8px 4px 0; color: var(--accent); }
#sheet { background: var(--paper); border-radius: 6px; padding: 5%; box-shadow: 0 1px 2px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.12);
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#art { position: relative; }
#ink, #kept { display: block; width: 100%; }
#photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#status { font-size: 13px; color: var(--dim); margin: 10px 0 8px; min-height: 18px; }
.marks { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--dim); margin: 2px 0 10px; }
.marks input { flex: 1; accent-color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 6px; }
.btn { padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.on { background: var(--ink); color: var(--bg); border-color: transparent; }
.btn.danger { color: #c2412d; }
.btn:disabled { opacity: .45; }
.hint { font-size: 12px; color: var(--dim); margin: 4px 0 12px; }
#makeCtl .hands { padding: 0 0 10px; }

#receipt { border-top: 1px solid var(--line); padding-top: 12px; }
#receipt h3 { margin: 0 0 2px; font-size: 14px; }
#receipt .sub { margin: 0 0 10px; font-size: 12.5px; color: var(--dim); }
.src { display: flex; gap: 10px; align-items: center; margin: 0 0 8px; }
.src img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--line); flex: none; }
.src .t { font-size: 13px; font-weight: 600; line-height: 1.25; }
.src .m { font-size: 11.5px; color: var(--dim); }
.src .p { margin-left: auto; font-weight: 700; font-size: 13px; white-space: nowrap; }
details summary { font-size: 12.5px; color: var(--accent); font-weight: 600; cursor: pointer; margin: 4px 0 8px; }
.rule { font-size: 11.5px; color: var(--dim); margin: 10px 0 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { padding: 0; text-align: left; border-radius: 10px; overflow: hidden; background: var(--card); border: 1px solid var(--line); }
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.tile div { padding: 6px 8px 8px; font-size: 12px; color: var(--dim); }
.tile b { display: block; color: var(--ink); font-size: 12.5px; }
.empty { color: var(--dim); text-align: center; margin-top: 40px; }

#toast { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 150px); max-width: min(92vw, 420px);
  padding: 10px 14px; border-radius: 12px; background: rgba(20,19,16,.92); color: #f3eee4; font-size: 14px; text-align: center; }
#bestFor { margin: 0 14px 8px; font-size: 12.5px; color: var(--ddim); text-shadow: 0 1px 3px #000; }
#bestHint { display: block; color: var(--ink); margin-bottom: 2px; }
#bestHint:empty { display: none; }
.bookTools { margin-top: 18px; }
.note { font-size: 13px; color: var(--dim); background: var(--card); border: 1px solid #c98a3a; border-radius: 10px; padding: 10px 12px; margin: 16px 0 0; }
