:root {
  --bg: #ece6da; --card: #faf7f0; --ink: #1d1b18; --dim: #6e675d; --line: #d8cfbf; --accent: #2f4a5c; --accent-ink: #fff;
  --paper: #f7f4ec; --dark: #121110; --dtext: #f3eee4; --glass: rgba(18,17,15,.62); --dline: rgba(239,232,218,.25);
  --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: #191816; --card: #23211e; --ink: #f1ece2; --dim: #a39b8e; --line: #3a352f; --accent: #8fb3c9; --accent-ink: #10181d; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.screen { min-height: 100%; padding: calc(var(--safe-t) + 6px) 14px calc(var(--safe-b) + 24px); max-width: 1100px; margin: 0 auto; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 0 12px; }
.bar h1 { flex: 1; margin: 0; font-size: 20px; 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); }
.btn { padding: 8px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: #c2412d; }
.btn.on { background: var(--ink); color: var(--bg); border-color: transparent; }
.btn.wide { width: 100%; justify-content: center; padding: 13px; margin-top: 16px; }
.btn:disabled, .icon:disabled { opacity: .35; }
.icon { font-size: 20px; padding: 4px 8px; color: var(--ink); }
.link { color: var(--accent); font-weight: 600; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.sub { color: var(--dim); font-size: 13px; margin: 6px 0; }
.lbl { font-size: 13px; color: var(--dim); font-weight: 600; margin: 14px 0 6px; }
.field { display: grid; gap: 5px; font-size: 13px; color: var(--dim); font-weight: 600; margin: 8px 0; }
.field input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 16px; color: var(--ink); }
.note { font-size: 13px; color: var(--dim); background: var(--card); border: 1px solid #c98a3a; border-radius: 10px; padding: 10px 12px; }
.empty { color: var(--dim); text-align: center; margin: 40px 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.chips button.on { background: var(--ink); color: var(--bg); border-color: transparent; font-weight: 600; }

/* pages drawn as sheets of frames */
.sheet { position: relative; width: 100%; background: var(--paper); border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.14), 0 6px 20px rgba(0,0,0,.08); container-type: inline-size; }
.sheet .cell { position: absolute; padding: 0; background: #fff; border: 1px solid rgba(29,27,24,.22); overflow: hidden; display: grid; place-items: center; }
.sheet .cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet .cell.empty { background: rgba(255,255,255,.55); border-style: dashed; }
.sheet .cell span { color: #b9b0a1; font-size: 6cqw; }
.sheet .cap { position: absolute; overflow: hidden; font-size: clamp(9px, 1.7cqw, 14px); line-height: 1.2; color: #1d1b18; }
.sheet .cap b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .cap span { display: block; color: #6e675d; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .ptitle { position: absolute; left: 2.5%; font: 600 clamp(12px, 3cqw, 26px) Georgia, serif; color: #1d1b18; }
#pgSheet { margin: 4px 0 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { padding: 10px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: left; display: grid; gap: 8px; }
.card .meta b { display: block; } .card .meta span { color: var(--dim); font-size: 13px; }
.homeTools { margin-top: 20px; }

/* new page */
.tpls { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.tpl { padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); display: grid; gap: 6px; font-size: 12.5px; text-align: center; }
.tpl.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); font-weight: 600; }
.tplPic { position: relative; background: var(--paper); border-radius: 3px; }
.tplPic i { position: absolute; background: #c9c0b0; }

/* the frame editor: full height; on a wide screen the layers sit beside the stage */
.screen.tool { position: fixed; inset: 0; max-width: none; display: flex; flex-direction: column; padding-bottom: calc(var(--safe-b) + 8px); }
#fMain { flex: 1; min-height: 0; display: flex; gap: 14px; }
#fLeft { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
#fStageBox { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; }
#fStage, #fGuide { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#fGuide { pointer-events: none; }
.pill.fit { position: absolute; right: 8px; top: 8px; z-index: 3; }
#fStage { background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.2); touch-action: none; display: block; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#fBusy { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; background: rgba(0,0,0,.25); color: #fff; font-weight: 600; }
#fTools, #fAdd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--card); }
.seg button { padding: 6px 11px; border-radius: 999px; font-size: 13.5px; color: var(--dim); }
.seg button.on { background: var(--ink); color: var(--bg); font-weight: 600; }
#fSize { width: 110px; accent-color: var(--accent); }
#fColours { display: flex; gap: 5px; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
.sw.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
#fColour { width: 30px; height: 28px; border: 0; padding: 0; background: none; }
#fSide { width: 320px; flex: none; overflow-y: auto; padding: 4px 2px 20px; }
.sideHead { display: flex; align-items: center; gap: 8px; margin: 12px 0 6px; } .sideHead b { flex: 1; } .sideHead .sub { margin: 0; }
.closeSide { display: none; }
.layer { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.layer.sel { background: var(--card); border-color: var(--line); }
.layer.off { opacity: .5; }
.layer canvas { width: 44px; border-radius: 4px; border: 1px solid var(--line); }
.layer .lname { flex: 1; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eye { font-size: 16px; width: 26px; color: var(--ink); }
.rng { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--dim); margin: 8px 0; }
.rng input[type=range] { flex: 1; accent-color: var(--accent); }
.rng select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.rng.short { margin: 0; }
.mini { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; } .mini .btn { padding: 6px 10px; font-size: 13px; }
.tints { display: flex; flex-wrap: wrap; gap: 6px; }
.tint { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 12.5px; }
.tint i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); }
.tint.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.panelBtn { display: none; }
@media (max-width: 899px) {
  .panelBtn { display: inline-flex; }
  #fSide { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 72vh; background: var(--bg); border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; padding: 4px 14px calc(var(--safe-b) + 20px); box-shadow: 0 -8px 30px rgba(0,0,0,.25); transform: translateY(105%); transition: transform .22s; z-index: 20; }
  #fSide.open { transform: none; }
  .closeSide { display: inline-block; }
  #fSize { width: 80px; }
}
.sheetOverlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; align-items: end; justify-items: center; z-index: 30; }
.sheetBox { width: min(560px, 100%); background: var(--bg); border-radius: 16px 16px 0 0; padding: 4px 16px calc(var(--safe-b) + 18px); }
.row { display: flex; width: 100%; justify-content: space-between; align-items: center; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); margin: 0 0 8px; }
.row span { color: var(--dim); font-size: 13px; }

/* camera and crop */
.screen.dark { position: fixed; inset: 0; max-width: none; padding: 0; background: #000; color: var(--dtext); }
#camVideo, #camGuide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#camGuide { pointer-events: none; }
#camMsg { position: absolute; left: 20px; right: 20px; top: 40%; text-align: center; color: rgba(255,255,255,.7); }
#camFlash { position: absolute; inset: 0; background: #fff; opacity: .6; pointer-events: none; }
.camTop { position: fixed; top: calc(var(--safe-t) + 10px); left: 12px; right: 12px; display: flex; justify-content: space-between; gap: 8px; z-index: 2; }
.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); }
.pill.go { background: #e9a23b; color: #1a1206; border-color: transparent; }
.camBottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 24px 0 calc(var(--safe-b) + 16px); background: linear-gradient(to top, rgba(0,0,0,.8), transparent); }
#camExtra { display: flex; justify-content: center; margin-bottom: 12px; }
#camExtra select { padding: 7px 10px; border-radius: 10px; background: var(--glass); color: var(--dtext); border: 1px solid var(--dline); font-size: 14px; }
.shootRow { display: flex; align-items: center; justify-content: space-between; padding: 0 22px; }
.side { width: 80px; font-size: 12.5px; color: rgba(255,255,255,.7); text-align: center; cursor: pointer; }
#camShutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--dtext); display: grid; place-items: center; }
#camShutter span { width: 56px; height: 56px; border-radius: 50%; background: var(--dtext); transition: transform .1s; }
#camShutter:active span { transform: scale(.88); }
#cropStage { position: absolute; top: calc(var(--safe-t) + 56px); bottom: calc(var(--safe-b) + 76px); left: 10px; right: 10px; display: grid; place-items: center; }
#cropCanvas { touch-action: none; }
.cropBar { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 18px); display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }

#toast { position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 120px); max-width: min(92vw, 440px);
  padding: 10px 14px; border-radius: 12px; background: rgba(20,19,16,.92); color: #f3eee4; font-size: 14px; text-align: center; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#fGuides { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 13px; }

/* arrange */
.arrBar { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px 2px; margin: 0 0 10px; }
.arrBar .actions { margin: 6px 0; }
.sheet .cell.picked { outline: 3px solid var(--accent); outline-offset: 2px; }
.sheet .cell .holdMark { position: absolute; left: 4px; top: 4px; padding: 1px 6px; border-radius: 6px; background: #1d1b18; color: #f3eee4; font-size: 10px; font-weight: 700; }
/* critique */
#crBody h2 { font-size: 16px; margin: 22px 0 6px; }
.habits { margin: 4px 0 6px; padding-left: 20px; } .habits li { margin: 3px 0; }
.readings { display: grid; gap: 10px; }
.rd { display: flex; gap: 12px; padding: 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.rd.fav { border-color: #c98a3a; box-shadow: 0 0 0 1px #c98a3a; }
.rd img { width: 86px; height: 86px; object-fit: cover; border-radius: 6px; flex: none; background: var(--line); }
.rdh { display: flex; align-items: center; gap: 8px; } .rdh b { flex: 1; }
.star { font-size: 22px; color: #c98a3a; padding: 0 4px; }
.holdTag { padding: 1px 7px; border-radius: 6px; background: var(--ink); color: var(--bg); font-size: 11px; font-weight: 700; }
.q { font-size: 13px; margin: 2px 0 6px; } .q.none { color: var(--dim); font-style: italic; }
.chipsR { display: flex; flex-wrap: wrap; gap: 5px; } .chipsR span { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.hold { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0 0 10px; } .hold p { margin: 6px 0; font-size: 14px; }
.holdForm textarea, .holdForm select { padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 15px; color: var(--ink); font-family: inherit; }
.capTest { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; align-items: center; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 20px); gap: 10px; }
.ctTop { width: 100%; display: flex; justify-content: space-between; } .ctTop .pill { background: var(--card); color: var(--ink); border-color: var(--line); }
#ctImg { flex: 1; min-height: 0; max-width: 100%; object-fit: contain; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.ctQ { font-weight: 600; margin: 4px 0 0; } .actions.center { justify-content: center; }
#ctCaption { color: var(--dim); margin: 0; }
.pill.peek { position: absolute; left: 8px; bottom: 8px; z-index: 3; background: rgba(18,17,15,.55); }
#fValues { display: flex; height: 16px; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); font-size: 10px; font-weight: 600; line-height: 16px; flex: none; }
#fValues div { text-align: center; white-space: nowrap; overflow: hidden; }
.galExtra { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: min(520px, 92vw); }
.galExtra select, .galExtra input { padding: 8px 10px; border-radius: 10px; background: var(--glass); color: var(--dtext); border: 1px solid var(--dline); font-size: 15px; }
.galExtra select { grid-column: 1 / -1; }
.galExtra input:disabled { opacity: .5; }
.galExtra input::placeholder { color: rgba(243,238,228,.55); }

/* master's hand */
.sheetBox.tall { max-height: 82vh; overflow-y: auto; }
.row.hand { text-align: left; gap: 10px; } .row.hand div { flex: 1; } .row.hand b { display: block; } .row.hand div span { display: block; font-size: 12.5px; margin-top: 2px; }
.row.hand .n { flex: none; font-size: 12px; }
.row.handRow { border-style: dashed; }
.receipt { font-size: 12.5px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.receipt b { display: block; margin-bottom: 2px; } .receipt > span { color: var(--dim); display: block; margin-bottom: 4px; }
.receipt div { margin: 2px 0; } .receipt i { font-style: normal; font-weight: 700; display: inline-block; min-width: 34px; } .receipt em { color: var(--dim); font-style: normal; }
