:root {
  --bg: #0f1417; --panel: #171e23; --panel2: #1e272d; --line: #2a353c;
  --text: #e7edf0; --muted: #8a9aa3; --primary: #1f9e8f; --primary-d: #157567;
  --warn: #f4a259; --danger: #e36;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Noto Sans Thai', 'Poppins', system-ui, sans-serif; font-size: 14px;
  height: 100vh; display: flex; flex-direction: column; overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }

/* topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar__brand { font-weight: 700; font-size: 16px; }
.topbar__brand span { color: var(--muted); font-weight: 400; }
.topbar__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { font-size: 12px; color: var(--muted); background: var(--panel2); padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); }
.chip--warn { color: var(--warn); border-color: var(--warn); }
.chip--ok { color: #5fd0a0; border-color: #2f7d63; }

/* cloud login modal */
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 10px; }
.login-card h3 { margin: 0; }
.login-hint { color: var(--muted); font-size: 12px; margin: 0; }
.login-input { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit; }
.login-input:focus { outline: none; border-color: var(--primary); }
.login-err { color: var(--danger); font-size: 12px; min-height: 14px; }
.login-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.btn-bar { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font-size: 13px; }
.btn-bar:hover { border-color: var(--primary); }
.btn-bar--primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.btn-bar--ai { background: linear-gradient(135deg, #7b5cff, #c44bff); border-color: transparent; color: #fff; font-weight: 700; }
.btn-bar--ai:hover { filter: brightness(1.08); }
.btn-bar--ai:disabled { opacity: .6; }
.ai-card h3 { background: linear-gradient(135deg, #9b7bff, #d98bff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ai-games { display: flex; gap: 6px; margin-bottom: 4px; }
.ai-games .form-tab { flex: 1; }
.ai-card .login-input { margin-bottom: 4px; }
.ai-label { font-size: 12px; color: var(--muted); margin-top: 6px; display: block; }
.ai-status { font-size: 12px; min-height: 16px; color: var(--muted); }
.ai-status.is-err { color: var(--danger); }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: 240px 1fr 1fr; min-height: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 14px; overflow-y: auto; }
.sidebar__title { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.theme-list { display: flex; flex-direction: column; gap: 6px; }
.theme-row { display: flex; gap: 4px; align-items: stretch; }
.theme-row__open { flex: 1; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.theme-row__open:hover { border-color: var(--primary); }
.theme-row__open small { color: var(--muted); font-size: 11px; }
.muted { color: var(--muted); font-size: 13px; }

/* editor form */
.editor { overflow-y: auto; padding: 14px; border-right: 1px solid var(--line); }
.form-tabs { display: flex; gap: 6px; position: sticky; top: -14px; background: var(--bg); padding: 10px 0; margin: -4px 0 10px; z-index: 5; border-bottom: 1px solid var(--line); }
.form-tab { flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); border-radius: 9px; padding: 10px 8px; font-size: 13px; font-weight: 700; transition: all .12s; }
.form-tab:hover { border-color: var(--primary); color: var(--text); }
.form-tab.is-active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 40%, transparent); }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.section__head { cursor: pointer; padding: 12px 14px; font-weight: 700; user-select: none; list-style: none; }
.section__head::-webkit-details-marker { display: none; }
.section__body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field__label { font-size: 12px; color: var(--muted); }
.field input[type=text], .field input[type=number], .field textarea, .field select {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--primary); }
.field__hint { font-size: 11px; color: var(--muted); }
.field__color { display: flex; gap: 8px; align-items: center; }
.field__color input[type=color] { width: 42px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; }
.field__hex { max-width: 120px; }
.field__switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.field__grid { display: flex; align-items: center; gap: 8px; }
.field__grid-n { max-width: 70px; }

/* asset uploader */
.asset { display: flex; gap: 10px; align-items: center; }
.asset__preview { width: 56px; height: 56px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2) center/contain no-repeat; display: grid; place-items: center; color: var(--muted); flex: 0 0 auto; }
.asset__preview--audio { font-size: 18px; }
.asset__btns { display: flex; gap: 6px; align-items: center; }
.asset__file { display: none; }
.btn-mini { background: var(--primary); color: #fff; border: 0; border-radius: 7px; padding: 6px 10px; font-size: 12px; }
.btn-mini--ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }

/* socials + cards */
.socials { display: flex; flex-direction: column; gap: 6px; }
.socials__row { display: flex; gap: 6px; }
.socials__row select { max-width: 120px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 8px; margin-bottom: 8px; }
.card-cell { position: relative; }
.card-thumb { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2) center/cover no-repeat; cursor: pointer; }
.card-thumb:hover { border-color: var(--primary); }
.card-thumb__del { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 11px; line-height: 1; }

/* hunter scenes editor */
.scenes-editor { display: flex; flex-direction: column; gap: 10px; }
.scene-row { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.scene-row__top { display: flex; gap: 6px; }
.scene-row__top input { flex: 1; }
.scene-row__imgs { display: flex; gap: 10px; }
.scene-thumb-wrap { display: flex; flex-direction: column; gap: 2px; align-items: center; flex: 1; }
.scene-thumb-wrap small { color: var(--muted); font-size: 11px; }
.scene-thumb { width: 100%; aspect-ratio: 4/3; border-radius: 8px; border: 1px solid var(--line); background: #0a0e10 center/cover no-repeat; cursor: pointer; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.scene-thumb:hover { border-color: var(--primary); }
.scene-warn { color: var(--warn); font-size: 12px; background: rgba(244,162,89,.12); border: 1px solid var(--warn); border-radius: 6px; padding: 4px 8px; }

/* visual difference picker (modal) */
.diff-editor { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.7); display: grid; place-items: center; padding: 20px; }
.diff-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; width: min(1000px, 96vw); max-height: 92vh; overflow: auto; }
.diff-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.diff-head b { flex: 1; }
.diff-count { color: var(--primary); font-weight: 700; font-size: 13px; }
.diff-hint { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.diff-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.diff-col { display: flex; flex-direction: column; gap: 4px; }
.diff-col small { color: var(--muted); font-size: 12px; }
.diff-stage { position: relative; cursor: crosshair; border-radius: 8px; overflow: hidden; border: 2px solid var(--primary); }
.diff-img { width: 100%; display: block; }
.diff-img--ref { border-radius: 8px; border: 1px solid var(--line); }
.diff-markers { position: absolute; inset: 0; }
.diff-dot { position: absolute; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; border: 2px solid #ffd23f; background: rgba(255,210,63,.25); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; cursor: pointer; box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
.diff-dot:hover { background: rgba(230,60,80,.4); border-color: #e36; }
@media (max-width: 760px) { .diff-body { grid-template-columns: 1fr; } }

/* project library (gallery) */
.proj-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: min(960px, 96vw); max-height: 92vh; overflow: auto; }
.proj-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.proj-head b { font-size: 16px; }
.proj-hint { flex: 1; color: var(--muted); font-size: 12px; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.proj-item { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.proj-thumb { aspect-ratio: 16/10; display: grid; place-items: center; position: relative; }
.proj-logo { width: 46%; height: 60%; background: center/contain no-repeat; }
.proj-thumb-title { font-family: 'Poppins'; font-weight: 800; color: #fff; font-size: 18px; text-shadow: 0 1px 6px rgba(0,0,0,.4); padding: 8px; text-align: center; }
.proj-meta { padding: 8px 10px 4px; display: flex; flex-direction: column; gap: 2px; }
.proj-meta b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-meta small { color: var(--muted); font-size: 11px; }
.proj-actions { display: flex; gap: 4px; padding: 6px 8px 8px; flex-wrap: wrap; }
.proj-actions .btn-mini { padding: 5px 9px; font-size: 12px; }
.proj-item--new { border: 1px dashed var(--line); background: transparent; color: var(--muted); align-items: center; justify-content: center; gap: 8px; cursor: pointer; min-height: 150px; font-weight: 700; }
.proj-item--new:hover { border-color: var(--primary); color: var(--text); }
.proj-new { font-size: 32px; line-height: 1; }

/* preview */
.preview-pane { display: flex; flex-direction: column; min-height: 0; background: #0a0e10; }
.preview-pane__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.seg { display: flex; background: var(--panel2); border-radius: 8px; border: 1px solid var(--line); overflow: hidden; }
.seg button { background: none; border: 0; color: var(--muted); padding: 6px 12px; font-size: 13px; }
.seg button.is-active { background: var(--primary); color: #fff; }
.preview-stage { flex: 1; display: grid; place-items: center; padding: 16px; overflow: auto; }
.preview-frame { background: #000; border-radius: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: hidden; border: 6px solid #222; }
.preview-frame.is-portrait { width: min(360px, 90%); aspect-ratio: 9 / 16; }
.preview-frame.is-landscape { width: min(640px, 100%); aspect-ratio: 16 / 9; }
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* statusbar */
.statusbar { padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.statusbar .is-err { color: var(--danger); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; overflow-y: auto; }
  .sidebar, .editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-pane { min-height: 60vh; }
}
