
:root {
  --bg-top: #f4ead9;
  --bg-top2: #e9dcc4;
  --bench: #cdb48f;
  --bench2: #bfa47c;
  --paper: #fffaf0;
  --ink: #3b2a1a;
  --muted: #7a6650;
  --line: #d9c6a5;
  --accent: #d0661c;
  --accent-soft: #ffcf8a;
  --ui: system-ui, -apple-system, "Hiragino Sans", "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  color-scheme: light;
}
html, body { height: 100%; }
body { margin: 0; background: var(--bg-top); color: var(--ink); font-family: var(--ui); overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; color: inherit; }
.bg { position: fixed; z-index: 0; }
#bgModel { background: radial-gradient(120% 90% at 50% 35%, #fbf4e7 0%, var(--bg-top) 55%, var(--bg-top2) 100%); transition: background 1.2s; }
body.done #bgModel { background: radial-gradient(90% 80% at 50% 40%, #fff3dc 0%, #e8c79a 45%, #6e4b33 100%); }
#bgSheet { background:
  repeating-linear-gradient(0deg, rgba(0,0,0,0.035) 0 1px, transparent 1px 24px),
  repeating-linear-gradient(90deg, rgba(0,0,0,0.035) 0 1px, transparent 1px 24px),
  linear-gradient(180deg, var(--bench) 0%, var(--bench2) 100%); }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; z-index: 1; }

#rotBtns, #rotBtns button, #holdBtns, #holdBtns button, #tools, #tools button { touch-action: none; }


#top { position: fixed; z-index: 3; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 10px; display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); pointer-events: none; font-variant-numeric: tabular-nums; }
#bar { width: 92px; height: 8px; border-radius: 4px; background: rgba(120, 90, 50, 0.18); overflow: hidden; }
#barIn { height: 100%; width: 0%; background: linear-gradient(90deg, #e8a25a, var(--accent)); border-radius: 4px; transition: width 0.4s; }
@media (max-width: 600px) { #stepNo { display: none; } }
#pct { min-width: 34px; text-align: right; color: var(--ink); font-weight: 600; }


#card { position: fixed; z-index: 3; left: 8px; top: calc(env(safe-area-inset-top, 0px) + 8px); width: 200px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 2px 10px rgba(80, 50, 20, 0.14); padding: 7px 8px 8px; }
#cardHead { display: flex; align-items: center; gap: 4px; font-size: 13px; }
#cardHead b { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.pg { width: 30px; height: 26px; border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 15px; line-height: 1; padding: 0; }
.pg:disabled { opacity: 0.35; }
#cardTitle { font-size: 12.5px; font-weight: 700; margin: 4px 0 2px; line-height: 1.3; }
#cardNote { font-size: 10px; line-height: 1.35; color: var(--muted); }
#cardNote div { margin: 1px 0 2px; }
#cardNote:empty { display: none; }
#diagram { display: block; width: 100%; height: auto; background: #fffdf8; border: 1px solid #efe3cd; border-radius: 6px; cursor: zoom-in; }
#cardParts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chip { font-family: inherit; color: inherit; cursor: pointer; display: flex; align-items: center; gap: 3px; font-size: 11px; background: #fbf1df; border: 1px solid #ecd9b8; border-radius: 6px; padding: 1px 5px 1px 2px; }
.chip svg { width: 20px; height: 20px; }
.chip.done { opacity: 0.45; text-decoration: line-through; }
#cardHead small { font-size: 10.5px; color: var(--muted); }
#cardNow { display: none; margin-top: 5px; width: 100%; font-size: 12px; padding: 4px; border-radius: 6px; border: 1px solid var(--accent); background: #fff4e6; color: var(--accent); }
#cardText { font-size: 11.5px; color: var(--muted); line-height: 1.4; margin-top: 4px; }

#cardHead .fold { width: 26px; margin-left: 2px; }
body.cardFold #cardBody { display: none; }
body.cardFold #card { width: auto !important; }


#pvCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
#mini { position: fixed; z-index: 3; border-radius: 12px; background: radial-gradient(90% 90% at 50% 40%, #fff8ea, #ecdcc0); border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(80, 50, 20, 0.16); overflow: hidden; cursor: zoom-in; }
#miniView { position: absolute; inset: 0; }
#miniLabel { position: absolute; left: 7px; top: 5px; font-size: 11px; font-weight: 700; color: var(--muted); pointer-events: none; }
#miniFold { position: absolute; right: 3px; top: 3px; width: 24px; height: 22px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255,255,255,0.85); font-size: 13px; line-height: 1; padding: 0; }
#miniTab { position: fixed; z-index: 3; display: none; height: 30px; padding: 0 12px; border-radius: 15px; border: 1px solid #c9ab7f; background: rgba(255,250,240,0.92); font-size: 13px; font-weight: 700; }
body.miniFold #mini { display: none; }
body.miniFold #miniTab { display: block; }
#peek { position: fixed; inset: 0; z-index: 10; background: rgba(40, 25, 10, 0.5); display: none; align-items: center; justify-content: center; padding: 12px; }
#peek.on { display: flex; }
#peekBox { background: var(--paper); border-radius: 14px; width: min(640px, 100%); height: min(720px, 100%); display: flex; flex-direction: column; padding: 10px; box-sizing: border-box; box-shadow: 0 8px 30px rgba(0,0,0,0.3); }
#peekHead { display: flex; align-items: center; gap: 8px; font-size: 15px; }
#peekHead b { flex: 1; }
#peekClose { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 14px; }
#peekView { position: relative; flex: 1; min-height: 0; margin: 8px 0; border-radius: 10px; overflow: hidden; background: radial-gradient(90% 80% at 50% 40%, #fffaf0, #ead8b8); }
#pvLabels { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#pvLabels span { position: absolute; transform: translate(-50%, -50%); font-size: 10.5px; font-weight: 700; color: #6b2f08; background: rgba(255, 248, 235, 0.85);
  border: 1px solid #e3c9a0; border-radius: 5px; padding: 0 3px; white-space: nowrap; }
#peekCtl { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
#explode { flex: 1; height: 30px; accent-color: var(--accent); }
#explodeVal { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 400; }
.chk { display: flex; align-items: center; gap: 3px; font-weight: 400; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
#peekHint { font-size: 12px; color: var(--muted); margin-top: 4px; }
#intro { position: fixed; inset: 0; z-index: 15; display: flex; align-items: center; justify-content: center; padding: 14px;
  background: radial-gradient(100% 80% at 50% 35%, #fff3dc 0%, #e8c79a 55%, #8a6142 100%); }
body.started #intro { display: none; }
#introBox { width: min(560px, 100%); height: min(760px, 100%); display: flex; flex-direction: column; align-items: center; border: 2px solid rgba(110, 60, 25, 0.35);
  border-radius: 16px; padding: 14px; box-sizing: border-box; background: rgba(255, 248, 232, 0.35); }
#introTop { text-align: center; }
#introTop small { font-size: 13px; letter-spacing: 0.2em; color: #7a4a22; }
#introTop h1 { margin: 2px 0 0; font-size: 34px; letter-spacing: 0.12em; color: #4a2a12; }
#introView { flex: 1; width: 100%; min-height: 0; }
#introSub { font-size: 13px; color: #5a3a1e; margin: 6px 0 12px; text-align: center; }
#introGo { padding: 13px 52px; border-radius: 26px; border: none; background: var(--accent); color: #fff; font-size: 18px; font-weight: 800; box-shadow: 0 3px 10px rgba(0,0,0,0.25); }
body.done #mini, body.done #miniTab { display: none; }


#rotBtns { position: fixed; z-index: 4; display: none; flex-direction: column; gap: 4px; }
body.holding #rotBtns { display: flex; }
body.holding #miniTab { display: none; }
.rotRow { display: flex; gap: 4px; --ax: #888; border-left: 4px solid var(--ax); padding-left: 3px; border-radius: 3px; }
#rotBtns button { width: 54px; height: 50px; padding: 2px 0 0; border-radius: 10px; border: 1px solid #c9ab7f; background: rgba(255,250,240,0.95); box-shadow: 0 1px 4px rgba(80,50,20,0.18);
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink); touch-action: manipulation; }
#rotBtns button:active { background: #ffe7c7; }
#rotBtns svg { width: 28px; height: 28px; }
#rotBtns span { font-size: 9.5px; line-height: 1.1; color: var(--muted); white-space: nowrap; }
#touchlog { position: fixed; z-index: 30; right: 4px; top: 70px; max-width: 70vw; margin: 0; display: none; pointer-events: none; font: 10.5px/1.35 ui-monospace, Menlo, Consolas, monospace;
  background: rgba(20, 12, 4, 0.78); color: #fff4df; padding: 5px 7px; border-radius: 6px; white-space: pre-wrap; }


#holdBtns { position: fixed; z-index: 4; display: none; gap: 8px; }
body.holding #holdBtns { display: flex; }
#holdBtns button { height: 46px; padding: 0 13px; border-radius: 23px; font-size: 15px; font-weight: 800; border: 1px solid #c9ab7f; background: rgba(255,250,240,0.95); box-shadow: 0 2px 6px rgba(80,50,20,0.2); }
#holdBtns #dropBtn { background: var(--accent); border-color: var(--accent); color: #fff; padding: 0 20px; }


#zoom { position: fixed; inset: 0; z-index: 10; background: rgba(40, 25, 10, 0.45); display: none; align-items: center; justify-content: center; padding: 16px; }
#zoom.on { display: flex; }
#zoomBox { background: var(--paper); border-radius: 12px; width: min(560px, 100%); padding: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.25); }
#zoomBox h2 { font-size: 16px; margin: 0 0 6px; }
#zoomSvg { width: 100%; height: auto; display: block; border: 1px solid #efe3cd; border-radius: 8px; background: #fffdf8; }
#zoomText { font-size: 14px; line-height: 1.6; margin: 8px 0; }
#zoomParts { display: flex; flex-wrap: wrap; gap: 6px; }
#zoomParts .chip { font-size: 13px; }
#zoomParts .chip svg { width: 30px; height: 30px; }
#zoomClose { margin-top: 10px; width: 100%; padding: 10px; font-size: 15px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }


#tools { position: fixed; z-index: 3; top: calc(env(safe-area-inset-top, 0px) + 30px); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#tools button { height: 32px; padding: 0 11px; border-radius: 16px; border: 1px solid #c9ab7f; background: rgba(255, 250, 240, 0.92); font-size: 13px; font-weight: 700; box-shadow: 0 1px 4px rgba(80, 50, 20, 0.15); }
#tools button.on { border-color: var(--accent); color: var(--accent); background: #fff4e6; }
#helpBtn { width: 32px; padding: 0 !important; }
#help { position: fixed; inset: 0; z-index: 10; background: rgba(40, 25, 10, 0.45); display: none; align-items: center; justify-content: center; padding: 16px; }
#help.on { display: flex; }
#helpBox { background: var(--paper); border-radius: 12px; width: min(520px, 100%); max-height: 88vh; overflow: auto; padding: 12px 14px; box-shadow: 0 8px 30px rgba(0,0,0,0.25); font-size: 13.5px; line-height: 1.55; }
#helpBox h2 { font-size: 16px; margin: 0 0 6px; }
#helpBox h3 { font-size: 13.5px; margin: 10px 0 2px; color: var(--accent); }
#helpBox ul { margin: 0; padding-left: 1.2em; }
#helpClose { margin-top: 10px; width: 100%; padding: 10px; font-size: 15px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.thumb.glow { box-shadow: 0 0 0 3px var(--accent), 0 0 14px rgba(208, 102, 28, 0.7); }
.tab.empty { opacity: 0.45; }


#tray { position: fixed; z-index: 3; display: flex; align-items: center; gap: 10px; padding: 0 12px; box-sizing: border-box;
  background: linear-gradient(180deg, #e2cfae, #d6bf98); border-top: 1px solid #c4a77c; border-bottom: 1px solid #b39467; }
#trayLabel { font-size: 12px; color: var(--muted); writing-mode: vertical-rl; letter-spacing: 0.1em; flex: none; }
#hand { display: flex; gap: 10px; flex: 1; align-items: center; min-width: 0; }
.thumb { width: 62px; height: 62px; flex: none; border-radius: 10px; background: rgba(255, 250, 240, 0.85); border: 1px solid #c9ab7f;
  display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; cursor: grab;
  box-shadow: 0 2px 4px rgba(80, 50, 20, 0.15); animation: popin 0.32s cubic-bezier(.2, 1.6, .5, 1); }
.thumb svg { width: 46px; height: 42px; pointer-events: none; }
.thumb span { font-size: 10.5px; color: var(--muted); line-height: 1; pointer-events: none; }
.thumb.dragging { opacity: 0.25; }
@keyframes popin { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#handEmpty { font-size: 12.5px; color: var(--muted); }


#tabs { position: fixed; z-index: 3; display: flex; gap: 6px; }
.tab { min-width: 40px; height: 30px; border-radius: 8px; border: 1px solid #a88b60; background: rgba(255, 248, 235, 0.8); font-size: 14px; font-weight: 700; position: relative; }
.tab.on { background: #fff; border-color: var(--accent); color: var(--accent); }
.tab i { position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: none; }
.tab.need i { display: block; }


#toast { position: fixed; z-index: 4; left: 50%; transform: translateX(-50%); background: rgba(59, 42, 26, 0.88); color: #fff8ec;
  font-size: 13.5px; padding: 7px 14px; border-radius: 18px; pointer-events: none; opacity: 0; transition: opacity 0.25s; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; }
#toast.on { opacity: 1; }
#toast.top { white-space: normal; text-align: center; line-height: 1.4; width: max-content; }


#done { position: fixed; z-index: 5; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); display: none; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; }
body.done #done { display: flex; }
#doneTitle { font-size: 26px; font-weight: 800; color: #fffaf0; text-shadow: 0 2px 8px rgba(60, 30, 10, 0.5); letter-spacing: 0.08em; }
#doneSub { text-align: center; line-height: 1.5; font-size: 14px; color: #fff3df; text-shadow: 0 1px 4px rgba(60, 30, 10, 0.6); }
#doneBtns { display: flex; gap: 10px; pointer-events: auto; }
#doneBtns button { padding: 11px 18px; border-radius: 22px; border: none; font-size: 15px; font-weight: 700; background: #fffaf0; color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,0.25); }
#doneBtns button.main { background: var(--accent); color: #fff; }
body.done #card, body.done #tray, body.done #tabs, body.done #bgSheet, body.done #tools { display: none; }
body.done #top { display: none; }

#loading { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: var(--bg-top); font-size: 15px; color: var(--muted); }


.lab-note { margin: 12px 0 0; font-size: 12.5px; line-height: 1.7; color: #5a3a1e; text-align: center; }
.lab-note a { color: inherit; text-underline-offset: 3px; display: inline-block; min-height: 30px; line-height: 30px; }
.lab-link { display: block; margin: 10px 0 8px; padding: 11px 18px; border-radius: 22px; background: var(--accent); color: #fff; font-size: 15px; font-weight: 700;
  text-align: center; text-decoration: none; }
.lab-link--done { margin: 0; background: #fffaf0; color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,0.25); }

#bgModel { background: radial-gradient(120% 90% at 50% 35%, #f7f9fb 0%, #dfe5ec 60%, #c3ccd6 100%) !important; }
#bgSheet { background: linear-gradient(180deg, #9aa3ad 0%, #7d8791 100%) !important; border-top: 10px solid transparent; border-image: repeating-linear-gradient(45deg, #1d1d1d 0 12px, #f5c400 12px 24px) 10; }
#tray { background: linear-gradient(180deg, #c9d0d8, #b5bec8) !important; border-color: #8d98a5 !important; }
#doneTitle { color: #1e2a38 !important; text-shadow: none !important; }
#doneSub { color: #3c4856 !important; text-shadow: none !important; }

.kitnui { position: fixed; z-index: 30; pointer-events: none; height: auto; opacity: 0; transform: translateY(8px); transition: opacity .15s, transform .15s; }
.kitnui.on { opacity: 1; transform: none; }
.kitbeam { position: fixed; left: 0; top: 0; z-index: 31; pointer-events: none; }
.kitnui-cheer { position: fixed; z-index: 30; pointer-events: none; right: 3%; bottom: 120px; width: 150px; height: auto; opacity: 0; transform: translateY(16px); transition: opacity .4s, transform .4s; }
.kitnui-cheer.on { opacity: 1; transform: none; }
@media (max-width: 700px) { .kitnui-cheer { width: 96px; bottom: 150px; right: 2%; } }

:root { --bench: #c3cad3; --bench2: #b2bac4; --paper: #f6f8fa; --ink: #1f2a37; --muted: #5d6b7a; --line: #c6ced8; }
#intro { background: radial-gradient(100% 80% at 50% 35%, #f7f9fb 0%, #d5dce4 55%, #6f7b88 100%) !important; }
#introBox { border-color: rgba(31, 42, 55, .3) !important; background: rgba(255, 255, 255, .45) !important; }
#introTop small { color: #4a5a6c !important; } #introTop h1 { color: #1E1B3A !important; } #introSub { color: #3c4856 !important; }
.lab-note { color: #3c4856; }

#toast { white-space: normal !important; text-overflow: clip !important; width: max-content; max-width: calc(100vw - 32px); text-align: center; line-height: 1.45; }
@media (max-width: 700px) { #toast { white-space: pre-line !important; } }   


.labfx { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; }
.labfx-word, .labfx-done { position: fixed; z-index: 41; pointer-events: none; opacity: 0; white-space: nowrap;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif; font-weight: 900; }

@font-face { font-family: "LabZMG"; font-weight: 900; font-display: swap; src: url("../../assets/fonts/zmg-900.woff2") format("woff2"); }
.labfx-word { font-family: "LabZMG", "Hiragino Maru Gothic ProN", "Yu Gothic UI", sans-serif; font-weight: 900; font-size: 40px; letter-spacing: .04em; color: #E2574F;
  text-shadow: 0 0 1px #fff, 2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 1.5px 1.5px 0 #fff, -1.5px 1.5px 0 #fff, 1.5px -1.5px 0 #fff, -1.5px -1.5px 0 #fff, 3px 4px 0 rgba(30, 27, 58, .28);
  transform: translate(-50%, -50%) rotate(-7deg); }
.labfx-word.on { animation: labfxWord .9s ease-out both; }
@keyframes labfxWord { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-7deg) scale(1.6); } 14% { opacity: 1; transform: translate(-50%, -50%) rotate(-7deg) scale(.95); }
  24% { transform: translate(-50%, -50%) rotate(-7deg) scale(1); } 70% { opacity: 1; transform: translate(-50%, -62%) rotate(-7deg) scale(1); } 100% { opacity: 0; transform: translate(-50%, -80%) rotate(-7deg) scale(1); } }
@media (max-width: 700px) { .labfx-word { font-size: 30px; } }

.labfx-done { color: #d9ecff; font: 700 22px/1 Consolas, Menlo, monospace; letter-spacing: .12em; padding: 10px 18px; border: 2px solid #7fd7ff; background: rgba(11, 35, 64, .85); transform: translate(-50%, 0); }
.labfx-done.on { animation: labfxDone 1.8s ease-out both; }
@keyframes labfxDone { 0% { opacity: 0; transform: translate(-50%, 8px); } 12% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .labfx-word.on, .labfx-done.on { animation-duration: .6s; } }
