/* Structure and behavior only. Every color, font, size and bit of art comes from the skin
   (CSS variables set from skins/<name>/skin.json). The values below are fallbacks. */
:root {
  --bg: #eceff3; --surface: #ffffff; --surface-2: #f5f7fa;
  --ink: #18212b; --ink-soft: #5a6877;
  --line: #dde3ea; --line-strong: #b9c3cf;
  --accent: #2f5bea; --accent-ink: #ffffff; --danger: #c0392b;
  --shadow: 0 6px 24px rgba(24, 33, 43, .14); --shadow-sm: 0 1px 2px rgba(24, 33, 43, .18);
  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 9px; --bar-mix: 16%; --bar-t: 40px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 var(--font-body); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; padding-left: max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.brand strong { font: 600 21px/1 var(--font-display); letter-spacing: .01em; }
.tag { font-size: 11px; color: var(--ink-soft); border: 1px solid var(--line-strong); border-radius: 99px; padding: 1px 9px; }
.controls { display: flex; gap: 8px; align-items: center; margin-left: auto; overflow-x: auto; padding: 3px; scrollbar-width: thin; }
.controls button, .btn { background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 8px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
.controls button:hover:not(:disabled), .btn:hover { border-color: var(--accent); }
.controls button:disabled { opacity: .45; cursor: default; }
.sel { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); white-space: nowrap; }
.sel select { background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; flex: none; }
.controls .seg button, .seg button { border: 0; border-radius: 0; background: transparent; padding: 6px 11px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg.small button { padding: 5px 12px; }

/* ---------- stage ---------- */
.stage { flex: 1; min-height: 0; display: flex; position: relative; }
#viewport { flex: 1; min-width: 0; position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; background: var(--bg); }
.has-bg-img #viewport { background-image: var(--asset-background); background-size: cover; background-position: center; }
#viewport.panning { cursor: grabbing; }
#plane { position: absolute; overflow: hidden; }
.layer { position: absolute; left: 0; top: 0; width: 0; height: 0; }

.lane-band { position: absolute; background: color-mix(in srgb, var(--c) 5%, var(--surface)); }
#app[data-orient="h"] .lane-band { border-bottom: 1px solid var(--line); }
#app[data-orient="v"] .lane-band { border-right: 1px solid var(--line); }
.grid { position: absolute; background: var(--line); pointer-events: none; }
.grid.major { background: var(--line-strong); opacity: .55; }
.grid.today { background: var(--accent); opacity: .7; }
#app[data-orient="h"] .grid.today { width: 2px !important; }
#app[data-orient="v"] .grid.today { height: 2px !important; }

/* ---------- ruler, lane labels, corner ---------- */
#ruler, #lanelabels, #corner { position: absolute; background: var(--surface); z-index: 6; overflow: hidden; pointer-events: none; }
#app[data-orient="h"] #ruler { border-bottom: 1px solid var(--line-strong); }
#app[data-orient="v"] #ruler { border-right: 1px solid var(--line-strong); }
#app[data-orient="h"] #lanelabels { border-right: 1px solid var(--line-strong); }
#app[data-orient="v"] #lanelabels { border-bottom: 1px solid var(--line-strong); }
#corner { z-index: 7; padding: 7px 9px; font-size: 11px; color: var(--ink-soft); border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); line-height: 1.3; }
#corner b { display: block; font: 600 13px var(--font-display); color: var(--ink); white-space: nowrap; }
#app[data-orient="v"] #corner { padding: 5px 6px; font-size: 10px; }
#app[data-orient="v"] #corner b { font-size: 11px; }

.tick { position: absolute; color: var(--ink-soft); }
#app[data-orient="h"] .tick.major { border-left: 1px solid var(--line-strong); }
#app[data-orient="v"] .tick.major { border-top: 1px solid var(--line-strong); }
.tick.minor { background: var(--line-strong); }
.tick .lab { position: absolute; white-space: nowrap; font-size: 10px; line-height: 1.15; }
.tick.major .lab { font: 600 12px/1.15 var(--font-body); color: var(--ink); left: 6px; top: 5px; }
.tick.major .lab i { display: block; font: 400 10px/1.3 var(--font-body); color: var(--ink-soft); }
#app[data-orient="h"] .tick.minor .lab { left: 4px; top: -2px; }
#app[data-orient="v"] .tick.minor .lab { right: 12px; top: -6px; text-align: right; }
.tick.today { background: var(--accent); }
.tick.today .lab { background: var(--accent); color: var(--accent-ink); padding: 1px 6px; border-radius: 99px; font-weight: 600; font-size: 10px; }
#app[data-orient="h"] .tick.today .lab { left: 5px; top: auto; bottom: 2px; }
#app[data-orient="v"] .tick.today .lab { left: 5px; top: 4px; right: auto; }

.lane-label { position: absolute; display: flex; align-items: flex-start; gap: 8px; padding: 9px 10px; font: 600 12px var(--font-body); color: var(--ink); overflow: hidden; }
.lane-label .sw { flex: none; width: 9px; height: 9px; margin-top: 3px; border-radius: 50%; background: var(--c); }
#app[data-orient="v"] .lane-label { align-items: center; padding: 0 8px; }
#app[data-orient="v"] .lane-label .sw { margin-top: 0; }

/* ---------- events ---------- */
.ev { position: absolute; --c: #777; cursor: pointer; outline: none; }
.ev .bar { position: absolute; border-radius: var(--radius); background: color-mix(in srgb, var(--c) var(--bar-mix), var(--surface)); border: 1.5px solid color-mix(in srgb, var(--c) 65%, var(--surface)); box-shadow: var(--shadow-sm); overflow: hidden; }
.ev .bar::before { content: ""; position: absolute; background: var(--c); }
#app[data-orient="h"] .ev .bar::before { left: 0; top: 0; bottom: 0; width: 4px; }
#app[data-orient="v"] .ev .bar::before { left: 0; right: 0; top: 0; height: 4px; }
.ev:hover .bar, .ev:focus-visible .bar { border-color: var(--c); }
.ev:focus-visible .bar { outline: 2px solid var(--accent); outline-offset: 2px; }
.ev.sel { z-index: 20; }
.ev.sel .bar, .ev.sel .marker { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 28%, transparent), var(--shadow); }
.ev .thumb { position: absolute; left: 8px; top: 3px; width: calc(var(--bar-t) - 9px); height: calc(var(--bar-t) - 9px); border-radius: calc(var(--radius) - 3px); background-size: cover; background-position: center; }
.ev.ongoing .bar { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 34px), transparent); }
#app[data-orient="v"] .ev.ongoing .bar { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 34px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 34px), transparent); }

.ev .marker { position: absolute; border-radius: 50%; background: var(--surface); border: 2px solid var(--c); box-shadow: var(--shadow-sm); overflow: hidden; }
.ev:hover .marker { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent), var(--shadow-sm); }
.ev .marker .dot { position: absolute; inset: 32%; border-radius: 50%; background: var(--c); }
.ev .marker .thumb { left: 0; top: 0; width: 100%; height: 100%; border-radius: 0; }

.ev .label { position: absolute; display: flex; flex-direction: column; justify-content: center; min-width: 0; overflow: hidden; pointer-events: auto; }
.ev .label .t { font: 600 13px/17px var(--font-body); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .label .d { font: 400 11px/15px var(--font-body); color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#app[data-orient="v"] .ev .label { justify-content: flex-start; }
#app[data-orient="v"] .ev .label .t { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

.handle { position: absolute; z-index: 3; cursor: ew-resize; touch-action: none; }
#app[data-orient="v"] .handle { cursor: ns-resize; }
.handle::after { content: ""; position: absolute; background: var(--surface); border: 2px solid var(--c); border-radius: 6px; box-shadow: var(--shadow-sm); }
#app[data-orient="h"] .handle::after { left: 4px; right: 4px; top: 5px; bottom: 5px; }
#app[data-orient="v"] .handle::after { top: 4px; bottom: 4px; left: 5px; right: 5px; }
.has-handle-img .handle::after { background: var(--asset-handle) center / contain no-repeat; border: 0; box-shadow: none; }
#app[data-orient="h"].has-handle-img .handle::after, #app[data-orient="v"].has-handle-img .handle::after { inset: 0; }

.chip, .chip-input { position: absolute; z-index: 30; border-radius: 6px; font: 600 11px/1.2 var(--font-body); white-space: nowrap; }
.chip { background: var(--ink); color: var(--surface); border: 0; padding: 4px 8px; cursor: text; box-shadow: var(--shadow-sm); }
.chip:hover { background: var(--accent); color: var(--accent-ink); }
.chip-input { background: var(--surface); border: 2px solid var(--accent); padding: 2px 4px; box-shadow: var(--shadow); }

#tip { position: absolute; z-index: 40; pointer-events: none; background: var(--ink); color: var(--surface); padding: 5px 10px; border-radius: 7px; font: 600 12px var(--font-body); white-space: nowrap; box-shadow: var(--shadow); }
#hint { position: absolute; z-index: 8; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 32px); background: color-mix(in srgb, var(--surface) 90%, transparent); color: var(--ink-soft); border: 1px solid var(--line); font-size: 12px; padding: 5px 12px; border-radius: 99px; pointer-events: none; text-align: center; transition: opacity .4s; }
#hint.gone { opacity: 0; }

/* ---------- inspector ---------- */
#inspector { width: 360px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line-strong); min-height: 0; }
.insp-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.insp-kicker { font: 600 12px var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; }
.icon-btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.insp-body { flex: 1; overflow: auto; padding: 14px 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.insp-foot { padding: 10px 16px; border-top: 1px solid var(--line); }
.fld { display: flex; flex-direction: column; gap: 5px; border: 0; padding: 0; margin: 0; min-width: 0; }
.fld > span, .fld > legend { font: 600 11px var(--font-body); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.fld input, .fld select, .fld textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 9px; }
.fld textarea { resize: vertical; }
.fld small, .muted { color: var(--ink-soft); font-size: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dur { color: var(--ink-soft); font-size: 12px; min-height: 16px; margin-top: -6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-person { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.chip-person button { border: 0; background: transparent; cursor: pointer; padding: 3px 9px; font-size: 12px; }
.chip-person .p-name { font-weight: 600; }
.chip-person .p-name:hover { color: var(--accent); }
.chip-person .p-x { border-left: 1px solid var(--line); padding: 3px 8px; color: var(--ink-soft); }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tile { position: relative; aspect-ratio: 4 / 3; border: 1px solid var(--line-strong); border-radius: 7px; padding: 0; cursor: pointer; background-size: cover; background-position: center; background-color: var(--surface-2); }
.tile:hover { border-color: var(--accent); }
.tile .play { position: absolute; inset: 0; margin: auto; width: 26px; height: 26px; border-radius: 50%; background: rgba(0, 0, 0, .55); }
.tile .play::after { content: ""; position: absolute; left: 10px; top: 7px; border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.tile .dur-badge { position: absolute; right: 4px; bottom: 4px; background: rgba(0, 0, 0, .65); color: #fff; font: 600 10px var(--font-body); padding: 1px 5px; border-radius: 4px; }
.file-btn { display: inline-block; align-self: flex-start; cursor: pointer; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--line-strong)); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: var(--danger); }

/* ---------- toast + lightbox ---------- */
#toast { position: fixed; z-index: 90; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; background: var(--ink); color: var(--surface); padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100% - 32px); font-size: 13px; }
#toast button { background: transparent; border: 0; color: var(--surface); font-weight: 700; cursor: pointer; text-decoration: underline; padding: 0; }
#lightbox { position: fixed; z-index: 100; inset: 0; background: rgba(8, 8, 10, .88); display: flex; align-items: center; justify-content: center; padding: 24px; }
#lightbox figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: min(92vw, 960px); }
#lightbox img { max-width: 100%; max-height: 76vh; border-radius: 8px; background: #222; }
#lightbox figcaption { color: #e8e8ea; font-size: 13px; text-align: center; max-width: 60ch; }
.lb-x, .lb-nav { position: absolute; background: rgba(255, 255, 255, .12); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 26px; line-height: 1; cursor: pointer; }
.lb-x:hover, .lb-nav:hover { background: rgba(255, 255, 255, .24); }
.lb-x { top: 16px; right: 16px; }
.lb-nav { top: 50%; margin-top: -22px; }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }

/* ---------- phones ---------- */
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 12px; }
  .controls { margin-left: 0; }
  .tag { display: none; }
  #inspector { position: absolute; z-index: 60; left: 0; right: 0; bottom: 0; width: auto; height: 64%; border-left: 0; border-top: 1px solid var(--line-strong); border-radius: 14px 14px 0 0; box-shadow: var(--shadow); }
  #hint { bottom: 8px; font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
