:root {
  --bg: #0e0f13;
  --panel: #171922;
  --panel-2: #1f2230;
  --border: #2a2e3e;
  --text: #e7e9f0;
  --muted: #9aa0b4;
  --accent: #6c8bff;
  --accent-2: #4f6fef;
  --ok: #38d39f;
  --err: #ff6b6b;
  --radius: 8px;     /* panel / card */
  --radius-sm: 5px;  /* input / button / control */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Google Sans Flex', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #14161f, #0e0f13);
}
.brand { font-size: 18px; font-weight: 700; }
.brand span { color: var(--accent); font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; }

.layout {
  flex: 1; display: grid; grid-template-columns: 380px 1fr; gap: 18px;
  padding: 18px; min-height: 0;
}
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.controls { overflow-y: auto; }
.preview { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }

.step { padding: 14px 0; border-bottom: 1px dashed var(--border); }
.step:last-child { border-bottom: none; }
.step.disabled { opacity: .4; pointer-events: none; }
.step h3 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.num {
  display: inline-flex; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-2); color: #fff; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}

.row { display: flex; gap: 8px; }
input[type="text"] {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }

button {
  cursor: pointer; border: none; border-radius: var(--radius-sm); font-size: 14px;
  padding: 10px 16px; font-weight: 600; color: #fff; background: var(--panel-2);
  transition: .15s;
}
button.primary { background: var(--accent-2); }
button.primary:hover { background: var(--accent); }
button.big { width: 100%; padding: 13px; font-size: 15px; margin-top: 4px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.filelabel {
  display: block; margin: 12px 0 6px; font-size: 13px; color: var(--muted);
}
.filelabel span { display: block; margin-bottom: 6px; }
input[type="file"] { font-size: 12px; color: var(--muted); width: 100%; }

.sliders { margin: 10px 0; }
.sliders label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.sliders output { color: var(--accent); font-weight: 600; float: right; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.tip { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---- Thu vien logo/frame ---- */
.lib { margin-top: 14px; }
.lib-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--muted); margin-bottom: 8px;
}
.upbtn {
  cursor: pointer; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--accent); font-weight: 600; font-size: 12px;
  padding: 4px 10px; border-radius: var(--radius-sm);
}
.upbtn:hover { border-color: var(--accent); }
.grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.thumb {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm);
  border: 2px solid var(--border); background: #0b0c10 center/contain no-repeat;
  background-image:
    linear-gradient(45deg, #20222e 25%, transparent 25%),
    linear-gradient(-45deg, #20222e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20222e 75%),
    linear-gradient(-45deg, transparent 75%, #20222e 75%);
  background-size: 12px 12px; background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  cursor: pointer; overflow: hidden;
}
.thumb img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
}
.thumb.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,139,255,.35); }
.thumb-del {
  position: absolute; top: 2px; right: 2px; z-index: 2;
  width: 18px; height: 18px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 1;
  padding: 0; display: flex; align-items: center; justify-content: center;
}
.thumb-del:hover { background: var(--err); }
.grid-empty { grid-column: 1 / -1; color: var(--muted); font-size: 12px; padding: 8px 0; }

/* ---- Danh sach video da tai ---- */
.vidlib { margin-top: 14px; }
.vidlist { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.vitem {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px; position: relative;
}
.vitem:hover { border-color: var(--accent); }
.vitem.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.vthumb {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 4px;
  background: #000 center/cover no-repeat; border: 1px solid var(--border);
}
.vmeta { min-width: 0; flex: 1; }
.vtitle { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vsub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.vdel {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; padding: 0;
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.vdel:hover { background: var(--err); border-color: var(--err); color: #fff; }

/* ---- Voiceover ---- */
.voiceover { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.voiceover textarea {
  width: 100%; min-height: 70px; resize: vertical; margin-top: 4px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
}
.voiceover textarea:focus { outline: none; border-color: var(--accent); }
.vrow { display: flex; gap: 8px; margin-top: 8px; }
.vrow select {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 10px; border-radius: var(--radius-sm); font-size: 13px;
}
.ratelbl { display: block; font-size: 13px; color: var(--muted); margin-top: 12px; }
.ratelbl output { color: var(--accent); font-weight: 600; float: right; }

.status { font-size: 13px; margin-top: 10px; min-height: 18px; }
.status.loading { color: var(--accent); }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.download {
  display: inline-block; margin-top: 12px; padding: 11px 16px; border-radius: var(--radius-sm);
  background: var(--ok); color: #06281f; font-weight: 700; text-decoration: none; width: 100%;
  text-align: center;
}

.stage-wrap { display: flex; align-items: center; justify-content: center; width: 100%; }
.placeholder { color: var(--muted); text-align: center; padding: 60px 20px; }

.stage {
  position: relative; border-radius: var(--radius-sm); overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); background: #000;
  touch-action: none; user-select: none;
}
.preview-img { display: block; width: 100%; height: 100%; }
.frame-img {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
}
.logo-img {
  position: absolute; cursor: grab; left: 0; top: 0;
  outline: 1px dashed rgba(108,139,255,.8); outline-offset: 2px;
}
.logo-img:active { cursor: grabbing; }

.result { max-height: 78vh; border-radius: var(--radius-sm); background: #000; }

.foot {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 10px; border-top: 1px solid var(--border);
}

/* ---- Topbar phai + dang nhap ---- */
.topright { display: flex; align-items: center; gap: 12px; }
.user-chip {
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: var(--radius-sm); font-size: 13px; color: var(--text);
}
button.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 6px 14px; font-size: 13px;
}
button.ghost:hover { border-color: var(--accent); color: var(--text); }

.auth-screen {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.auth-card h2 { margin: 0 0 2px; font-size: 22px; }
.auth-sub { margin: 0 0 20px; color: var(--accent); font-size: 13px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.auth-card input {
  display: block; width: 100%; margin-top: 6px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text);
  padding: 11px 12px; border-radius: var(--radius-sm); font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-error { color: var(--err); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin: 16px 0 0; }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 600; margin-left: 4px; }

/* ---- Cai dat / Ket noi ---- */
#settings-screen { flex: 1; padding: 24px; overflow-y: auto; }
.settings-wrap { max-width: 640px; margin: 0 auto; }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h2 { margin: 0; font-size: 22px; }
.settings-sub { color: var(--muted); font-size: 13px; margin: 6px 0 20px; }
.conn-cards { display: flex; flex-direction: column; gap: 12px; }
.conn-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.conn-ico { font-size: 28px; width: 36px; text-align: center; }
.conn-body { flex: 1; }
.conn-name { font-weight: 600; font-size: 15px; }
.conn-note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.conn-act { display: flex; align-items: center; gap: 8px; }
.conn-on { color: var(--ok); font-size: 13px; font-weight: 600; }
.conn-soon { color: var(--muted); font-size: 12px; font-style: italic; }

/* ---- Day nhap ---- */
.publish-area { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.publish-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.publish-area input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 8px;
}
.publish-area input:focus { outline: none; border-color: var(--accent); }
#publish-btns { display: flex; flex-direction: column; gap: 8px; }
.pub-btn { width: 100%; }
#publish-status a { color: var(--accent); font-weight: 600; }

/* ===== Icon SVG ===== */
.ic { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; flex: 0 0 auto; }
.ic-wrap { display: inline-flex; align-items: center; }
.spin { animation: ic-spin .8s linear infinite; }
@keyframes ic-spin { to { transform: rotate(360deg); } }

button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-ic { color: var(--accent); }
.user-chip { display: inline-flex; align-items: center; gap: 6px; }
.upbtn { display: inline-flex; align-items: center; gap: 4px; }
.download { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.status { display: flex; align-items: center; gap: 6px; }
.status:empty { display: none; }

/* ===== List view (danh sach project) ===== */
.listwrap { max-width: 1000px; margin: 0 auto; padding: 20px 18px; display: flex; flex-direction: column; gap: 18px; }
.panel h3, .create h3 { margin: 0 0 12px; font-size: 15px; }
.create .row { align-items: stretch; }

.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.pgrid-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.pcard {
  position: relative; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: .15s;
}
.pcard:hover { border-color: var(--accent); transform: translateY(-2px); }
.pcard-thumb { aspect-ratio: 16 / 10; background: #000 center/cover no-repeat; }
.pcard-body { padding: 10px 12px; }
.pcard-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }
.pbadge {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  background: var(--accent-2); color: #fff; font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.pcard-del {
  position: absolute; top: 6px; right: 6px; z-index: 2; width: 26px; height: 26px;
  border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; padding: 0;
  opacity: 0; transition: .15s;
}
.pcard:hover .pcard-del { opacity: 1; }
.pcard-del:hover { background: var(--err); }

/* ===== Detail view ===== */
.detail-top { display: flex; align-items: center; gap: 14px; padding: 14px 18px 0; }
.detail-title { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
