:root {
  --bg: #0b0e15; --panel: rgba(24, 29, 41, 0.92); --panel2: #1c2230; --line: rgba(255,255,255,0.08);
  --ink: #e9edf5; --dim: #8e98ab; --accent: #ff8a3d; --accent2: #4aa3ff; --ok: #38d39f;
  --r: 12px; --safe-t: env(safe-area-inset-top); --safe-b: env(safe-area-inset-bottom);
  --safe-l: env(safe-area-inset-left); --safe-r: env(safe-area-inset-right);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }

header#top, footer#bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); min-height: 56px; }
footer#bar { border-top: 1px solid var(--line); border-bottom: 0; min-height: 52px; }
.row { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.spacer { flex: 1; }
.grp { display: flex; gap: 6px; align-items: center; }

.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; letter-spacing: 0.2px; margin-right: 4px; }
.logo, .splogo { width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff9 0 8%, transparent 9%), radial-gradient(circle at 30% 70%, #4aa3ff 0 34%, transparent 35%),
    radial-gradient(circle at 70% 35%, #ff8a3d 0 30%, transparent 31%), radial-gradient(circle at 68% 76%, #9a6a44 0 26%, transparent 27%), #232a3a; }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; min-width: 42px; height: 42px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; font-size: 18px; transition: background .12s, transform .06s; }
.btn:hover { background: #262e40; }
.btn:active { transform: scale(0.96); }
.btn.pill { font-size: 14px; font-weight: 600; padding: 0 14px; }
.btn.small { height: 34px; min-width: 34px; font-size: 13px; }
.btn.accent { background: linear-gradient(180deg, #ff9a52, #f0762a); border-color: #ff9a52; color: #1a0f06; }
.btn.accent:hover { background: linear-gradient(180deg, #ffa866, #f38237); }
.btn.on { background: #2b3a58; border-color: var(--accent2); box-shadow: inset 0 0 0 1px var(--accent2); }
.btn.big { height: 52px; font-size: 17px; padding: 0 24px; border-radius: 14px; font-weight: 700; }

.seg { display: flex; background: #121722; border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { background: transparent; border: 0; border-radius: 9px; height: 40px; min-width: 50px; padding: 0 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 18px; cursor: pointer; color: var(--dim); }
.seg button small { font-size: 10px; font-weight: 600; letter-spacing: .2px; margin-top: -1px; }
.seg button.on { background: #2b3448; color: var(--ink); box-shadow: 0 1px 0 #fff1 inset; }
.seg.small button { height: 30px; min-width: 0; flex: 1; font-size: 12px; font-weight: 700; }

main { flex: 1; display: flex; min-height: 0; }
#palette { width: 214px; background: var(--panel); border-right: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
#mats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 3px; }
.mat { display: flex; align-items: center; gap: 6px; padding: 5px 5px; min-width: 0; border-radius: 9px; border: 1px solid transparent; background: transparent; cursor: pointer; text-align: left; min-height: 38px; }
.mat:hover { background: #ffffff08; }
.mat.on { background: #2b3448; border-color: #ffffff22; }
.mat .sw { width: 22px; height: 22px; flex: none; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffffaa 0 12%, transparent 30%), var(--c); box-shadow: 0 0 0 1px #0006 inset, 0 1px 3px #0008; }
.mat .sw.st { border-radius: 5px; }
.mat .sw.fx { background: radial-gradient(circle, #fff6 0 10%, var(--c) 45%, transparent 72%); box-shadow: none; }
.mat span { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

#stageWrap { flex: 1; position: relative; min-width: 0; background: #070910; }
#gl, #ov { position: absolute; border-radius: 6px; }
#ov { touch-action: none; cursor: crosshair; }
#hint { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: #000a; padding: 8px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
  pointer-events: none; opacity: 0; transition: opacity .3s; white-space: nowrap; }
#hint.show { opacity: 1; }
#stats { position: absolute; right: 10px; bottom: 8px; font: 11px ui-monospace, Menlo, monospace; color: #fff6; pointer-events: none; }

#dial { width: 42px; height: 42px; border-radius: 50%; background: radial-gradient(circle, #1b2231 55%, #2a3346 56%); border: 1px solid var(--line); position: relative; cursor: grab; touch-action: none; }
#dial i { position: absolute; left: 50%; top: 50%; width: 3px; height: 17px; background: var(--accent2); border-radius: 2px; transform-origin: 50% 0; transform: translate(-50%, 0) rotate(0deg); }
#dial i::after { content: ""; position: absolute; bottom: -4px; left: -3.5px; border: 5px solid transparent; border-top: 7px solid var(--accent2); }

.rec { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 13px; color: #ff6b6b; letter-spacing: .5px; }
.rec i { width: 10px; height: 10px; border-radius: 50%; background: #ff4d4d; animation: pulse 1.6s infinite; }
.rec b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.rec.paused i { animation: none; background: #777; }
@keyframes pulse { 50% { opacity: .25; } }
.mono { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--dim); min-width: 92px; text-align: center; }
#scrub { flex: 1; accent-color: var(--accent); height: 30px; }

.pop { position: fixed; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; display: grid; grid-template-columns: repeat(4, 52px); gap: 6px; box-shadow: 0 10px 40px #000a; }
.pop button { height: 52px; font-size: 30px; background: #ffffff08; border: 1px solid transparent; border-radius: 10px; cursor: pointer; }
.pop button.on { border-color: var(--accent); }
.pop button.wide { grid-column: span 4; font-size: 14px; font-weight: 600; height: 40px; }

.modal { position: fixed; inset: 0; z-index: 40; background: #0009; display: flex; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.card { background: #151a25; border: 1px solid var(--line); border-radius: 18px; width: min(860px, 100%); max-height: 88vh; overflow: auto; padding: 18px 20px 22px; box-shadow: 0 20px 80px #000c; }
.mhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.mhead h2 { margin: 0; font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.scene { background: #1d2331; border: 1px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; text-align: left; transition: transform .1s, border-color .1s; }
.scene:hover { border-color: var(--accent); transform: translateY(-2px); }
.scene .em { font-size: 30px; }
.scene h3 { margin: 6px 0 4px; font-size: 15px; }
.scene p { margin: 0; color: var(--dim); font-size: 12.5px; }
.sess { background: #1d2331; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.sess img { width: 100%; aspect-ratio: 1.6; object-fit: cover; display: block; background: #0b0e15; }
.sess .meta { padding: 8px 10px 4px; font-size: 13px; }
.sess .meta b { display: block; }
.sess .meta small { color: var(--dim); }
.sess .acts { display: flex; gap: 4px; padding: 6px 8px 10px; flex-wrap: wrap; }
.sess .acts .btn { height: 32px; font-size: 12px; padding: 0 8px; min-width: 0; }
.libtools { display: flex; gap: 8px; margin-bottom: 12px; }
.empty { color: var(--dim); padding: 30px; text-align: center; }

#splash { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(ellipse at 50% 30%, #1d2740, #070910 70%); transition: opacity .4s; }
#splash.gone { opacity: 0; pointer-events: none; }
.sp { max-width: 640px; text-align: center; }
.splogo { width: 96px; height: 96px; margin: 0 auto 10px; box-shadow: 0 0 60px #ff8a3d55; }
.sp h1 { font-size: 56px; margin: 6px 0 4px; letter-spacing: -1px; background: linear-gradient(90deg, #7cc0ff, #ffb07a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sp .tag { font-size: 19px; color: #cfd6e4; margin: 0 0 24px; }
.spbtns { display: flex; gap: 12px; justify-content: center; margin-bottom: 22px; flex-wrap: wrap; }
.sp .fine { color: var(--dim); font-size: 13.5px; }
.sp .tribute { color: #6f7a8f; font-size: 12px; margin-top: 18px; }

#toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%) translateY(20px); background: #222a3b; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  z-index: 60; opacity: 0; transition: all .25s; pointer-events: none; font-weight: 600; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.vidrec { position: fixed; top: 70px; right: 20px; z-index: 35; background: #c0262d; color: #fff; padding: 6px 12px; border-radius: 20px; font-weight: 700; font-size: 13px; }

@media (max-width: 1000px) {
  .seg button small { display: none; }
  .seg button { min-width: 40px; }
  .brand b { display: none; }
  #palette { width: 196px; }
  .mat span { font-size: 11.5px; }
}
@media (orientation: portrait) {
  main { flex-direction: column-reverse; }
  #palette { width: auto; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; max-height: 108px; }
  #mats { grid-template-columns: none; grid-auto-flow: column; grid-template-rows: 1fr 1fr; }
  #sizes { flex-direction: column; width: 44px; flex: none; }
  header#top { flex-wrap: wrap; }
}

.btn.anchor { width: 100%; justify-content: center; }

#sizes { align-items: center; }
#sizes .szlab { font-size: 11px; font-weight: 700; color: var(--dim); padding: 0 6px 0 8px; letter-spacing: .3px; }
#sizes button { height: 36px; }
#sizes .dot { display: block; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffffffaa 0 15%, transparent 40%), var(--dot, #4aa3ff); box-shadow: 0 0 0 1px #0006 inset; }
@media (orientation: portrait) { #sizes .szlab { display: none; } }


#bHelp { font-weight: 800; font-size: 18px; }
.guide .gcols { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 16px; }
.guide section { background: #1d2331; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.guide h3 { margin: 0 0 4px; font-size: 14.5px; }
.guide p { margin: 0; color: #c4ccda; font-size: 13px; line-height: 1.45; }
.guide .gfoot { margin-top: 12px; color: var(--dim); font-size: 12px; text-align: center; }

.vidready { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.vidready video { width: 100%; max-height: 50vh; border-radius: 12px; background: #000; }
.vidready .vnote { margin: 0; color: var(--dim); font-size: 13px; }

.plogo { height: 18px; width: auto; flex: none; margin-left: 8px; opacity: 0.95; }
@media (max-width: 700px) { .plogo { display: none; } }

.pop .pophead { grid-column: 1 / -1; font-size: 11.5px; font-weight: 700; color: var(--dim); padding: 2px 2px 0; letter-spacing: .3px; }
