/* Coloring Book. A paper-colored book with a dark violet header. The menu is
   one card: the picture you picked, tabs under it, then the shelves. While
   coloring, the tools run along the top and the colors along the bottom, and
   the page fills what is between them. */
:root {
  /* R-C40: colours that were written out in rules, as tokens (theme-derive.py) */
  --kBg1: #4d4073;
  --kBg10: #fdd835;
  --kBg11: #43a047;
  --kBg12: #29b6f6;
  --kBg13: #7e57c2;
  --kBg14: rgba(34, 32, 43, .35);
  --kBg2: #5d4f88;
  --kBg3: #ffffff;
  --kBg4: #f7f3ea;
  --kBg5: rgba(255, 255, 255, .85);
  --kBg6: #faf7f0;
  --kBg7: #dcd6c9;
  --kBg8: rgba(255, 253, 248, .92);
  --kBg9: #e53935;
  --kInk1: #ffffff;

  --bg: #f3efe6;
  --ink: #22202b;
  --dim: #5f5a6b;
  --card: #fffdf8;
  --line: #d9d2c3;
  --head: #3b2f5c;
  --hot: #6b4fbf;
  --hot-ink: #ffffff;
  --soft: #ece6f7;
}

/* R-C40: the dark look. This product's own is light; the other is chosen with the switch beside Home. */
:root[data-theme="dark"] {
  /* the header bar is dark in both looks, as are its pills and their white text */
  --kBg1: #4d4073;
  --kBg10: #fdd835;
  --kBg11: #43a047;
  --kBg12: #29b6f6;
  --kBg13: #7e57c2;
  --kBg14: rgba(232, 230, 245, .35);
  --kBg2: #5d4f88;
  --kBg3: #0d0d0d;
  --kBg4: #18150f;
  --kBg5: rgba(13, 13, 13, .85);
  --kBg6: #14120e;
  --kBg7: #2e2a20;
  --kBg8: rgba(16, 14, 11, .92);
  --kBg9: #d94b43;
  --kInk1: #ffffff;

  --bg: #191610;
  --ink: #e8e6f5;
  --dim: #9f99ac;
  --card: #0e0d0a;
  --line: #312c20;
  --head: #3b2f5c;
  --hot: #6b4fbf;
  --hot-ink: #ffffff;
  --soft: #1d1824;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
}
#app { display: flex; flex-direction: column; height: 100%; -webkit-touch-callout: none; }

#hdr {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px;
  background: var(--head); color: var(--kInk1); position: relative; z-index: 5;
}
#hdrTitle { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 700; font-size: 15px; }
@media (max-width: 380px) { #hdrTitle { visibility: hidden; } }
/* R-C26: [hidden] loses to any display of our own */
[hidden] { display: none !important; }
.pill { min-width: 44px; min-height: 44px; border: 0; border-radius: 12px; background: var(--kBg1); color: var(--kInk1); font-size: 18px; cursor: pointer; }
.pill:active { background: var(--kBg2); }

#main { position: relative; flex: 1; min-height: 0; }
.scr { display: none; position: absolute; inset: 0; overflow-y: auto; padding: 10px; }
.scr.on { display: block; }
#scr-how > * { max-width: 640px; margin-left: auto; margin-right: auto; }

/* ---- the menu ------------------------------------------------------------------------- */
#menuCard, .upCard { max-width: 560px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 10px 12px 12px; }
h1 { font-size: 28px; margin: 2px 0 6px; }
.upCard h2 { font-size: 22px; margin: 2px 0 6px; }
.stat { color: var(--dim); font-size: 13px; margin: 6px 2px 0; }
.big { display: block; width: 100%; min-height: 52px; margin: 8px 0; border: 1px solid var(--line); border-radius: 14px;
       background: var(--soft); color: var(--ink); font-size: 17px; font-weight: 600; cursor: pointer; }
.big.primary { background: var(--hot); border-color: var(--hot); color: var(--hot-ink); }
.big:disabled { opacity: .45; cursor: default; }
#prevBox, #upBox { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 6px 0 4px; }
#prev, #upPrev { width: min(62vw, 240px); height: auto; aspect-ratio: 3 / 4; background: var(--kBg3); border: 1px solid var(--line); border-radius: 8px; }
#prevName, #upNote { font-size: 14px; color: var(--dim); text-align: center; min-height: 18px; }
.tabRow { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 6px 0; }
.tabRow.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tab { min-height: 46px; min-width: 0; padding: 4px 2px; border-radius: 12px; border: 2px solid transparent; background: var(--soft); color: var(--dim);
       font-size: 14px; font-weight: 700; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; }
.tab small { font-weight: 500; font-size: 11px; }
.tab.sel { border-color: var(--hot); color: var(--ink); background: var(--kBg3); }
.shelfRow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 10px 0 6px; }
.shelf { min-height: 50px; min-width: 0; border-radius: 12px; border: 2px solid transparent; background: var(--soft); color: var(--ink); cursor: pointer;
         display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; gap: 1px; padding: 2px; }
.shelf .te { font-size: 20px; }
.shelf.sel { border-color: var(--hot); background: var(--kBg3); }
.pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.pic { position: relative; min-height: 76px; min-width: 0; border-radius: 12px; border: 2px solid transparent; background: var(--kBg4); color: var(--ink); cursor: pointer;
       display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; font-size: 12px; }
.pic .te { font-size: 28px; }
.pic img { pointer-events: none; -webkit-touch-callout: none; width: 60px; height: 80px; object-fit: cover; border-radius: 4px; background: var(--kBg3); border: 1px solid var(--line); }
.pic small { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pic.sel { border-color: var(--hot); background: var(--kBg3); }
.pic .del { position: absolute; top: 2px; right: 2px; min-width: 44px; min-height: 44px; border: 0; border-radius: 10px; background: var(--kBg5);
            font-size: 16px; cursor: pointer; overflow: hidden; }
#delBar { position: sticky; bottom: 8px; max-width: 560px; margin: 8px auto 0; display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px;
          background: var(--head); color: var(--kInk1); border-radius: 14px; font-size: 15px; }
#delBar span { flex: 1; min-width: 0; }
#delBar .big { width: auto; margin: 0; padding: 0 16px; min-height: 48px; }
#delAsk .setNote { margin: 14px 0 0; }
.empty { grid-column: 1 / -1; color: var(--dim); font-size: 14px; padding: 8px 2px; }

#custom { margin: 8px 0 0; border: 1px solid var(--line); border-radius: 14px; background: var(--kBg6); }
#custom > summary { list-style: none; }
#custom > summary::-webkit-details-marker { display: none; }
#custom > summary::after { content: "▾"; margin-left: auto; color: var(--dim); }
#custom[open] > summary::after { content: "▴"; }
summary { min-height: 48px; display: flex; align-items: center; padding: 0 12px; cursor: pointer; font-weight: 600; }
.setBody { padding: 4px 12px 12px; }
.setRow { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.setLbl { flex: 1 1 120px; font-size: 14px; }
.setNote { color: var(--dim); font-size: 12px; line-height: 1.4; }
.knob { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.knobBtn { min-height: 44px; min-width: 56px; border-radius: 10px; border: 1px solid var(--line); background: var(--kBg3); color: var(--dim); font-size: 13px; cursor: pointer; }
.knobBtn.on { color: var(--ink); border: 2px solid var(--hot); font-weight: 700; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 8px 0; font-size: 14px; line-height: 1.5; }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.filePick { position: relative; display: flex; align-items: center; justify-content: center; }
.filePick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* ---- coloring ---------------------------------------------------------------------------- */
#scr-play { padding: 0; overflow: hidden; }
#scr-play.on { display: flex; flex-direction: column; }
#bar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 6px 4px; background: var(--card); border-bottom: 1px solid var(--line); }
.tool { min-width: 44px; min-height: 44px; border-radius: 12px; border: 2px solid transparent; background: var(--soft); color: var(--ink); font-size: 20px; cursor: pointer; padding: 0 6px; }
.tool:disabled { opacity: .35; cursor: default; }
.tool.sel { border-color: var(--hot); background: var(--kBg3); }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; background: var(--kBg7); }
#cvs, #marks { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#marks { pointer-events: none; }
#progress { position: absolute; left: 8px; top: 8px; padding: 4px 10px; border-radius: 12px; background: var(--kBg8); font-size: 13px; font-weight: 600; pointer-events: none; }
#progress:empty { display: none; }
#glFail { position: absolute; inset: 20% 10% auto; padding: 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: 14px; line-height: 1.5; }
#tray { background: var(--card); border-top: 1px solid var(--line); padding: 4px 6px calc(env(safe-area-inset-bottom, 0px) + 6px); }
.trayRow { display: flex; gap: 4px; align-items: center; margin: 2px 0; }
.trayRow.wrap { flex-wrap: wrap; }
.trayRow .gap { flex: 1; }
.medium, .setBtn { min-width: 44px; min-height: 44px; border-radius: 12px; border: 2px solid transparent; background: var(--soft); font-size: 13px; cursor: pointer; padding: 2px 8px; color: var(--ink); }
.medium.sel, .setBtn.sel { border-color: var(--hot); background: var(--kBg3); font-weight: 700; }
#swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; max-height: 148px; overflow-y: auto; padding: 2px; }
.sw { position: relative; min-height: 44px; min-width: 44px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .18); cursor: pointer; padding: 0;
      font-size: 13px; font-weight: 800; color: var(--ink); }
.sw.light { color: var(--ink); }
.sw.dark { color: var(--kInk1); }
.sw.sel { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--hot); }
.sw.done::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.sw .left { position: absolute; right: -2px; bottom: -4px; font-size: 10px; background: var(--kBg3); color: var(--ink); border-radius: 8px; padding: 0 3px; border: 1px solid var(--line); }
.sw.pick { background: conic-gradient(var(--kBg9), var(--kBg10), var(--kBg11), var(--kBg12), var(--kBg13), var(--kBg9)); }
.sw.pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; overflow-y: auto; background: var(--kBg14); padding: 12px; z-index: 10; }
.ovl.on { display: flex; }
.ovl.see { background: transparent; pointer-events: none; }
.ovl.see .ovlCard { pointer-events: auto; margin-top: auto; margin-bottom: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: center; }
.ovl.see .ovlCard h2, .ovl.see .ovlCard p { grid-column: 1 / -1; }
.ovl.see .big { margin: 0; min-height: 48px; font-size: 15px; }
.ovl.see .big.primary { grid-column: 1 / -1; }
.ovlCard { width: min(420px, 100%); margin: auto; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 16px; text-align: center; }
.ovlCard.small { width: auto; }
.ovlCard h2 { margin: 4px 0 6px; font-size: 24px; }
.ovlCard p { color: var(--dim); font-size: 15px; line-height: 1.45; margin: 6px 0; }
.toast { background: var(--head); color: var(--kInk1); padding: 8px 14px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.toast-host { position: fixed; left: 0; right: 0; bottom: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 40; }
@media (max-height: 480px) {
  #prev, #upPrev { width: 120px; }
  h1 { font-size: 22px; }
  #swatches { max-height: 96px; }
  .ovlCard .big { display: inline-block; width: calc(50% - 8px); min-height: 46px; margin: 4px 2px; font-size: 15px; }
}
