[hidden] { display: none !important; }
:root {
  --bg: #07060b;
  --panel: #0e0c16;
  --panel2: #151225;
  --line: #2a2445;
  --fg: #d9d4f0;
  --dim: #8a83ad;
  --acc: #39ff88;
  --acc2: #ff2bd6;
  --acc3: #29f3ff;
  --warn: #ffb000;
  --font-ui: "DotGothic16", "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  --font-num: "VT323", "Share Tech Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 13px; overflow: hidden; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }

/* ---- BOOT ---- */
#boot { position: fixed; inset: 0; z-index: 5000; background: #000; display: grid; place-items: center; }
#boot::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.35) 0 1px, transparent 1px 3px), radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.8)); }
.boot-crt { width: min(900px, 94vw); color: var(--acc); text-shadow: 0 0 6px rgba(57,255,136,.8); }
#boot-logo { font-family: var(--font-num); font-size: clamp(9px, 1.7vw, 18px); line-height: 1.05; margin: 0; color: var(--acc2); text-shadow: 0 0 10px rgba(255,43,214,.9); white-space: pre; overflow: hidden; }
.boot-sub { letter-spacing: .5em; margin: 8px 0 20px; color: var(--acc3); text-shadow: 0 0 8px rgba(41,243,255,.8); }
#boot-log { font-family: var(--font-num); font-size: 20px; line-height: 1.15; min-height: 9em; margin: 0 0 20px; white-space: pre-wrap; }
.boot-btns { display: flex; flex-wrap: wrap; gap: 14px; }
.btn.big.boot-cont { border-color: var(--dim); color: var(--dim); text-shadow: none; }
.boot-foot { color: var(--dim); text-shadow: none; margin-top: 18px; font-size: 12px; }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
#boot.out { animation: crtOff .55s ease-in forwards; }
@keyframes crtOff { 0% { transform: scale(1); filter: brightness(1); } 60% { transform: scale(1, .004); filter: brightness(3); } 100% { transform: scale(0, .004); opacity: 0; } }

/* ---- LAYOUT ---- */
#app { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
#app.noui { grid-template-columns: 0 1fr; }
#app.noui #panel { display: none; }
#app.noui #topbar, #app.noui #timeline { display: none; }
#panel { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #1a0f2e, var(--panel)); }
.logo { font-family: var(--font-num); font-size: 34px; line-height: 1; letter-spacing: 2px; color: #fff;
  text-shadow: 2px 0 var(--acc2), -2px 0 var(--acc3), 0 0 14px rgba(255,43,214,.6); }
.logo span { color: var(--acc); text-shadow: 0 0 10px var(--acc); }
.brand-sub { color: var(--dim); font-size: 10px; letter-spacing: .25em; margin-top: 4px; }
#panel-body { overflow-y: auto; flex: 1; padding: 6px 0 40px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

details.sec { border-bottom: 1px solid var(--line); }
details.sec > summary { list-style: none; cursor: pointer; padding: 10px 14px; display: flex; gap: 10px; align-items: center; user-select: none; font-size: 14px; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary:hover { background: var(--panel2); }
details.sec[open] > summary { color: #fff; background: linear-gradient(90deg, rgba(255,43,214,.14), transparent); }
details.sec > summary::after { content: "▸"; margin-left: auto; color: var(--dim); transition: transform .15s; }
details.sec[open] > summary::after { transform: rotate(90deg); color: var(--acc2); }
.tag { font-family: var(--font-num); font-size: 15px; color: #000; background: var(--acc); padding: 0 5px; border-radius: 2px; min-width: 26px; text-align: center; }
details.sec:nth-child(3n+2) .tag { background: var(--acc2); }
details.sec:nth-child(3n) .tag { background: var(--acc3); }
.sec-body { padding: 4px 14px 14px; }
.grp { margin-top: 10px; }
.grp-t { font-size: 11px; color: var(--acc3); letter-spacing: .15em; margin: 6px 0 4px; border-bottom: 1px dashed var(--line); padding-bottom: 3px; }

.row { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; min-height: 28px; }
.row .lbl { color: var(--dim); font-size: 12px; line-height: 1.2; }
.rng { display: grid; grid-template-columns: 1fr 70px; align-items: center; gap: 6px; }
.rng output, .rng .num { font-family: var(--font-num); font-size: 17px; text-align: right; color: var(--acc); cursor: text; }
.rng .num { width: 70px; background: #000; border: 1px solid var(--acc); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: linear-gradient(90deg, var(--acc2), var(--acc3)); border-radius: 0; opacity: .55; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 16px; margin-top: -6px; background: #fff; border: 2px solid #000; box-shadow: 0 0 6px var(--acc2); }
input[type=range]::-moz-range-track { height: 4px; background: linear-gradient(90deg, var(--acc2), var(--acc3)); opacity: .55; }
input[type=range]::-moz-range-thumb { width: 8px; height: 14px; background: #fff; border: 2px solid #000; border-radius: 0; }
select, input[type=text], input[type=number], input[type=date] { width: 100%; background: #05040a; border: 1px solid var(--line); padding: 5px 6px; border-radius: 0; color: var(--fg); }
select:focus, input:focus { outline: 1px solid var(--acc2); }
input[type=color] { width: 100%; height: 26px; border: 1px solid var(--line); background: #000; padding: 1px; }
.sw { position: relative; width: 40px; height: 20px; display: inline-block; }
.sw input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.sw i { position: absolute; inset: 0; background: #05040a; border: 1px solid var(--line); }
.sw i::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; background: var(--dim); transition: left .12s; }
.sw input:checked + i { border-color: var(--acc); box-shadow: 0 0 8px rgba(57,255,136,.4) inset; }
.sw input:checked + i::after { left: 22px; background: var(--acc); }

.btn { background: #120f20; border: 1px solid var(--line); padding: 6px 10px; cursor: pointer; color: var(--fg); transition: all .1s; white-space: nowrap; }
.btn:hover { border-color: var(--acc2); color: #fff; box-shadow: 0 0 10px rgba(255,43,214,.35); }
.btn:active { transform: translateY(1px); }
.btn.pri { background: linear-gradient(180deg, #ff2bd6, #a0108a); border-color: #ff7ce8; color: #fff; font-weight: bold; }
.btn.acc { background: linear-gradient(180deg, #1ce87a, #0a8a44); border-color: #8bffbf; color: #001a0b; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.big { font-size: 22px; padding: 12px 30px; background: transparent; border: 2px solid var(--acc); color: var(--acc); text-shadow: 0 0 8px var(--acc); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.btns .btn { flex: 1 1 auto; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chip { background: #05040a; border: 1px solid var(--line); padding: 4px 7px; font-size: 12px; cursor: pointer; color: var(--fg); }
.chip:hover { border-color: var(--acc3); }
.chip.on { background: var(--acc3); color: #000; border-color: var(--acc3); }
.note { color: var(--dim); font-size: 11px; line-height: 1.5; margin: 6px 0; }
.note b { color: var(--warn); font-weight: normal; }
.search { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin: 6px 0; }
.results { max-height: 160px; overflow-y: auto; border: 1px solid var(--line); display: none; }
.results.on { display: block; }
.results div { padding: 4px 8px; cursor: pointer; border-bottom: 1px solid #1a1630; }
.results div:hover { background: var(--panel2); color: var(--acc); }
#minimap { position: relative; z-index: 0; height: 210px; border: 1px solid var(--line); margin: 8px 0; background: #111; }
.leaflet-container { background: #111; font-family: var(--font-ui); }
.keylist { font-family: var(--font-num); font-size: 16px; max-height: 140px; overflow-y: auto; border: 1px solid var(--line); margin: 6px 0; }
.keylist div { display: flex; justify-content: space-between; padding: 2px 8px; border-bottom: 1px solid #1a1630; }
.keylist button { background: none; border: 0; color: var(--acc2); cursor: pointer; }

/* ---- MAIN ---- */
#main { display: grid; grid-template-rows: 40px 1fr 52px; min-width: 0; min-height: 0; }
#topbar { display: flex; justify-content: space-between; align-items: center; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); gap: 10px; }
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; overflow: hidden; white-space: nowrap; }
.tb-right { display: flex; gap: 6px; }
#tb-place { font-size: 15px; color: #fff; }
.dim { color: var(--dim); font-family: var(--font-num); font-size: 16px; }
.led { width: 9px; height: 9px; background: var(--acc); box-shadow: 0 0 8px var(--acc); flex: none; }
.led.busy { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: blink .4s steps(2) infinite; }
.led.err { background: #ff3030; box-shadow: 0 0 8px #ff3030; }
#stage { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden;
  background: repeating-linear-gradient(45deg, #0a0912 0 10px, #0c0b16 10px 20px); }
#frame { position: relative; box-shadow: 0 0 0 1px #2a2445, 0 0 40px rgba(0,0,0,.8); }
#frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#gl { cursor: grab; }
#gl:active { cursor: grabbing; }
#overlay { pointer-events: none; }
#pick-hint { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(0,0,0,.8); border: 1px solid var(--warn); color: var(--warn); padding: 6px 14px; z-index: 3; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); z-index: 5; }
.ld-box { width: 320px; border: 1px solid var(--acc); padding: 16px; background: #000; box-shadow: 0 0 20px rgba(57,255,136,.3); }
.ld-t { color: var(--acc); font-family: var(--font-num); font-size: 22px; letter-spacing: .2em; margin-bottom: 10px; }
.ld-bar { height: 14px; border: 1px solid var(--acc); padding: 2px; }
.ld-bar i { display: block; height: 100%; width: 0%; background: repeating-linear-gradient(90deg, var(--acc) 0 8px, transparent 8px 10px); transition: width .1s; }
.ld-p { color: var(--acc); font-family: var(--font-num); font-size: 18px; margin-top: 6px; text-align: right; }
#timeline { display: flex; align-items: center; gap: 10px; padding: 0 12px; border-top: 1px solid var(--line); background: var(--panel); }
#timeline .play { width: 44px; height: 34px; font-size: 16px; color: var(--acc); border-color: var(--acc); }
#timeline .snd { color: var(--dim); border-color: var(--line); min-width: 58px; font-family: var(--font-num); font-size: 16px; padding: 4px 6px; }
#timeline .snd.on { color: var(--acc3); border-color: var(--acc3); box-shadow: 0 0 8px rgba(41,243,255,.35); }
#scrub { flex: 1; }
#tl-time { font-family: var(--font-num); font-size: 19px; color: var(--acc3); min-width: 130px; text-align: right; }
.rec { color: #ff4a4a; border-color: #5a1a2a; }
.rec:hover { border-color: #ff4a4a; box-shadow: 0 0 10px rgba(255,60,60,.5); }

#modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 3000; }
.modal-box { width: 420px; border: 1px solid var(--acc2); background: #0a0814; padding: 20px; box-shadow: 0 0 40px rgba(255,43,214,.3); }
.modal-t { font-family: var(--font-num); font-size: 26px; color: var(--acc2); letter-spacing: .2em; margin-bottom: 12px; }
.modal-p { font-family: var(--font-num); font-size: 18px; margin: 10px 0 14px; color: var(--acc); }
#modal .ld-bar { border-color: var(--acc2); }
#modal .ld-bar i { background: repeating-linear-gradient(90deg, var(--acc2) 0 8px, transparent 8px 10px); }
#toast { position: fixed; right: 18px; bottom: 70px; z-index: 4000; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; }
#toast div { background: #000; border: 1px solid var(--acc); color: var(--acc); padding: 8px 14px; max-width: 420px; font-size: 13px; animation: tin .2s ease-out; box-shadow: 0 0 12px rgba(57,255,136,.25); }
#toast div.err { border-color: #ff4a4a; color: #ff8080; }
@keyframes tin { from { transform: translateX(30px); opacity: 0; } }

@media (max-width: 800px) {
  html, body { height: 100dvh; }
  #app { grid-template-columns: 1fr; grid-template-rows: 52vh 1fr; }
  /* プレビューを比率に合わせるときは枠を横幅いっぱいにし、設定パネルは下に続けて全体をスクロール */
  #app.fitw { grid-template-rows: max-content max-content; overflow-y: auto; overscroll-behavior: contain; }
  #app.fitw #main { grid-template-rows: 40px calc(100vw * var(--ar, 1.7778)) 48px; }
  #app.fitw #panel-body { overflow: visible; }
  #app.noui.fitw { grid-template-rows: 1fr; overflow: hidden; }
  #app.noui.fitw #main { grid-template-rows: 1fr; }
  #app.noui { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  #panel { order: 2; border-right: 0; border-top: 1px solid var(--line); min-height: 0; }
  #panel-body { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .brand { padding: 10px 14px 8px; }
  .logo { font-size: 26px; }
  #main { order: 1; grid-template-rows: 40px 1fr 48px; }
  #topbar { padding: 0 8px; gap: 6px; }
  #tb-info { display: none; }
  #tb-place { font-size: 14px; }
  .tb-right { gap: 4px; flex: none; }
  .tb-right .btn.sm { padding: 4px 6px; }
  #timeline { gap: 6px; padding: 0 8px; }
  #timeline .play { width: 40px; height: 32px; }
  #scrub { min-width: 40px; }
  #tl-time { min-width: 0; font-size: 15px; }
  #timeline .btn.sm { padding: 4px 6px; }
  #timeline .snd { min-width: 0; font-size: 15px; }
  .row { grid-template-columns: 84px 1fr; }
  .ld-box, .modal-box { width: min(420px, 92vw); }
  #toast { right: 10px; left: 10px; bottom: 60px; align-items: stretch; }
  #toast div { max-width: none; }
}
@media (pointer: coarse) {
  input[type=range] { height: 28px; }
  input[type=range]::-webkit-slider-runnable-track { height: 6px; }
  input[type=range]::-webkit-slider-thumb { width: 18px; height: 24px; margin-top: -9px; }
  input[type=range]::-moz-range-thumb { width: 16px; height: 22px; }
  .sw { width: 48px; height: 26px; }
  .sw i::after { width: 20px; height: 20px; }
  .sw input:checked + i::after { left: 24px; }
  details.sec > summary { padding: 12px 14px; }
  .btn, .chip { -webkit-tap-highlight-color: transparent; }
}
