/* SwitFire Web — สีทั้งหมดมาจากธีม (ตัวแปร --*) */
:root { --panel:#1C1C22; --dialog:#1E1E26; --row:#2A2A34; --chip:#2C2C36; --ink:#fff; --accent:#6B5CF5; --on:#fff; --soft:#B9B2FF;
  --sub:rgba(255,255,255,.62); --border:rgba(255,255,255,.12); --hover:rgba(255,255,255,.28); --warn:#FFD166; --ok:#34C759;
  --font:'Leelawadee UI','Noto Sans Thai',sans-serif; color-scheme: dark; }
[data-light="1"] { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--panel); color: var(--ink); font: 14px/1.5 var(--font); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
.ic { flex: none; display: block; }
#app { display: grid; grid-template-rows: 1fr auto auto; height: 100%; }

/* ---------- เวที ---------- */
#stage { position: relative; background: #000; overflow: hidden; min-height: 0; user-select: none; }
#stage video, #stage img.still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#stage.aspect-fill video, #stage.aspect-fill img.still { object-fit: fill; }
#ov { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#stage.drawing #ov, #stage.editing #ov { cursor: crosshair; }
#subs { position: absolute; inset: 0; display: none; flex-direction: column; justify-content: flex-end; gap: .35em; padding: 4vh 5vw; background: #000; color: #fff; text-align: center; }
#stage.subtitle-mode #subs { display: flex; }
#subs .ln { font-weight: 600; text-shadow: 0 2px 4px #000; opacity: .45; }
#subs .ln.cur { opacity: 1; }
#subs .ln small { display: block; font-size: .45em; opacity: .7; font-weight: 400; }

#start { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(ellipse at top, color-mix(in srgb, var(--accent) 22%, var(--panel)), var(--panel) 70%); overflow: auto; }
#start.hidden { display: none; }
.hero { max-width: 760px; width: 100%; text-align: center; }
.hero img { width: 72px; height: 72px; border-radius: 18px; }
.hero h1 { margin: 10px 0 2px; font-size: 28px; }
.hero p { color: var(--sub); margin: 0 0 22px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--dialog); border: 1px solid var(--border); border-radius: 16px; padding: 18px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .ic { color: var(--accent); }
.card b { font-size: 15px; }
.card span { color: var(--sub); font-size: 12px; }
.hero .warnbox { margin-top: 16px; }

/* ---------- แถบเครื่องมือ ---------- */
#toolbar { display: flex; align-items: center; gap: 6px; padding: 7px 8px; overflow-x: auto; scrollbar-width: none; background: var(--panel); border-top: 1px solid var(--border); min-width: 0; }
.tb { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; min-width: 38px; padding: 0 9px; border-radius: 10px; border: 1px solid transparent; background: var(--chip); cursor: pointer; white-space: nowrap; }
.tb:hover { background: var(--row); border-color: var(--border); }
.tb.on { background: var(--accent); color: var(--on); }
.tb:disabled { opacity: .45; cursor: default; }
.tb { flex: none; }
#statusChip { flex: 1 1 auto; }
@media (max-width: 720px) { #statusChip span:last-child { display: none; } #statusChip { flex: 0 0 auto; min-width: 38px; } #statusbar { justify-content: flex-start; overflow-x: auto; } }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 3px; flex: none; }
#statusChip { flex: 1; min-width: 60px; justify-content: flex-start; background: transparent; color: var(--sub); overflow: hidden; }
#statusChip span { overflow: hidden; text-overflow: ellipsis; }
#statusChip.warn { color: var(--warn); }
.badge { background: #B45309; color: #fff; border-radius: 8px; padding: 3px 8px; font-size: 12px; white-space: nowrap; }
.badge[hidden] { display: none; }
#langBtn .chev { opacity: .7; }

#statusbar { display: flex; align-items: center; gap: 4px; justify-content: flex-end; padding: 3px 10px; font-size: 12px; color: var(--sub); background: var(--panel); border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; }
.chip[hidden] { display: none; }
.meter { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.meter i { width: 4px; border-radius: 1.5px; background: var(--chip); }
[data-light="1"] .meter i { background: #D4D4D8; }
.meter i.on { background: var(--accent); }
.meter i.hot { background: #F59E0B; }

/* ---------- เมนู ---------- */
.menu { position: fixed; z-index: 50; min-width: 240px; max-height: 70vh; overflow: auto; background: var(--dialog); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.menu h6 { margin: 6px 10px 2px; font-size: 12px; color: var(--soft); }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; text-align: left; padding: 6px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--accent); color: var(--on); }
.menu button .tick { width: 16px; display: inline-flex; }
.menu hr { border: 0; height: 1px; background: var(--border); margin: 4px 6px; }

/* ---------- กล่องโต้ตอบ ---------- */
dialog { padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--dialog); color: var(--ink); box-shadow: 0 24px 80px rgba(0,0,0,.45); max-width: min(1120px, 96vw); max-height: 92vh; width: 100%; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog.panel { position: fixed; margin: 0; inset: auto; resize: both; overflow: hidden; min-width: 360px; min-height: 240px; max-width: 98vw; max-height: 96vh; }
dialog.panel .dlg { height: 100%; max-height: none; }
dialog.panel header { cursor: move; user-select: none; touch-action: none; }
dialog.panel header::before { content: ''; width: 14px; height: 14px; flex: none; opacity: .45; background: radial-gradient(circle, currentColor 1.2px, transparent 1.6px) 0 0 / 5px 5px; }
#settings.panel { width: min(1120px, 96vw); height: min(800px, 92vh); }
#settings.panel .dlg { height: 100%; }
#regions.panel { width: min(1060px, 96vw); height: min(720px, 90vh); }
#history.panel { width: min(760px, 96vw); height: min(640px, 90vh); }
dialog.small { max-width: 560px; }
.dlg { display: flex; flex-direction: column; max-height: 92vh; }
.dlg header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dlg header h2 { margin: 0; font-size: 16px; flex: 1; }
.dlg .body { overflow: auto; padding: 16px 20px 24px; }
.dlg footer { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--border); }
.x { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--sub); }
.x:hover { background: var(--row); color: var(--ink); }

#settings .dlg { flex-direction: row; height: 100%; }
#settings nav { width: 290px; flex: none; padding: 10px 8px; border-right: 1px solid var(--border); background: var(--panel); overflow: auto; border-radius: 16px 0 0 16px; }
#settings nav button { display: flex; gap: 12px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 10px; cursor: pointer; margin: 2px 0; }
#settings nav button:hover { background: var(--row); }
#settings nav button.on { background: var(--chip); }
#settings nav b { display: block; font-size: 14px; }
#settings nav small { display: block; color: var(--sub); font-size: 11px; line-height: 1.4; }
#settings .main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#settings .main > .body { flex: 1; }

/* ---------- ฟอร์ม ---------- */
.page h3 { font-size: 15px; margin: 20px 0 8px; }
.page h3:first-child { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 8px 0; }
.row > label:first-child { white-space: nowrap; }
.row .grow { flex: 1; min-width: 200px; }
.note { color: var(--sub); font-size: 12px; margin: 4px 0 8px; }
.note.warn, .warnbox { color: var(--warn); }
.note.ok { color: var(--ok); }
.warnbox { border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=email], select, textarea {
  background: var(--row); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; min-height: 34px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input:hover, select:hover, textarea:hover { border-color: var(--hover); }
select { padding-right: 28px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; }
select option { background: var(--dialog); color: var(--ink); }
input[type=number] { width: 96px; }
textarea { width: 100%; min-height: 140px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; resize: vertical; }
input.key { width: 360px; max-width: 100%; font-family: ui-monospace, Consolas, monospace; }
.check { display: flex; align-items: center; gap: 10px; margin: 8px 0; cursor: pointer; }
.check input { appearance: none; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--hover); background: var(--row); display: grid; place-content: center; flex: none; margin: 0; cursor: pointer; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ''; width: 10px; height: 6px; border: solid var(--on); border-width: 0 0 2.5px 2.5px; transform: translateY(-1px) rotate(-45deg); }
input[type=range] { width: 100%; appearance: none; background: transparent; height: 22px; margin: 2px 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill, 0%) 100% no-repeat, var(--chip); }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 50%; background: var(--accent); border: 2px solid var(--dialog); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--chip); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--dialog); }
.btn { display: inline-flex; align-items: center; gap: 7px; background: var(--accent); color: var(--on); border: 1px solid var(--accent); border-radius: 10px; padding: 7px 14px; min-height: 34px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.1); }
.btn.outline { background: transparent; color: var(--ink); border-color: var(--border); }
.btn.outline:hover { background: var(--row); border-color: var(--hover); filter: none; }
.btn.danger { background: transparent; color: #F87171; border-color: color-mix(in srgb, #F87171 50%, transparent); }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.theme { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: transparent; cursor: pointer; text-align: left; }
.theme.on { border-color: var(--accent); background: var(--row); }
.theme .sw { display: flex; gap: 3px; }
.theme .sw i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(127,127,127,.4); }
.theme small { display: block; color: var(--sub); }
.list { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.list .it { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list .it:last-child { border-bottom: 0; }
.list .it:hover { background: var(--row); }
.list .it.on { background: var(--chip); }
.list .it .grow { flex: 1; min-width: 0; }
.list .it small { color: var(--sub); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.on { border-color: var(--ink); }
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } #settings nav { width: 72px; } #settings nav small, #settings nav b { display: none; } }
.hist .it { cursor: default; align-items: flex-start; }
.hist .it .o { color: var(--sub); font-size: 12px; white-space: pre-wrap; }
.hist .it .t { white-space: pre-wrap; }
pre.log { font: 12px/1.45 ui-monospace, Consolas, monospace; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; max-height: 50vh; overflow: auto; white-space: pre-wrap; margin: 0; }
.kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--dialog); border: 1px solid var(--border); padding: 10px 16px; border-radius: 12px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.35); max-width: 90vw; }
.progress { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hover); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
body.fs #toolbar, body.fs #statusbar { display: none; }
