@font-face { font-family: "UI Thai"; src: url(/static/fonts/NotoSansThai-Medium.ttf); font-weight: 400 600; }
@font-face { font-family: "UI Thai"; src: url(/static/fonts/NotoSansThai-Bold.ttf); font-weight: 700 900; }

:root {
  --bg: #EEF1F4;
  --panel: #FFFFFF;
  --panel-2: #F6F8FA;
  --line: #DCE2E8;
  --ink: #13212E;
  --muted: #5E6E7C;
  --accent: #1C8FD6;
  --accent-ink: #FFFFFF;
  --navy: #0A3552;
  --ok: #1E9E6A;
  --warn: #C98A0B;
  --bad: #D2483B;
  --stale: #7A6BD1;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E151C; --panel: #151F29; --panel-2: #1B2733; --line: #283745; --ink: #E5EDF3; --muted: #93A6B6;
    --accent: #3BA7EA; --navy: #BFE2F7; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 "UI Thai", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 7px 14px; font-weight: 600; }
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--panel-2); border-radius: 9px; padding: 8px 11px; }
textarea { resize: vertical; min-height: 64px; }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* layout */
.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; margin-right: 6px; }
.brand i { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--navy)); display: inline-block; }
.topbar .name { max-width: 320px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar select { width: auto; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.main { display: grid; grid-template-columns: 260px minmax(380px, 1fr) minmax(340px, 440px); gap: 0; min-height: 0; }
.col { min-height: 0; overflow: auto; }
.col + .col { border-left: 1px solid var(--line); }

/* scene list */
.scenes { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.scene-item { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 10px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); cursor: pointer; text-align: left; font-weight: 500; }
.scene-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.scene-item .n { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--navy); color: var(--panel); font-weight: 800; font-size: 13px; }
.scene-item .t { font-weight: 700; font-size: 14px; line-height: 1.3; }
.scene-item .s { font-size: 12px; color: var(--muted); }
.vdot { width: 10px; height: 10px; border-radius: 50%; }
.vdot.ok { background: var(--ok); } .vdot.warn { background: var(--warn); } .vdot.stale { background: var(--stale); } .vdot.missing { background: transparent; border: 2px solid var(--muted); }
.add-row { display: flex; gap: 6px; padding: 0 12px 16px; }

/* editor */
.editor { padding: 18px 22px 40px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 .grow { flex: 1; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.fields .wide { grid-column: 1 / -1; }
.list-field { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; }
.list-item { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.list-item .inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.list-item .ops { display: flex; flex-direction: column; gap: 4px; }
.list-item .ops button { padding: 2px 8px; }
.img-field { display: flex; gap: 10px; align-items: center; }
.img-field img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.icon-pick { display: flex; gap: 8px; align-items: center; }
.icon-pick img { width: 26px; height: 26px; filter: invert(var(--icon-invert, 0)); }
@media (prefers-color-scheme: dark) { .icon-pick img { --icon-invert: 1; } }
.voice-box textarea { min-height: 80px; font-size: 16px; }
.spoken { background: var(--panel-2); border-radius: 9px; padding: 8px 11px; font-size: 14px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.warn-box { border-left: 4px solid var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.stale-box { border-left: 4px solid var(--stale); background: color-mix(in srgb, var(--stale) 12%, transparent); padding: 8px 12px; border-radius: 6px; font-size: 14px; }
details.card summary { cursor: pointer; font-weight: 700; }
audio { width: 100%; height: 36px; }

/* preview */
.preview { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.stage { width: 100%; aspect-ratio: 9 / 16; max-height: 68vh; margin: 0 auto; border-radius: 14px; overflow: hidden; background: #111; border: 1px solid var(--line); }
.stage iframe { width: 100%; height: 100%; border: 0; display: block; }
.transport { display: flex; align-items: center; gap: 10px; }
.transport input[type=range] { flex: 1; accent-color: var(--accent); }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); min-width: 92px; text-align: right; }
.renders { display: flex; flex-direction: column; gap: 8px; }
.render-item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.render-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); padding: 0; width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 15, 25, .45); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 17px; flex: 1; }
.dlg-body { padding: 16px 18px; max-height: 70vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table td, .table th { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.voice-card { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.voice-card.sel { border-color: var(--accent); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy); color: var(--panel); padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 99; max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 1100px) {
  .main { grid-template-columns: 220px 1fr; }
  .main .preview { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .app { height: auto; }
  .col { overflow: visible; }
}
@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; }
  .col + .col { border-left: 0; border-top: 1px solid var(--line); }
  .fields { grid-template-columns: 1fr; }
}

.font-preview { margin-top: 6px; padding: 8px 12px; border-radius: 9px; background: var(--panel-2); font-size: 22px; line-height: 1.35; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-preview small { display: block; font-size: 14px; color: var(--muted); }
.fields > * { min-width: 0; }

.ai-log { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; }
.ai-msg { padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5; max-width: 92%; }
.ai-msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.ai-msg.ai { align-self: flex-start; background: var(--panel-2); }
.ai-msg.system { align-self: center; color: var(--muted); font-size: 13px; }
#ai-box textarea { min-height: 56px; }
