/* Guhit Story mode: same sunny desk as Draw (tokens and .ib/.tool/.sw buttons come from index.html).
   Wide (tablet landscape, PC): tools left, the frame in the middle, scenes on the right, the timeline strip under the frame.
   Narrow (tablet portrait, phones): the frame on top, then colours, the timeline, the tools; scenes in a sheet. */
#storyView { grid-template-columns: 92px minmax(0, 1fr) 270px; grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "sbar sbar sbar" "stools sstage spanel" "stools sdock spanel" "stools tline spanel"; }
.sbar { grid-area: sbar; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 2px solid var(--line); background: var(--panel); min-width: 0; }
.sbar .ib { min-height: 44px; }
.sbar .stitle { border: 0; background: none; font: 900 18px var(--font); color: var(--ink); display: flex; align-items: center; gap: 6px; min-width: 0; padding: 4px 6px; border-radius: 12px; }
.sbar .stitle span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sbar .stitle svg.i { width: 18px; height: 18px; color: var(--muted); }
.sbar .sscene { min-width: 0; flex: 0 1 auto; }
.sbar .sscene span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.stools { grid-area: stools; display: flex; flex-direction: column; gap: 6px; padding: 10px 8px; overflow-y: auto; overflow-x: hidden; border-right: 2px solid var(--line); background: var(--panel); }
.stools .tool { min-height: 60px; }
.stools .tool[data-st="add"] { background: var(--sun); border-color: #E9BE19; }
.sstage { grid-area: sstage; position: relative; background: var(--desk); overflow: hidden; min-height: 0; }
.sstage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.slayer { position: absolute; left: 10px; top: 10px; z-index: 2; border: 2px solid var(--line); background: rgba(255,255,255,.94); border-radius: 999px; padding: 6px 12px; min-height: 44px;
  font: 800 14px var(--font); color: var(--ink); display: flex; gap: 6px; align-items: center; max-width: calc(100% - 20px); }
.slayer.bg { border-color: var(--mint); background: #E3FAF6; }
.slayer svg.i { width: 18px; height: 18px; }
.sfno { position: absolute; right: 10px; top: 10px; z-index: 2; background: rgba(43,45,66,.78); color: #fff; border-radius: 999px; padding: 4px 10px; font: 800 13px var(--font); pointer-events: none; }
.itembar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 3; display: flex; gap: 4px; padding: 5px; background: #fff; border: 2px solid var(--ink);
  border-radius: 18px; box-shadow: 0 6px 18px rgba(0,0,0,.18); max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none; }
.itembar::-webkit-scrollbar { display: none; }
.itembar button { border: 0; background: var(--paper); border-radius: 12px; min-width: 48px; min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font: 800 11px var(--font); color: var(--ink); padding: 2px 6px; flex: none; }
.itembar button svg.i { width: 20px; height: 20px; }
.itembar button.del { color: var(--coral-d); }
.sdock { grid-area: sdock; display: flex; align-items: center; gap: 8px 14px; padding: 6px 12px; border-top: 2px solid var(--line); background: var(--panel); flex-wrap: wrap; min-width: 0; }
.sdock .dockA { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sdock .size input { width: 120px; }
.onion { display: flex; align-items: center; gap: 6px; }
.onion .ib[aria-pressed="true"] { background: #FFE3E3; border-color: var(--coral); }
.onion input { width: 90px; }
.sdock .pal .sw { width: 32px; height: 32px; }
@media (min-width: 900px) { .sdock { flex-wrap: nowrap; } .sdock .pal { flex: 1; flex-wrap: nowrap; overflow-x: auto; min-width: 0; padding: 4px; scrollbar-width: thin; } }
.sdock .picker { width: 32px; height: 32px; }
.tline { grid-area: tline; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center; padding: 6px 10px; border-top: 2px solid var(--line); background: var(--panel); min-width: 0; }
.tacts { display: grid; grid-template-columns: repeat(3, 44px); gap: 4px; }
.tacts .ib { padding: 0; min-width: 44px; }
.tacts .ib.hold { font: 900 14px var(--font); }
.strip { list-style: none; margin: 0; padding: 4px 2px 6px; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; min-width: 0; scroll-behavior: smooth; }
.strip li { flex: none; position: relative; }
.fcard { position: relative; border: 3px solid var(--line); background: #fff; border-radius: 12px; padding: 0; width: 112px; height: 84px; display: block; overflow: hidden; }
.fcard canvas { width: 100%; height: 100%; display: block; }
.fcard.on { border-color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.fcard .fn { position: absolute; left: 4px; top: 4px; background: rgba(43,45,66,.8); color: #fff; border-radius: 8px; padding: 0 6px; font: 800 12px/18px var(--font); }
.fcard .fh { position: absolute; right: 4px; top: 4px; background: var(--sun); color: var(--ink); border-radius: 8px; padding: 0 6px; font: 900 12px/18px var(--font); }
.grip { position: absolute; left: 50%; bottom: -2px; transform: translateX(-50%); width: 56px; height: 24px; border-radius: 10px 10px 0 0; border: 0; background: var(--ink); color: #fff;
  touch-action: none; display: grid; place-items: center; cursor: grab; }
.grip svg.i { width: 18px; height: 18px; }
.fadd { width: 84px; height: 84px; border: 3px dashed #D9C9A6; background: var(--paper); border-radius: 12px; display: grid; place-items: center; color: var(--ink); font: 800 12px var(--font); }
.fadd svg.i { width: 30px; height: 30px; }
.strip li.drop::before { content: ""; position: absolute; left: -6px; top: 0; bottom: 0; width: 4px; border-radius: 2px; background: var(--coral); }
.strip li.dropR::after { content: ""; position: absolute; right: -6px; top: 0; bottom: 0; width: 4px; border-radius: 2px; background: var(--coral); }
.ghost { position: fixed; z-index: 70; pointer-events: none; opacity: .85; transform: rotate(-4deg); box-shadow: 0 10px 30px rgba(0,0,0,.25); border-radius: 12px; }

.spanel { grid-area: spanel; border-left: 2px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.spanel h3 { margin: 0; font: 900 18px var(--font); display: flex; align-items: center; gap: 6px; }
.spanel h4 { margin: 0 0 6px; font: 900 15px var(--font); }
.spsec { padding: 10px 12px; border-bottom: 2px solid var(--line); }
.scl { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sci { display: flex; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 14px; background: #fff; padding: 4px; }
.sci.on { border-color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.sci .go { flex: 1; min-width: 0; border: 0; background: none; display: flex; align-items: center; gap: 8px; text-align: left; font: 800 14px var(--font); color: var(--ink); min-height: 48px; padding: 0 2px; }
.sci .go span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.sci .go small { display: block; color: var(--muted); font-weight: 700; font-size: 12px; }
.sci canvas, .sci .pg { width: 56px; height: 42px; border-radius: 8px; border: 1px solid var(--line); flex: none; background: #fff; }
.sci .pg { display: grid; place-items: center; font: 900 11px var(--font); color: #fff; text-align: center; line-height: 1.05; padding: 2px; overflow: hidden; }
.sci .mini { border: 0; background: var(--paper); border-radius: 10px; width: 40px; height: 44px; display: grid; place-items: center; color: var(--ink); flex: none; }
.sci .mini svg.i { width: 18px; height: 18px; }
.sci .mini:disabled { opacity: .3; }
.addscene { margin-top: 8px; width: 100%; justify-content: center; }
.bgs2 { display: flex; flex-wrap: wrap; gap: 6px; }
.bgs2 .sw { width: 34px; height: 34px; }
.rec { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rec .ib.on { background: var(--coral); color: #fff; border-color: var(--coral-d); }
.rec small, .spnote { color: var(--muted); font-weight: 700; font-size: 13px; display: block; margin-top: 6px; }
.fps { display: flex; align-items: center; gap: 8px; }
.fps input { flex: 1; min-width: 0; }
.fps b { min-width: 28px; text-align: right; }

/* the add sheet, text editor, player, comic, stories list */
.addgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.addgrid button { border: 2px solid var(--line); background: #fff; border-radius: 16px; min-height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font: 800 13px var(--font); color: var(--ink); padding: 6px; }
.addgrid button svg.i { width: 32px; height: 32px; }
.addgrid canvas { width: 64px; height: 64px; }
.modal h4 { margin: 14px 0 6px; font: 900 16px var(--font); }
.tarea { width: 100%; min-height: 96px; border: 3px solid var(--line); border-radius: 14px; padding: 10px 12px; font: 800 20px var(--font); background: #fff; resize: vertical; user-select: text; -webkit-user-select: text; }
.tarea:focus { outline: none; border-color: var(--blue); }
.fontchips .chip2 { min-height: 48px; font-size: 18px; }
.cswatches { display: flex; flex-wrap: wrap; gap: 6px; }
.cswatches .sw { width: 34px; height: 34px; }
.player { display: flex; flex-direction: column; gap: 10px; }
.player canvas { width: 100%; max-height: 62vh; aspect-ratio: 4 / 3; object-fit: contain; background: #000; border-radius: 16px; display: block; }
.pctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pctl .ib { min-height: 52px; }
.pbar { flex: 1 1 120px; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; min-width: 80px; }
.pbar i { display: block; height: 100%; width: 0; background: var(--coral); }
.pages { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; max-height: 52vh; overflow: auto; padding: 8px; background: var(--desk); border-radius: 16px; }
.pages img { width: 200px; height: auto; background: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.18); border-radius: 4px; }
.pages img.land { width: 280px; }
.tut { text-align: center; }
.tut .big { width: 84px; height: 84px; border-radius: 50%; background: var(--sun); display: grid; place-items: center; margin: 4px auto 10px; }
.tut .big svg.i { width: 46px; height: 46px; }
.tut h3 { margin: 0 0 6px; font: 900 22px var(--font); color: var(--coral); }
.tut p { margin: 0 auto; max-width: 420px; font-size: 17px; }
.dots { display: flex; justify-content: center; gap: 8px; margin: 14px 0 0; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--coral); width: 26px; border-radius: 5px; }
.busy2 { position: fixed; inset: 0; z-index: 65; display: grid; place-items: center; background: rgba(255,248,236,.82); font: 900 22px var(--font); color: var(--coral); text-align: center; padding: 20px; }
.busy2 div { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.busy2 i { width: 54px; height: 54px; border-radius: 50%; background: var(--sun); animation: puff .8s ease-in-out infinite alternate; }
.busy2 small { color: var(--ink); font-size: 15px; }
#printRoot { display: none; }

body[data-mode="story"] #docName, body[data-mode="story"] #galBtn, body[data-mode="story"] #moreBtn, body[data-mode="story"] .dOnly { display: none !important; }

@media (max-width: 1100px) { #storyView { grid-template-columns: 88px minmax(0, 1fr) 240px; } }
@media (max-width: 899px) {
  #storyView { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto auto; grid-template-areas: "sbar" "sstage" "sdock" "tline" "stools"; }
  .sbar { padding: 6px 8px; gap: 6px; }
  .stools { flex-direction: row; border-right: 0; border-top: 2px solid var(--line); overflow-x: auto; overflow-y: hidden; padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); gap: 4px; }
  .stools .tool { flex: 1 0 52px; min-height: 58px; font-size: 12px; }
  .sdock { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 6px; padding: 6px 8px; }
  .sdock .dockA { justify-content: space-between; }
  .sdock .size { flex: 1; min-width: 0; } .sdock .size input { flex: 1; width: auto; min-width: 0; }
  .sdock .pal { flex-wrap: nowrap; overflow-x: auto; padding: 4px 4px 6px; scrollbar-width: none; }
  .tline { grid-template-columns: minmax(0, 1fr); padding: 4px 8px; gap: 4px; }
  .tacts { grid-template-columns: repeat(6, 44px); justify-content: center; }
  .fcard { width: 92px; height: 69px; }
  .fadd { width: 69px; height: 69px; }
  .spanel { position: fixed; left: 0; right: 0; bottom: 0; max-height: 78%; z-index: 30; border: 0; border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.25);
    transform: translateY(105%); transition: transform .22s ease; padding-bottom: env(safe-area-inset-bottom); visibility: hidden; }
  .spanel.open { transform: none; visibility: visible; }
}
@media (max-width: 520px) {
  .sbar .lbl { display: none; }
  .sbar .ib { padding: 0 8px; }
  .sbar .sscene span { max-width: 96px; }
  .onion input { width: 64px; }
  .sdock .size > span:first-child { display: none; }
}
@media (max-width: 440px) {
  .seg button svg.i { display: none; }
  .seg button { padding: 0 10px; }
}
@media (max-width: 999px) and (max-height: 540px) and (orientation: landscape) {
  #storyView { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: "sbar sbar" "stools sstage" "stools sdock" "stools tline"; }
  .stools { flex-direction: column; border-top: 0; border-right: 2px solid var(--line); overflow-y: auto; overflow-x: hidden; width: 76px; }
  .stools .tool { flex: none; min-height: 50px; }
  .sdock { flex-direction: row; align-items: center; }
  .tline { grid-template-columns: auto minmax(0, 1fr); }
  .tacts { grid-template-columns: repeat(3, 40px); }
  .fcard { width: 72px; height: 54px; } .fadd { width: 54px; height: 54px; }
}

/* print: only the comic pages, one per sheet (the page size is set when Print is tapped) */
@media print {
  html, body { position: static !important; height: auto !important; overflow: visible !important; background: #fff !important; }
  #app, .mback, .toast, .sheetback, .busy2, .ghost { display: none !important; }
  #printRoot { display: block !important; }
  #printRoot .pp { break-after: page; page-break-after: always; overflow: hidden; }
  #printRoot .pp:last-child { break-after: auto; page-break-after: auto; }
  #printRoot img { width: 100%; height: 100%; display: block; }
}
