/* KaiTik-aligned design tokens (mint + lavender on deep slate) */
:root {
  --bg: #0a0c10;
  --bg-2: #141922;
  --bg-3: #1a212c;
  --bg-4: #212a36;
  --border: #212a36;
  --text: #f5f7fb;
  --text-dim: #9aa3b2;
  --text-mute: #727c8c;
  --accent: #34e3a3;
  --accent-2: #8b9bff;
  --accent-soft: rgba(52, 227, 163, 0.15);
  --accent-ink: #04231a;
  --gold: #f5c451;
  --radius: 14px;
  --radius-xl: 16px;
  --shadow-card: 0 8px 30px -12px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Prompt', 'Noto Sans Thai', system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(900px 400px at 85% -10%, rgba(52, 227, 163, 0.07), transparent 60%),
    radial-gradient(700px 380px at -10% 20%, rgba(139, 155, 255, 0.06), transparent 60%);
  background-attachment: fixed;
}

/* ========== ล็อกความสูงจอตอนอยู่ใน Editor (กัน scroll ทั้งหน้า) ========== */
html.kaisub-editor-open {
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}
body.kaisub-editor-open {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden !important;
  overscroll-behavior: none;
  /* กัน bounce/scroll บน iOS */
  position: fixed;
  inset: 0;
  width: 100%;
}
body.kaisub-editor-open .ann-host {
  flex: 0 0 auto;
  position: relative;
  top: auto;
  z-index: 80;
}
body.kaisub-editor-open .kt-header {
  flex: 0 0 auto;
}
/* ขั้นตอนอื่นซ่อนอยู่ — editor เติมพื้นที่ที่เหลือใต้ header */
body.kaisub-editor-open #step-upload,
body.kaisub-editor-open #step-processing,
body.kaisub-editor-open #step-render {
  display: none !important;
}
::selection { background: rgba(52, 227, 163, 0.3); }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #2c3745; }

.step { display: none; }
.step.active { display: block; }

.text-gradient {
  background: linear-gradient(100deg, #34e3a3 10%, #8b9bff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

@keyframes fadeUp {
  0% { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
.anim-up { animation: fadeUp 0.55s cubic-bezier(0.22, 1, 0.36, 1) both; }
.anim-pop { animation: popIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both; }
.d-1 { animation-delay: 0.06s; }
.d-2 { animation-delay: 0.12s; }
.d-3 { animation-delay: 0.18s; }
.d-4 { animation-delay: 0.24s; }

.card-hover {
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.card-hover:hover {
  transform: translateY(-2px);
  border-color: rgba(52, 227, 163, 0.35);
  box-shadow: var(--shadow-card);
}
.btn-press {
  transition: transform 0.12s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}
.btn-press:hover:not(:disabled) {
  box-shadow: 0 4px 18px -6px rgba(52, 227, 163, 0.45);
}
.btn-press:active:not(:disabled) { transform: scale(0.97); }

/* ================= แถบหัวเว็บ KaiTik (บางๆ ด้านบนสุด ทุกขั้นตอน) ================= */
/* ================= ประกาศจากแอดมิน (marquee เต็มความกว้าง) ================= */
.ann-host {
  position: sticky;
  top: 0;
  z-index: 80;
  width: 100%;
  box-shadow: 0 4px 20px rgba(245, 196, 81, 0.12);
}
.ann-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(245, 196, 81, 0.4);
  background: linear-gradient(90deg, #3a2a0a, #2a1f08, #3a2a0a);
  box-sizing: border-box;
}
.ann-bar.tone-1 {
  border-color: rgba(52, 227, 163, 0.35);
  background: linear-gradient(90deg, #0f2b22, #0a1f18, #0f2b22);
}
.ann-bar.tone-2 {
  border-color: rgba(139, 155, 255, 0.4);
  background: linear-gradient(90deg, #1a1530, #12102a, #1a1530);
}
.ann-badge {
  flex-shrink: 0;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--gold);
  color: #2a1e05;
  white-space: nowrap;
}
.ann-bar.tone-1 .ann-badge { background: var(--accent); color: var(--accent-ink); }
.ann-bar.tone-2 .ann-badge { background: var(--accent-2); color: #0a0c10; }
.ann-track {
  position: relative;
  flex: 1 1 0%;
  min-width: 0;
  overflow: hidden;
  mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
}
.ann-marquee {
  display: inline-flex;
  width: max-content;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
  color: #ffe7a0;
  will-change: transform;
  animation: annMarquee 28s linear infinite;
}
.ann-bar.tone-1 .ann-marquee { color: #a7f3d0; }
.ann-bar.tone-2 .ann-marquee { color: #c7d2fe; }
.ann-marquee-chunk {
  display: inline-block;
  flex-shrink: 0;
  white-space: nowrap;
}
.ann-track:hover .ann-marquee { animation-play-state: paused; }
.ann-close {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: #ffe7a0;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.ann-close:hover { background: rgba(0, 0, 0, 0.45); color: #fff; }
@keyframes annMarquee {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .ann-marquee { animation: none !important; }
}

.kt-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 20px; font-size: 12px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  color: var(--text-dim);
}
.kt-header-brand {
  font-weight: 800; font-size: 12.5px; text-decoration: none; color: var(--text);
  letter-spacing: -0.01em;
}
.kt-header-brand b {
  background: linear-gradient(100deg, #34e3a3 10%, #8b9bff 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.kt-header-brand span { color: var(--text-mute); font-weight: 600; }
.kt-header-sep { color: var(--text-mute); }
.kt-header-current { color: var(--text-dim); font-weight: 600; }
.kt-header-link {
  margin-left: auto; color: var(--accent); text-decoration: none; font-weight: 700; font-size: 11.5px;
  white-space: nowrap;
}
.kt-header-link:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .kt-header {
    flex-wrap: wrap; gap: 4px 8px; padding: 8px 12px; font-size: 11px;
  }
  .kt-header-current { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kt-header-link { margin-left: 0; width: 100%; text-align: right; padding: 4px 0; }
  .topbar { padding: 12px 14px; }
  .upload-body { padding: 20px 14px 48px; }
  .hero-sub { font-size: 14px; padding: 0 4px; }
  .dropzone { padding: 36px 16px; }
  .dz-main { font-size: 16px; }
  .quota-card {
    border-radius: 16px; padding: 12px 14px; flex-direction: column; gap: 6px;
    text-align: center;
  }
  .lang-row { flex-wrap: wrap; gap: 8px; }
  .lang-row select { width: 100%; max-width: 280px; }
}

/* ================= การ์ดโควต้า/แผน (โชว์บนหน้าอัปโหลด) ================= */
.quota-card {
  display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 8px 10px; margin: 16px auto 0; padding: 10px 18px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--bg-2);
  font-size: 13px; color: var(--text-dim); max-width: 100%;
}
.quota-card .quota-text { color: var(--text-dim); }
.quota-card .quota-text b { color: var(--text); font-weight: 800; }
.quota-card .quota-reset { color: var(--text-mute); font-size: 11.5px; }
.quota-plan-badge {
  font-size: 11px; font-weight: 800; letter-spacing: 0.03em;
  border-radius: 999px; padding: 3px 11px; white-space: nowrap;
}
/* Free: เรียบ ๆ */
.quota-card.plan-free .quota-plan-badge { background: var(--bg-3); color: var(--text-dim); border: 1px solid var(--border); }
.quota-card.plan-anonymous .quota-plan-badge { background: var(--bg-3); color: var(--text-mute); border: 1px solid var(--border); }
/* Standard: โทนเขียวของแบรนด์ */
.quota-card.plan-standard {
  border-color: rgba(52, 227, 163, 0.35);
  background: linear-gradient(180deg, rgba(52, 227, 163, 0.08), transparent 60%), var(--bg-2);
}
.quota-card.plan-standard .quota-plan-badge {
  background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(52, 227, 163, 0.45);
}
/* Pro: ทอง พรีเมี่ยม พร้อม glow */
.quota-card.plan-pro {
  border-color: rgba(245, 196, 81, 0.5);
  background: linear-gradient(180deg, rgba(245, 196, 81, 0.12), transparent 65%), var(--bg-2);
  box-shadow: 0 0 0 1px rgba(245, 196, 81, 0.15), 0 8px 24px -12px rgba(245, 196, 81, 0.5);
}
.quota-card.plan-pro .quota-plan-badge {
  background: linear-gradient(100deg, #f5c451, #ffdd8a);
  color: #3a2800; border: none;
}
.quota-card.plan-pro .quota-text b { color: #f5c451; }
/* Ultra: ทีมงาน — โทนม่วง-ไซแอน + สายฟ้ากระพริบ */
@keyframes ultraBoltFlicker {
  0%, 100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 3px #67e8f9) drop-shadow(0 0 8px #c084fc);
  }
  8% { opacity: 0.15; transform: scale(0.85) rotate(-8deg); filter: none; }
  11% {
    opacity: 1;
    transform: scale(1.25) rotate(6deg);
    filter: drop-shadow(0 0 8px #67e8f9) drop-shadow(0 0 16px #f472b6) drop-shadow(0 0 22px #c084fc);
  }
  14% { opacity: 0.4; transform: scale(0.95); }
  17% {
    opacity: 1;
    transform: scale(1.12) rotate(-3deg);
    filter: drop-shadow(0 0 6px #67e8f9) drop-shadow(0 0 12px #c084fc);
  }
  38% { opacity: 0.2; }
  41% {
    opacity: 1;
    transform: scale(1.2);
    filter: drop-shadow(0 0 10px #f0abfc) drop-shadow(0 0 18px #67e8f9);
  }
  55% { opacity: 1; transform: scale(1); }
  81% {
    opacity: 1;
    transform: scale(1.15);
    filter: drop-shadow(0 0 12px #67e8f9) drop-shadow(0 0 20px #c084fc);
  }
}
@keyframes ultraBadgeGlow {
  0%, 100% { box-shadow: 0 0 0 1px rgba(192, 132, 252, 0.35), 0 0 10px rgba(103, 232, 249, 0.15); }
  50% { box-shadow: 0 0 0 1px rgba(103, 232, 249, 0.5), 0 0 18px rgba(192, 132, 252, 0.4); }
}
@keyframes ultraTextShimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.badge-ultra {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-radius: 999px;
  padding: 2px 9px 2px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.3;
  white-space: nowrap;
  color: #e9d5ff;
  background: linear-gradient(135deg, rgba(42, 24, 64, 0.95), rgba(15, 35, 48, 0.95));
  border: 1px solid rgba(192, 132, 252, 0.45);
  animation: ultraBadgeGlow 2.2s ease-in-out infinite;
  vertical-align: middle;
}
.badge-ultra-bolt {
  display: inline-block;
  font-size: 1.15em;
  line-height: 1;
  color: #67e8f9;
  animation: ultraBoltFlicker 1.65s ease-in-out infinite;
  transform-origin: center bottom;
  will-change: transform, opacity, filter;
}
.badge-ultra-label {
  background: linear-gradient(100deg, #e9d5ff, #67e8f9 40%, #f0abfc 70%, #e9d5ff);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: ultraTextShimmer 3s ease-in-out infinite;
}
/* ป้ายนิ่ง ชั้นเดียว — ใช้ใน editor / การ์ด (ไม่กระพริบ) */
.badge-ultra-static {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: #c084fc;
  background: #2a1840;
  border: 1px solid rgba(192, 132, 252, 0.45);
}
@media (prefers-reduced-motion: reduce) {
  .badge-ultra, .badge-ultra-bolt, .badge-ultra-label { animation: none !important; }
  .badge-ultra-bolt { opacity: 1; filter: drop-shadow(0 0 4px #67e8f9); }
}
.quota-card.plan-ultra {
  border-color: rgba(192, 132, 252, 0.55);
  background: linear-gradient(180deg, rgba(192, 132, 252, 0.14), transparent 65%), var(--bg-2);
  box-shadow: 0 0 0 1px rgba(103, 232, 249, 0.12), 0 8px 24px -12px rgba(192, 132, 252, 0.45);
}
.quota-card.plan-ultra .quota-plan-badge {
  /* ใช้ .badge-ultra แทน badge ธรรมดา */
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
}
.quota-card.plan-ultra .quota-text b { color: #c084fc; }

/* ================= Upload ================= */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; }
.logo { font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }
.logo span, .ed-title span {
  background: linear-gradient(100deg, #34e3a3 10%, #8b9bff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.badge-beta {
  font-size: 11px; color: var(--accent); border: 1px solid rgba(52, 227, 163, 0.45);
  border-radius: 999px; padding: 2px 10px; background: var(--accent-soft); font-weight: 600;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.btn-icon {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  width: 38px; height: 38px; border-radius: 12px; cursor: pointer; font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.btn-icon:hover { border-color: rgba(52, 227, 163, 0.5); box-shadow: 0 0 0 3px var(--accent-soft); }

.upload-body { max-width: 720px; margin: 0 auto; padding: 28px 20px 60px; text-align: center; }
.hero-title { font-size: clamp(30px, 6vw, 52px); font-weight: 800; line-height: 1.25; letter-spacing: -0.02em; }
.hero-title em {
  font-style: normal;
  background: linear-gradient(100deg, #34e3a3 10%, #8b9bff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  margin: 14px auto 0; max-width: 420px; color: var(--text-dim); font-size: 15px; line-height: 1.55;
}
.steps-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  margin: 28px 0 32px; text-align: left;
}
@media (max-width: 640px) {
  .steps-grid { grid-template-columns: repeat(2, 1fr); }
}
.step-card {
  border: 1px solid var(--border); background: var(--bg-2); border-radius: 12px;
  padding: 14px 12px; min-height: 100%;
}
.step-card .sc-ico { font-size: 20px; margin-bottom: 6px; }
.step-card b { display: block; font-size: 12.5px; color: var(--accent-2); margin-bottom: 4px; }
.step-card p { font-size: 11.5px; color: var(--text-mute); line-height: 1.45; margin: 0; }
.steps-row { display: none; }

.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(52, 227, 163, 0.04), transparent 50%), var(--bg-2);
  padding: 52px 24px; cursor: pointer;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: rgba(52, 227, 163, 0.45);
  box-shadow: var(--shadow-card), 0 0 0 1px rgba(52, 227, 163, 0.12);
  transform: translateY(-2px);
}
.dz-icon {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  background: var(--accent-soft); border: 1px solid rgba(52, 227, 163, 0.3);
}
.dz-main { font-size: 18px; font-weight: 700; }
.dz-sub { color: var(--text-mute); margin-top: 8px; font-size: 13.5px; }
.dz-formats { margin-top: 18px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.dz-formats span {
  font-size: 11px; color: var(--text-dim); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 10px; background: var(--bg-3); font-weight: 600;
}
.lang-row {
  margin-top: 22px; color: var(--text-dim); font-size: 14px;
  display: flex; gap: 10px; justify-content: center; align-items: center;
}
.foot { margin-top: 48px; color: var(--text-mute); font-size: 12px; }

select {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-family: inherit; font-size: 14px;
}
select:focus { outline: none; border-color: rgba(52, 227, 163, 0.55); }
.lang-row input[type="text"] {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-family: inherit; font-size: 14px;
  max-width: 340px;
}
.lang-row input[type="text"]:focus { outline: none; border-color: rgba(52, 227, 163, 0.55); }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* ================= Processing / Render ================= */
.proc-box { max-width: 480px; margin: 8vh auto; text-align: center; padding: 0 20px; }
.spinner {
  width: 48px; height: 48px; margin: 0 auto 24px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.proc-status { font-size: 19px; font-weight: 700; }
.proc-hint { color: var(--text-mute); font-size: 14px; margin-top: 10px; line-height: 1.5; }
.progress-track { height: 8px; background: #1a212c; border-radius: 999px; margin-top: 20px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #34e3a3, #8b9bff);
  transition: width 0.25s cubic-bezier(0.22, 1, 0.36, 1); border-radius: 999px;
}
/* พรีวิวคลิประหว่างแยกเสียง — อยู่ใน viewport จริง (จำเป็นสำหรับ iPhone) */
.proc-video-wrap {
  margin: 0 auto 20px;
  max-width: 220px;
}
.proc-video-host {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 280px;
  border-radius: 16px;
  overflow: hidden;
  background: #0d1118;
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px -16px rgba(0,0,0,0.55);
}
.proc-video-host video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.render-done { margin-top: 28px; display: flex; flex-direction: column; gap: 12px; align-items: center; }

.btn-primary {
  background: var(--accent); color: var(--accent-ink); border: none;
  padding: 12px 22px; border-radius: 12px; font-family: inherit; font-size: 15px;
  font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.btn-primary:hover { box-shadow: 0 4px 18px -6px rgba(52, 227, 163, 0.5); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  padding: 12px 22px; border-radius: 12px; font-family: inherit; font-size: 15px; cursor: pointer;
}
.btn-secondary:hover { border-color: rgba(52, 227, 163, 0.45); }
.btn-ghost {
  background: none; border: 1px dashed var(--border); color: var(--text-mute);
  padding: 10px; border-radius: 12px; font-family: inherit; font-size: 14px;
  cursor: pointer; width: 100%; margin-top: 10px;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(52, 227, 163, 0.45); }

/* ================= Editor layout ================= */
/* ไม่ใช้ 100vh ล้วน — จะทับ header/ann แล้วทำให้ทั้งหน้า scroll ปุ่ม play หลุดล่าง */
#step-editor.active {
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback ก่อนมี class lock */
  max-height: 100dvh;
  overflow: hidden;
  min-height: 0;
}
body.kaisub-editor-open #step-editor.active {
  flex: 1 1 0;
  height: auto !important;
  max-height: none;
  min-height: 0;
  overflow: hidden;
}

.ed-top {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 16, 0.85); backdrop-filter: blur(10px);
  flex: 0 0 auto;
}
.ed-title { font-weight: 800; font-size: 16px; flex: 0 0 auto; }
.ed-title small { color: var(--text-mute); font-weight: 400; font-size: 12px; margin-left: 6px; }
.ed-spacer { flex: 1; min-width: 4px; }

/* แถบกลาง: แผน + โควต้า */
.ed-quota {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  text-align: center;
  padding: 0 6px;
  line-height: 1.2;
  pointer-events: auto;
}
.ed-quota-plan {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.ed-quota-dot { display: none; }
.ed-quota-remain {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.ed-quota-remain b { color: var(--text); font-weight: 800; }
.ed-quota-cta {
  display: none;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  margin-top: 1px;
}
.ed-quota-cta:hover { text-decoration: underline; }
/* ยังไม่เข้าสู่ระบบ / anonymous */
.ed-quota[data-plan="anonymous"] .ed-quota-plan { color: var(--text-mute); }
.ed-quota[data-plan="anonymous"] .ed-quota-cta { display: inline; }
.ed-quota[data-plan="anonymous"] .ed-quota-cta::after { content: ' เพื่อใช้งานมากขึ้น'; }
/* Free / Standard / Pro / Ultra */
.ed-quota[data-plan="free"] .ed-quota-plan { color: var(--text-dim); }
.ed-quota[data-plan="standard"] .ed-quota-plan { color: var(--accent); }
.ed-quota[data-plan="pro"] .ed-quota-plan { color: var(--gold); }
.ed-quota[data-plan="ultra"] .ed-quota-plan {
  color: inherit;
  background: none;
  overflow: visible;
  max-width: none;
  padding: 0;
  border: none;
}
.ed-quota[data-plan="needs-claim"] .ed-quota-plan { color: #f87171; }
.ed-quota[data-plan="needs-claim"] .ed-quota-cta {
  display: inline;
}
.ed-quota[data-plan="needs-claim"] .ed-quota-cta::after { content: none !important; }
.ed-quota-cta.ed-quota-cta-soft {
  display: inline;
  color: var(--text-mute);
  font-weight: 600;
}
.ed-quota-cta.ed-quota-cta-soft:hover { color: var(--accent); }
.ed-quota-cta.ed-quota-cta-soft::after { content: none !important; }
.ed-quota-cta[hidden] { display: none !important; }

/* เดสก์ท็อป: แสดงแถวเดียว แผน · โควต้า */
@media (min-width: 769px) {
  .ed-quota {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 6px;
    justify-content: center;
  }
  .ed-quota-dot { display: inline; color: var(--text-mute); font-size: 11px; }
  .ed-quota-plan { font-size: 12px; }
  .ed-quota-remain { font-size: 11.5px; }
  .ed-quota-cta { font-size: 11px; margin-top: 0; }
  .ed-quota[data-plan="anonymous"] .ed-quota-cta::after { content: ' · เข้าสู่ระบบเพื่อใช้งานมากขึ้น'; }
}
.ed-iconbtn {
  background: none; border: 1px solid transparent; color: var(--text);
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 15px;
}
.ed-iconbtn:hover { background: var(--bg-3); border-color: var(--border); }
.ed-iconbtn:disabled { opacity: .35; cursor: default; }
.ed-btn {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 10px; font-family: inherit; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; transition: border-color 0.15s, box-shadow 0.15s;
}
.ed-btn:hover { border-color: rgba(52, 227, 163, 0.45); }
.ed-btn.on { border-color: rgba(52, 227, 163, 0.5); color: var(--accent); background: var(--accent-soft); }
.ed-btn-accent {
  background: var(--accent); color: var(--accent-ink); font-weight: 700; border-color: var(--accent);
}
.ed-btn-accent:hover { box-shadow: 0 4px 16px -6px rgba(52, 227, 163, 0.5); }
.ed-btn-accent-soft {
  background: var(--accent-soft); color: var(--accent); border-color: rgba(52, 227, 163, 0.4);
}

.ed-main { display: flex; flex: 1 1 auto; min-height: 0; min-width: 0; }
.ed-left { flex: 1; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); }
.ed-hint { text-align: center; color: var(--text-dim); font-size: 12.5px; padding: 8px; flex: 0 0 auto; }
.ed-hint b { color: var(--accent); }
.ed-preview-area {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0 12px 12px; overflow: hidden;
}
/* Safe Zone ลอยบนมุมวิดีโอ (อยู่ใน .video-wrap) */
.ed-float-tools {
  position: absolute; top: 8px; left: 8px; z-index: 6;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.ed-float-tools .float-tool { pointer-events: auto; }
.float-tool {
  background: rgba(12, 14, 18, 0.78); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 9px; font-size: 11px;
  display: flex; gap: 5px; align-items: center; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--text); user-select: none;
}
.float-tool input { accent-color: var(--accent); width: 12px; height: 12px; margin: 0; }

/* Stage: video + side settings panel side-by-side (panel never covers video) */
.preview-stage {
  display: flex; flex-direction: row; align-items: stretch; justify-content: center;
  gap: 0; max-width: 100%; max-height: 100%; min-width: 0; min-height: 0; height: 100%;
}
.video-wrap {
  position: relative; background: #000; border-radius: 10px; overflow: hidden;
  max-width: 100%; max-height: 100%; flex: 0 1 auto; min-width: 0;
  transition: max-width .28s ease;
}
/* panel-open max-width set with .sub-side-panel.open rules below */
.video-wrap video {
  display: block;
  max-width: 100%;
  /* ใช้ความสูงพื้นที่พรีวิวจริง ไม่ผูก 100vh ทั้งจอ (กันดัน timeline หลุด) */
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
body.kaisub-editor-open .video-wrap {
  max-height: 100%;
}
.video-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#subCanvas { cursor: pointer; touch-action: none; }
#safeCanvas { pointer-events: none; }

/* Side panel slides out to the right of the preview */
.sub-side-panel {
  flex: 0 0 0; width: 0; max-width: 0; opacity: 0;
  overflow: hidden; overflow-y: auto;
  background: linear-gradient(180deg, rgba(52, 227, 163, 0.04), transparent 30%), var(--bg-2);
  border: 1px solid transparent; border-radius: 0 14px 14px 0;
  padding: 0; margin: 0; box-sizing: border-box;
  pointer-events: none;
  transition: flex-basis .28s ease, width .28s ease, max-width .28s ease, opacity .22s ease, padding .28s ease, border-color .22s ease;
  align-self: stretch; min-height: 0;
}
.sub-side-panel.open {
  flex: 0 0 260px; width: 260px; max-width: 260px; opacity: 1;
  padding: 12px 12px 20px; border-color: rgba(52, 227, 163, 0.22);
  pointer-events: auto; margin-left: 8px;
  box-shadow: -8px 0 28px -12px rgba(0, 0, 0, 0.55);
}
.preview-stage.panel-open .video-wrap { max-width: calc(100% - 268px); }
.sub-side-panel .sub-popup-head,
.sub-side-panel .sub-popup-label,
.sub-side-panel .ps-align-row,
.sub-side-panel .ps-artboard-panel,
.sub-side-panel .swatches,
.sub-side-panel .shadow-wrap,
.sub-side-panel .grad-wrap {
  min-width: 220px; /* keep content stable while panel width animates */
}
.chk-inline {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px;
  color: var(--text); margin: 8px 0 4px; cursor: pointer; user-select: none;
}
.chk-inline input { accent-color: var(--accent); }
.shadow-wrap, .grad-wrap { margin-top: 2px; }
.shadow-wrap[hidden], .grad-wrap[hidden], .fold-body[hidden] { display: none !important; }
.sub-side-panel .swatches { gap: 6px; margin-bottom: 4px; }
.sub-side-panel .swatch { width: 26px; height: 26px; }

/* Collapsible sections (สี / stroke / shadow) */
.fold-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 10px 0 0; padding: 10px 12px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-align: left;
}
.fold-btn:hover { border-color: rgba(52, 227, 163, 0.4); }
.fold-btn.open {
  border-color: rgba(52, 227, 163, 0.45); background: var(--accent-soft); color: var(--accent);
  border-radius: 9px 9px 0 0;
}
.fold-btn .fold-chevron {
  font-style: normal; font-size: 12px; transition: transform .2s; color: var(--text-mute);
}
.fold-btn.open .fold-chevron { transform: rotate(90deg); color: var(--accent); }
.fold-body {
  padding: 10px 8px 12px; margin: 0 0 4px;
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 9px 9px; background: var(--bg);
}
.fold-btn.open + .fold-body { border-color: rgba(52, 227, 163, 0.35); }
.grad-preview {
  height: 22px; border-radius: 8px; margin: 6px 0 10px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, #34e3a3, #8b9bff);
}
.sub-popup-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.sub-popup-close { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; line-height: 1; padding: 4px; }
.sub-popup-close:hover { color: var(--text); }
.sub-popup-label { display: block; font-size: 12px; color: var(--text-dim); margin: 10px 0 6px; }
.sub-popup-label .sl-dim { font-size: 10.5px; opacity: .8; }
.sub-popup-label select, .sub-popup-label input[type="range"] { display: block; width: 100%; margin-top: 6px; }
.sub-popup-label output { float: right; color: var(--text); font-size: 12px; }

/* Illustrator-style align buttons */
/* Photoshop-style align buttons: icon + Thai label */
.ps-align-row { display: flex; gap: 6px; margin: 4px 0 10px; }
.ps-artboard-panel {
  display: flex; flex-direction: column; gap: 6px;
  margin: 4px 0 10px; padding: 8px; background: var(--bg-3); border-radius: 10px;
  border: 1px solid var(--border);
}
.ps-artboard-row { display: flex; align-items: stretch; gap: 6px; }
.ps-align-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; background: var(--bg); border: 1.5px solid var(--border); color: var(--text-dim);
  padding: 8px 4px 6px; border-radius: 8px; cursor: pointer; min-height: 52px;
  font-family: inherit; transition: border-color .15s, color .15s, background .15s;
}
.ps-align-btn span {
  font-size: 11px; font-weight: 600; line-height: 1.1; letter-spacing: 0;
  color: inherit; white-space: nowrap;
}
.ps-align-btn:hover { border-color: rgba(52, 227, 163, 0.45); color: var(--text); }
.ps-align-btn.active, .ps-align-btn:active,
.align-btn.active {
  color: var(--accent); border-color: rgba(52, 227, 163, 0.5); background: var(--accent-soft);
}
.ps-ico {
  width: 22px; height: 22px; display: block; flex-shrink: 0;
  fill: currentColor;
}

@media (max-width: 900px) {
  .preview-stage.panel-open .video-wrap { max-width: calc(100% - 230px); }
  .sub-side-panel.open { flex-basis: 220px; width: 220px; max-width: 220px; }
  .sub-side-panel .sub-popup-head,
  .sub-side-panel .sub-popup-label,
  .sub-side-panel .ps-align-row,
  .sub-side-panel .ps-artboard-panel,
  .sub-side-panel .swatches,
  .sub-side-panel .shadow-wrap,
  .sub-side-panel .grad-wrap { min-width: 184px; }
}

.sw-label .sl-dim { color: var(--text-dim); font-weight: 400; font-size: 12px; }

/* ---- Right panel ---- */
.ed-right {
  width: 460px; flex: 0 0 auto; display: flex; flex-direction: column;
  min-height: 0; min-width: 0; background: rgba(20, 25, 34, 0.92); overflow: hidden;
  border-left: 1px solid var(--border);
}
@media (max-width: 1100px) { .ed-right { width: 380px; } }
@media (max-width: 900px) { .ed-right { width: 320px; } }

/* แถบนำทางมือถือ (เปิดด้วย .mob-mode) */
.mob-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 200;
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 12, 16, 0.96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 2px;
  align-items: stretch;
  justify-content: space-around;
}
.mob-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--text-mute);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 6px 2px;
  cursor: pointer;
  min-width: 0;
}
.mob-nav-ico { font-size: 15px; line-height: 1; }
.mob-nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}
.mob-nav-export.active,
.mob-nav-btn.mob-nav-export:active {
  color: var(--accent-ink);
  background: var(--accent);
}

/* ---------- โหมดมือถือ: พรีวิวค้าง + แผงซ้อน (ขวาบาง / ล่าง ~20%) ---------- */
/* body เป็น flex คอลัมน์ — กัน kt-header + 100dvh ดันไทม์ไลน์หลุดใต้จอ
   (ใช้ร่วมกับ .kaisub-editor-open — ค่า lock viewport อยู่ด้านบนแล้ว) */
body.editor-mob {
  overflow: hidden !important;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
}
body.editor-mob .ann-host {
  flex: 0 0 auto;
  position: relative;
  top: auto;
}
body.editor-mob .kt-header {
  flex: 0 0 auto;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  padding: 3px 10px !important;
  font-size: 10px !important;
  min-height: 0;
  line-height: 1.2;
}
body.editor-mob .kt-header-current {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}
body.editor-mob .kt-header-link {
  margin-left: auto !important;
  width: auto !important;
  padding: 0 !important;
  font-size: 10px !important;
  white-space: nowrap;
}
body.editor-mob .kt-header-sep { display: none; }

#step-editor.mob-mode.active {
  display: flex !important;
  flex-direction: column;
  /* เติมพื้นที่ที่เหลือใต้ kt-header — ไม่ใช้ 100dvh ทับหัว */
  flex: 1 1 0 !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow: hidden;
  /* จองที่ให้ mob-nav fixed ด้านล่าง */
  padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}
#step-editor.mob-mode .mob-nav {
  display: flex;
  z-index: 200;
}
#step-editor.mob-mode .ed-top {
  flex-wrap: nowrap;
  gap: 2px;
  padding: 2px 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 0 0 auto;
  min-height: 0;
}
#step-editor.mob-mode .ed-top .ed-iconbtn {
  width: 28px;
  height: 28px;
  font-size: 13px;
  border-radius: 8px;
}
#step-editor.mob-mode .ed-title { font-size: 12px; white-space: nowrap; flex: 0 0 auto; }
#step-editor.mob-mode .ed-title small { display: none; }
#step-editor.mob-mode .ed-btn:not(.ed-btn-accent) { display: none; }
#step-editor.mob-mode #exportBtn { display: none !important; }
#step-editor.mob-mode .desk-only-tool { display: none !important; }
#step-editor.mob-mode .desk-vol-ctrl { display: none !important; }
/* กลางแถบหัว — แผน + โควต้า กระชับ */
#step-editor.mob-mode .ed-quota {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 4px;
  gap: 0;
}
#step-editor.mob-mode .ed-quota-plan {
  font-size: 9.5px;
  letter-spacing: -0.01em;
}
#step-editor.mob-mode .ed-quota-remain {
  font-size: 9px;
}
#step-editor.mob-mode .ed-quota-cta {
  font-size: 8.5px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
#step-editor.mob-mode .ed-quota[data-plan="anonymous"] .ed-quota-cta::after {
  content: ' · ใช้งานมากขึ้น';
}

/* พรีวิว + แถบล่างโชว์ตลอด — แผงเครื่องมือเป็น overlay */
#step-editor.mob-mode .ed-main {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  /* เว้นที่ให้ ed-bottom fixed (อัปเดตด้วย JS syncMobBottomOffset) */
  margin-bottom: var(--ed-bottom-h, 78px);
}
#step-editor.mob-mode .ed-left {
  display: flex !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  border: none !important;
  flex-direction: column !important;
  /* เปิดเทมเพลต → ดันซ้าย / เปิดสี → ดันขวา / ปิด → กลาง */
  padding-left: 0;
  padding-right: 0;
  transition: padding-left 0.22s ease, padding-right 0.22s ease;
  box-sizing: border-box;
}
#step-editor.mob-mode[data-ws="template"] .ed-left {
  padding-right: min(60px, 15vw);
}
/* แถบล่าง — fixed เหนือ mob-nav เสมอ (ไม่ต้องปัดจอขึ้น) */
#step-editor.mob-mode .ed-bottom {
  display: flex !important;
  flex-direction: column;
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  overflow: visible;
  z-index: 190;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 12, 16, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  /* ความสูงประมาณ timeline+transport — ใช้ CSS var ซิงค์กับ padding ed-main */
  --ed-bottom-h: 78px;
}
#step-editor.mob-mode.tl-collapsed .ed-bottom {
  --ed-bottom-h: 42px;
}
/* เว้นที่ให้ ed-bottom fixed ไม่ทับพรีวิว */
/* ปุ่มลูกศรซ่อน/แสดงไทม์ไลน์ */
.tl-collapse-btn {
  display: none;
  align-self: center;
  width: 40px;
  height: 16px;
  margin: 2px 0 0;
  padding: 0;
  border: none;
  border-radius: 0 0 8px 8px;
  background: var(--bg-3);
  color: var(--text-mute);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  z-index: 2;
}
.tl-collapse-btn:active { color: var(--accent); }
#step-editor.mob-mode .tl-collapse-btn { display: flex; align-items: center; justify-content: center; }
#step-editor.mob-mode.tl-collapsed .tl-collapse-btn {
  transform: rotate(180deg);
  border-radius: 8px 8px 0 0;
  margin: 0 0 2px;
}
#step-editor.mob-mode.tl-collapsed .timeline {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  border: none !important;
}

/* แผงขวา = overlay (ไม่กิน layout ของพรีวิว) */
#step-editor.mob-mode .ed-right {
  display: none;
  position: absolute;
  z-index: 30;
  background: var(--bg-2);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
}
#step-editor.mob-mode[data-ws="text"] .ed-right,
#step-editor.mob-mode[data-ws="style"] .ed-right,
#step-editor.mob-mode[data-ws="template"] .ed-right,
#step-editor.mob-mode[data-ws="export"] .ed-right {
  display: flex !important;
}
/* เทมเพลต: แถบขวาบางลง 50% แนวตั้ง ปัดขึ้น-ลง */
#step-editor.mob-mode[data-ws="template"] .ed-right {
  top: 0;
  right: 0;
  bottom: 0;
  width: min(60px, 15vw);
  max-width: 15vw;
  border-radius: 12px 0 0 12px;
  border-right: none;
  animation: mobSlideRight 0.22s ease;
  --mob-tpl-w: min(60px, 15vw);
}
/* ข้อความ / สไตล์ / ส่งออก: ชีตล่าง ~20% จอ */
#step-editor.mob-mode[data-ws="text"] .ed-right,
#step-editor.mob-mode[data-ws="style"] .ed-right,
#step-editor.mob-mode[data-ws="export"] .ed-right {
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  width: 100%;
  max-width: 100%;
  height: min(22dvh, 180px);
  max-height: 24dvh;
  border-radius: 16px 16px 0 0;
  border-bottom: none;
  animation: mobSlideUp 0.22s ease;
}
@keyframes mobSlideRight {
  from { transform: translateX(100%); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes mobSlideUp {
  from { transform: translateY(100%); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

/* แถบจับบน bottom sheet */
#step-editor.mob-mode[data-ws="text"] .ed-right::before,
#step-editor.mob-mode[data-ws="style"] .ed-right::before,
#step-editor.mob-mode[data-ws="export"] .ed-right::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  margin: 6px auto 0;
  flex: 0 0 auto;
}

#step-editor.mob-mode .ed-right > .tabs { display: none !important; }
#step-editor.mob-mode .tab-panel {
  display: none !important;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 10px 12px;
}
#step-editor.mob-mode[data-ws="template"] #tab-template,
#step-editor.mob-mode[data-ws="style"] #tab-style,
#step-editor.mob-mode[data-ws="text"] #tab-text,
#step-editor.mob-mode[data-ws="export"] #tab-export {
  display: block !important;
}

/* พรีวิว — ใช้พื้นที่เต็ม (ซ่อนคำใบ้เพื่อไม่สิ้นเปลืองแนวตั้ง) */
#step-editor.mob-mode .ed-hint {
  display: none !important;
}
#step-editor.mob-mode .ed-preview-area {
  flex: 1;
  min-height: 0;
  padding: 2px 4px;
  align-items: center;
  justify-content: center;
}
/* Safe Zone: มุมบนซ้ายของวิดีโอ ชิปเล็ก */
#step-editor.mob-mode .ed-float-tools {
  position: absolute !important;
  top: 6px !important;
  left: 6px !important;
  width: auto;
  z-index: 6;
  gap: 4px;
}
#step-editor.mob-mode .float-tool {
  padding: 3px 7px;
  font-size: 10px;
  gap: 4px;
  white-space: nowrap;
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.72);
}
#step-editor.mob-mode .float-tool input { width: 11px; height: 11px; }
#step-editor.mob-mode .preview-stage {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  flex-direction: column !important;
  align-items: center;
  justify-content: center;
}
/* พรีวิวใหญ่เมื่อไม่มีแผงซ้าย/ขวา — เติมพื้นที่ preview-area */
#step-editor.mob-mode .ed-preview-area {
  container-type: size;
}
#step-editor.mob-mode .video-wrap {
  position: relative;
  --vw: 9;
  --vh: 16;
  aspect-ratio: var(--vw) / var(--vh);
  /* fallback: ใหญ่กว่าเดิม (เดิม 58dvh) */
  width: min(98vw, calc((100dvh - 160px) * var(--vw) / var(--vh))) !important;
  max-width: 100% !important;
  max-height: min(100%, calc(100dvh - 160px)) !important;
  height: auto !important;
  margin: 0 auto;
  flex: 0 1 auto;
  align-self: center;
  background: #000;
  transition: max-width 0.22s ease, max-height 0.22s ease, width 0.22s ease;
}
/* ใช้ความสูงจริงของกรอบพรีวิว (cqh) ถ้าเบราว์เซอร์รองรับ */
@supports (height: 1cqh) {
  #step-editor.mob-mode .video-wrap {
    width: min(100%, calc(100cqh * var(--vw) / var(--vh))) !important;
    max-width: 100% !important;
    max-height: 100cqh !important;
  }
}
/* ตอนเปิดเทมเพลต/สี — ยังใหญ่แต่ไม่ล้นแถบข้าง */
#step-editor.mob-mode[data-ws="template"] .video-wrap,
#step-editor.mob-mode[data-ws="color"] .video-wrap {
  max-width: 100% !important;
  max-height: 100% !important;
}
#step-editor.mob-mode .video-wrap video {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  object-fit: fill;
  display: block;
}
#step-editor.mob-mode .video-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
#step-editor.mob-mode .sub-side-panel { display: none !important; }
#step-editor.mob-mode .preview-stage.panel-open .video-wrap { max-width: 100% !important; }

/* ไทม์ไลน์เตี้ย + transport กระชับ (อยู่เหนือ mob-nav) */
#step-editor.mob-mode .transport {
  flex-wrap: nowrap;
  gap: 3px;
  padding: 4px 6px 6px;
  align-items: center;
  min-height: 0;
}
#step-editor.mob-mode .play-btn {
  width: 28px;
  height: 28px;
  font-size: 11px;
  flex: 0 0 auto;
}
#step-editor.mob-mode .ed-iconbtn {
  width: 26px;
  height: 26px;
  font-size: 12px;
  padding: 0;
  flex: 0 0 auto;
}
#step-editor.mob-mode .time-label {
  font-size: 10px;
  flex: 0 0 auto;
  min-width: 0;
  max-width: none;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  letter-spacing: -0.02em;
}
/* แถบฟอนต์มือถือ: สี + ชื่อฟอนต์ + ขนาด */
.mob-font-bar {
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
#step-editor.mob-mode .mob-font-bar {
  display: flex !important;
}
/* ปุ่มวงกลมสีรุ้ง — เปิดแผงสีซ้าย */
.mob-color-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-3);
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.mob-color-btn[aria-expanded="true"],
#step-editor.mob-mode[data-ws="color"] .mob-color-btn {
  border-color: rgba(52, 227, 163, 0.55);
  box-shadow: 0 0 0 2px rgba(52, 227, 163, 0.18);
}
.mob-color-rainbow {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(
    #ef4444, #f59e0b, #ffd400, #22c55e, #22d3ee, #3b82f6, #a78bfa, #f472b6, #ef4444
  );
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.mob-font-btn {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 110px;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 8px 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
}
.mob-font-btn[aria-expanded="true"] {
  border-color: rgba(52, 227, 163, 0.55);
  background: var(--accent-soft);
  color: var(--accent);
}
.mob-font-btn-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.mob-font-btn-chev {
  flex: 0 0 auto;
  font-size: 14px;
  opacity: 0.55;
  transform: rotate(90deg);
  line-height: 1;
}
.mob-font-btn[aria-expanded="true"] .mob-font-btn-chev {
  transform: rotate(-90deg);
  opacity: 0.9;
}
.mob-size-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.mob-size-btn[aria-expanded="true"] {
  border-color: rgba(52, 227, 163, 0.55);
  background: var(--accent-soft);
  color: var(--accent);
}
.mob-size-ico {
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  letter-spacing: -0.5px;
}
/* แถบฟอนต์แนวนอนบาง ๆ เหนือ transport — ปัดซ้ายขวา */
.mob-font-strip {
  display: none;
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: calc(100% - 2px);
  z-index: 45;
  background: rgba(14, 16, 22, 0.97);
  border: 1px solid var(--border);
  border-radius: 12px 12px 10px 10px;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.4);
  padding: 6px 4px 7px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#step-editor.mob-mode .mob-font-strip:not([hidden]) {
  display: block;
}
.mob-font-strip-track {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding: 0 4px 2px;
  scrollbar-width: none;
}
.mob-font-strip-track::-webkit-scrollbar { display: none; }
.mob-font-chip {
  flex: 0 0 auto;
  scroll-snap-align: start;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  line-height: 28px;
}
.mob-font-chip.active {
  border-color: rgba(52, 227, 163, 0.55);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 0 1px rgba(52, 227, 163, 0.15);
}
/* สไลด์ขนาดแนวตั้ง — โผล่ข้างไอคอน A แล้วซ่อนหลังปรับ */
.mob-size-pop {
  display: none;
  position: absolute;
  right: 8px;
  bottom: calc(100% + 4px);
  z-index: 46;
  width: 48px;
  height: 168px;
  padding: 8px 6px 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(14, 16, 22, 0.97);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-sizing: border-box;
}
#step-editor.mob-mode .mob-size-pop:not([hidden]) {
  display: flex;
}
.mob-size-val {
  font-size: 11px;
  font-family: monospace;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  flex: 0 0 auto;
}
.mob-size-hint {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-mute);
  line-height: 1;
  flex: 0 0 auto;
  margin-top: auto;
}
.mob-size-range-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  /* ความสูงจริงของแถบรูด ≈ ความสูงกล่อง − ตัวเลข − hint */
  height: 120px;
}
.mob-size-range {
  /* แนวตั้งจริง — ไม่หมุน (หมุนแล้ว track สั้น/เพี้ยนบน iOS) */
  -webkit-appearance: slider-vertical;
  appearance: slider-vertical;
  writing-mode: vertical-lr;
  direction: rtl; /* ค่าสูงอยู่ด้านบน */
  width: 28px;
  height: 100%;
  min-height: 110px;
  margin: 0 auto;
  padding: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: none;
}
/* fallback เบราว์เซอร์ที่ไม่รองรับ slider-vertical: หมุน + ความยาวเต็มกล่อง */
@supports not (appearance: slider-vertical) {
  .mob-size-range-wrap {
    align-items: center;
    justify-content: center;
  }
  .mob-size-range {
    -webkit-appearance: none;
    appearance: none;
    writing-mode: horizontal-tb;
    direction: ltr;
    width: 120px;
    height: 28px;
    min-height: 0;
    transform: rotate(-90deg);
    transform-origin: center center;
  }
  .mob-size-range::-webkit-slider-runnable-track {
    height: 5px;
    border-radius: 99px;
    background: var(--bg-4);
  }
  .mob-size-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    margin-top: -6.5px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #04231a;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  }
  .mob-size-range::-moz-range-track {
    height: 5px;
    border-radius: 99px;
    background: var(--bg-4);
  }
  .mob-size-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #04231a;
  }
}

/* แผงสีซ้าย — เปิด/ปิดแบบเทมเพลต (ฝั่งตรงข้าม) */
.mob-color-panel {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 30;
  width: min(72px, 18vw);
  max-width: 18vw;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 12px 12px 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  flex-direction: column;
  pointer-events: auto;
  animation: mobSlideLeft 0.22s ease;
}
@keyframes mobSlideLeft {
  from { transform: translateX(-100%); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}
#step-editor.mob-mode[data-ws="color"] .mob-color-panel {
  display: flex !important;
}
#step-editor.mob-mode[data-ws="color"] .ed-right {
  display: none !important;
}
/* ตอนเปิดสี — ดันพรีวิวไปขวา */
#step-editor.mob-mode[data-ws="color"] .ed-left {
  padding-left: min(72px, 18vw);
  padding-right: 0;
}
.mob-color-panel-inner {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mob-color-sec { min-width: 0; }
.mob-color-lab {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 5px;
  line-height: 1.2;
}
.mob-swatches {
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 5px !important;
}
.mob-swatches .swatch,
.mob-swatches .swatch-custom {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  border-radius: 50% !important;
  flex: 0 0 auto;
}
.mob-swatches .swatch-custom {
  font-size: 12px;
}

#step-editor.mob-mode .timeline {
  height: 32px !important;
  max-height: 32px;
  margin: 0 6px 2px;
  overflow: hidden;
  border-radius: 7px;
  flex: 0 0 auto;
}
#step-editor.mob-mode .ruler { height: 11px; font-size: 8px; }
#step-editor.mob-mode .ruler i { bottom: -20px; }
#step-editor.mob-mode #waveCanvas {
  top: 11px !important;
  height: 10px !important;
}
#step-editor.mob-mode .chips {
  top: 20px !important;
  height: 12px !important;
}
#step-editor.mob-mode .chip {
  top: 0 !important;
  height: 11px !important;
  font-size: 8px !important;
  line-height: 1.1;
  padding: 0 4px !important;
  border-radius: 3px;
}
#step-editor.mob-mode .chip-text {
  font-size: 8px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#step-editor.mob-mode .chip small { display: none; }
#step-editor.mob-mode .chip-handle { width: 4px; }

/* เทมเพลตแนวตั้ง — การ์ดเล็ก โชว์แค่ชื่อ */
#step-editor.mob-mode[data-ws="template"] #tab-template {
  padding: 4px 3px 8px;
}
#step-editor.mob-mode[data-ws="template"] .font-mode-switch {
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  margin-bottom: 4px;
}
#step-editor.mob-mode[data-ws="template"] .font-mode-copy b {
  font-size: 0;
  text-align: center;
  line-height: 0;
}
#step-editor.mob-mode[data-ws="template"] .font-mode-copy b::after {
  content: 'ฟอนต์';
  font-size: 8px;
  line-height: 1.15;
  font-weight: 700;
}
#step-editor.mob-mode[data-ws="template"] .font-mode-copy small { display: none !important; }
#step-editor.mob-mode[data-ws="template"] .switch-track {
  transform: scale(0.85);
  transform-origin: center;
}
#step-editor.mob-mode[data-ws="template"] .tpl-head {
  font-size: 8px;
  margin: 2px 0 4px;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
}
#step-editor.mob-mode[data-ws="template"] .tpl-head span { display: none; }
#step-editor.mob-mode[data-ws="template"] .pack-grid,
#step-editor.mob-mode[data-ws="template"] .tpl-grid {
  display: flex !important;
  flex-direction: column !important;
  gap: 3px !important;
  grid-template-columns: none !important;
}
#step-editor.mob-mode[data-ws="template"] .pack-card,
#step-editor.mob-mode[data-ws="template"] .tpl-card {
  width: 100%;
  min-width: 0;
  padding: 5px 2px 4px;
  border-radius: 7px;
  border-width: 1.5px;
}
/* โชว์แค่ชื่อ — ซ่อนรายละเอียด / demo / emoji ใหญ่ */
#step-editor.mob-mode[data-ws="template"] .pack-emoji {
  font-size: 11px;
  margin-bottom: 1px;
  line-height: 1;
}
#step-editor.mob-mode[data-ws="template"] .pack-card b,
#step-editor.mob-mode[data-ws="template"] .tpl-card b,
#step-editor.mob-mode[data-ws="template"] .tpl-name {
  font-size: 8px;
  white-space: normal;
  line-height: 1.15;
  margin-bottom: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
#step-editor.mob-mode[data-ws="template"] .pack-card small,
#step-editor.mob-mode[data-ws="template"] .tpl-card small,
#step-editor.mob-mode[data-ws="template"] .tpl-demo {
  display: none !important;
}
#step-editor.mob-mode[data-ws="template"] .tpl-card.active::after {
  top: 1px;
  right: 2px;
  font-size: 8px;
}
#step-editor.mob-mode[data-ws="template"] .tpl-group {
  font-size: 8px;
  margin-top: 3px;
  padding-bottom: 1px;
  text-align: center;
  white-space: normal;
  line-height: 1.15;
}

/* ชีตล่าง: ปุ่ม/คอนโทรลเล็กลง ประหยัดพื้นที่ */
#step-editor.mob-mode[data-ws="text"] .tab-panel,
#step-editor.mob-mode[data-ws="style"] .tab-panel,
#step-editor.mob-mode[data-ws="export"] .tab-panel {
  padding: 4px 10px 10px;
}
#step-editor.mob-mode[data-ws="style"] .style-font-select,
#step-editor.mob-mode[data-ws="style"] select {
  font-size: 12px;
  padding: 6px 8px;
  margin-bottom: 6px;
}
#step-editor.mob-mode[data-ws="style"] .font-preview {
  font-size: 13px;
  padding: 6px;
  margin-bottom: 6px;
}
#step-editor.mob-mode[data-ws="style"] .sw-label,
#step-editor.mob-mode[data-ws="style"] .sl-label {
  font-size: 11px;
  margin: 6px 0 4px;
}
#step-editor.mob-mode[data-ws="style"] .sl-label output { font-size: 11px; }
#step-editor.mob-mode[data-ws="style"] .mode-btn {
  padding: 5px 4px;
  font-size: 11px;
}
#step-editor.mob-mode[data-ws="style"] .ps-align-btn {
  padding: 4px 2px;
  font-size: 10px;
  min-height: 0;
}
#step-editor.mob-mode[data-ws="style"] .ps-ico {
  width: 16px;
  height: 16px;
}
#step-editor.mob-mode[data-ws="style"] .swatch,
#step-editor.mob-mode[data-ws="style"] .swatches button {
  width: 22px !important;
  height: 22px !important;
  min-width: 22px;
}
#step-editor.mob-mode[data-ws="style"] .fold-btn {
  padding: 6px 8px;
  font-size: 11px;
}
#step-editor.mob-mode[data-ws="style"] .tgl {
  padding: 5px 10px;
  font-size: 11px;
}
#step-editor.mob-mode[data-ws="text"] .text-tools {
  font-size: 11px;
  padding-bottom: 6px;
}
#step-editor.mob-mode[data-ws="text"] .sub-row {
  padding: 5px 2px;
  gap: 6px;
}
#step-editor.mob-mode[data-ws="text"] .sub-row-meta { flex-basis: 48px; }
#step-editor.mob-mode[data-ws="text"] .sub-row-no,
#step-editor.mob-mode[data-ws="text"] .sub-row-time { font-size: 10px; }
#step-editor.mob-mode[data-ws="text"] .sub-row textarea,
#step-editor.mob-mode[data-ws="text"] .sub-row input {
  font-size: 12px;
  padding: 5px 6px;
}
#step-editor.mob-mode[data-ws="text"] .btn-ghost {
  font-size: 12px;
  padding: 6px 10px;
}
.export-sheet {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px 2px;
}
.export-sheet-hint {
  margin: 0;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}
.export-sheet-btn {
  width: 100%;
  font-size: 13px !important;
  padding: 10px 12px !important;
  border-radius: 10px;
}

.tabs { display: flex; gap: 4px; padding: 10px 10px 0; flex: 0 0 auto; min-width: 0; }
.tab {
  flex: 1; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim); padding: 10px 4px; cursor: pointer; font-family: inherit;
  font-size: 12.5px; font-weight: 600; border-radius: 8px 8px 0 0; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text); background: var(--bg-3);
  border-bottom-color: var(--accent); box-shadow: inset 0 -1px 0 var(--accent);
}
.tab-panel {
  display: none; overflow-x: hidden; overflow-y: auto; flex: 1;
  padding: 12px 14px 20px; min-width: 0; min-height: 0;
}
.tab-panel.active { display: block; }

/* text tab */
.text-tools {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-dim); padding-bottom: 10px; min-width: 0;
}
.text-tools b { color: var(--text); }
.text-tools-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-list { display: flex; flex-direction: column; width: 100%; min-width: 0; }
.sub-row {
  display: flex; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--border);
  align-items: flex-start; border-left: 3px solid transparent;
  min-width: 0; width: 100%; box-sizing: border-box;
}
.sub-row.current { border-left-color: var(--accent); background: var(--accent-soft); }
/* Index + timestamp stacked so the text field gets max horizontal space */
.sub-row-meta {
  flex: 0 0 58px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 5px;
  min-width: 0;
}
.sub-row-no {
  color: var(--text-dim); font-size: 11px; line-height: 1.3; text-align: left;
}
.sub-row-time {
  color: var(--text-dim); font-size: 11.5px; font-family: monospace;
  cursor: pointer; line-height: 1.3; white-space: nowrap;
}
.sub-row-time:hover { color: var(--accent); }
/* flex:1 alone lets textarea shrink to unreadable width; min-width:0 + flex-basis 0
   forces it to take remaining panel space and wrap Thai/Latin text properly */
.sub-row-text {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  resize: none;
  padding: 5px 8px;
  min-height: 2.1em;
  overflow-x: hidden;
  overflow-y: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  field-sizing: content; /* auto-grow height where supported */
}
.sub-row-text:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.sub-row-del {
  flex: 0 0 28px; background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 14px; padding-top: 6px; opacity: 0; line-height: 1;
}
.sub-row:hover .sub-row-del { opacity: 1; }
.sub-row-del:hover { color: #f87171; }

/* template tab — font lock switch */
.font-mode-switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; margin-bottom: 14px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; user-select: none; min-width: 0;
  transition: border-color .15s, background .15s;
}
.font-mode-switch:hover { border-color: rgba(52, 227, 163, 0.35); }
.font-mode-switch:has(input:checked) {
  border-color: rgba(52, 227, 163, 0.5);
  background: var(--accent-soft);
}
.font-mode-copy { min-width: 0; flex: 1; }
.font-mode-copy b { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.font-mode-copy small { display: block; font-size: 11.5px; color: var(--text-dim); line-height: 1.4; }
.switch { position: relative; flex: 0 0 auto; display: inline-flex; }
.switch input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; margin: 0; cursor: pointer; z-index: 2;
}
.switch-track {
  display: block; width: 46px; height: 26px; border-radius: 999px;
  background: var(--bg-4); border: 1px solid var(--border);
  transition: background .18s, border-color .18s; position: relative;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: #c5ccd6;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
  transition: transform .18s, background .18s;
}
.switch input:checked + .switch-track {
  background: rgba(52, 227, 163, 0.35);
  border-color: rgba(52, 227, 163, 0.65);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
  background: var(--accent);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* template tab — fit width, vertical scroll only (no horizontal overflow) */
.tpl-head { font-size: 14px; font-weight: 600; margin-bottom: 12px; min-width: 0; }
.tpl-head span { color: var(--text-dim); font-weight: 400; font-size: 12px; float: right; }
.tpl-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  width: 100%; max-width: 100%; min-width: 0; overflow-x: hidden;
}
@media (max-width: 1100px) { .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tpl-card {
  border: 2px solid var(--border); border-radius: 12px; padding: 10px; cursor: pointer;
  background: var(--bg-3); text-align: left; position: relative;
  min-width: 0; max-width: 100%; overflow: hidden;
}
.tpl-card.active {
  border-color: rgba(52, 227, 163, 0.55);
  box-shadow: 0 0 0 1px rgba(52, 227, 163, 0.2);
}
.tpl-card.active::after { content: '✓'; position: absolute; top: 8px; right: 10px; color: var(--accent); font-weight: 700; z-index: 2; }
.tpl-name {
  font-size: 12.5px; font-weight: 600; margin-bottom: 8px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.tpl-demo {
  background: #000; border-radius: 8px; padding: 16px 4px; text-align: center;
  font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden;
  color: #fff; max-width: 100%; min-width: 0;
}
.tpl-demo em { font-style: normal; display: inline-block; }

/* hover animation previews for templates */
.tpl-card:hover .tpl-demo .ta-popIn { animation: taPopIn .45s ease-out infinite alternate; }
.tpl-card:hover .tpl-demo .ta-bounce { animation: taBounce .5s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-slideUp { animation: taSlideUp .55s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-fade { animation: taFade .8s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-shake { animation: taShake .35s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-typewriter { animation: taBlink .7s step-end infinite; }
.tpl-card:hover .tpl-demo .ta-neon { animation: taNeon 1s ease-in-out infinite alternate; }
.tpl-card:hover .tpl-demo .ta-wave { animation: taWave .6s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-rainbow { animation: taHue 2s linear infinite; }
.tpl-card:hover .tpl-demo .ta-zoomIn { animation: taZoomIn .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-dropIn { animation: taDropIn .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-riseIn { animation: taRiseIn .65s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-rotateIn { animation: taRotateIn .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-blurIn { animation: taBlurIn .8s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-elasticPop { animation: taElastic .9s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-flipIn { animation: taFlip .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-swingIn { animation: taSwing .8s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-stretchIn { animation: taStretch .65s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-glideLeft { animation: taGlideL .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-glideRight { animation: taGlideR .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-wordPop { animation: taWordPop .55s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-wordFade { animation: taFade .7s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-wordRise { animation: taRiseIn .55s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-wordFlip { animation: taFlip .55s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-spinWord { animation: taSpin .7s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-beatBounce { animation: taBeat .45s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-beatGlow { animation: taNeon .6s ease-in-out infinite alternate; }
.tpl-card:hover .tpl-demo .ta-beatColor { animation: taBeat .5s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-jellyWord { animation: taJelly .55s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-focusScale { animation: taBeat .6s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-focusColor { animation: taPulseColor .8s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-karaoke { animation: taPulseColor .9s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-karaokeFill { animation: taPulseColor .9s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-minimalBox { animation: taBoxPulse .8s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-boxBar { animation: taFade .9s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-gradient { animation: taHue 2.5s linear infinite; }
.tpl-card:hover .tpl-demo .ta-outline { animation: taPulseColor 1s ease-in-out infinite; }
.tpl-card:hover .tpl-demo .ta-pop3d { animation: taWordPop .6s ease-out infinite; }
.tpl-card:hover .tpl-demo .ta-minimal { animation: taFade 1.2s ease-in-out infinite; }
/* โมชันเอกลักษณ์ */
.tpl-card:hover .tpl-demo .ta-silkReveal { animation: taSilk .9s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-helixCascade { animation: taHelix .85s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-orbitIn { animation: taOrbit 1s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-tiltDrift { animation: taTilt .95s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-bloomRise { animation: taBloom .95s cubic-bezier(.34,1.4,.64,1) infinite; }
/* เอฟเฟกต์ซิกเนเจอร์ */
.tpl-card:hover .tpl-demo .ta-vortexPull { animation: taVortex .95s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-stampPress { animation: taStamp .85s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-ribbonUnfurl { animation: taRibbon .9s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-echoTrail { animation: taEcho .9s cubic-bezier(.22,1,.36,1) infinite; }
.tpl-card:hover .tpl-demo .ta-prismMerge { animation: taPrism 1s cubic-bezier(.22,1,.36,1) infinite; }

@keyframes taPopIn { from { transform: scale(.7); opacity: .5; } to { transform: scale(1.05); opacity: 1; } }
@keyframes taSilk {
  0%   { transform: translate(4px, 10px) rotate(-4deg) scale(.88); opacity: .25; }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
}
@keyframes taHelix {
  0%   { transform: translate(-8px, 10px) rotate(-18deg) scale(.5); opacity: .15; }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
}
@keyframes taOrbit {
  0%   { transform: translate(12px, -8px) rotate(12deg) scale(.65); opacity: .2; }
  60%  { transform: translate(-3px, 2px) rotate(-2deg) scale(1.04); opacity: .9; }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
}
@keyframes taTilt {
  0%   { transform: translateY(8px) rotate(10deg) scale(.85); opacity: .2; }
  70%  { transform: translateY(-1px) rotate(-1deg) scale(1.02); opacity: 1; }
  100% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}
@keyframes taBloom {
  0%   { transform: translateY(12px) rotate(-6deg) scale(.35); opacity: .15; }
  55%  { transform: translateY(-2px) rotate(1deg) scale(1.08); opacity: 1; }
  100% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}
@keyframes taVortex {
  0%   { transform: translate(14px, -10px) rotate(-40deg) scale(.3); opacity: .1; }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
}
@keyframes taStamp {
  0%   { transform: translateY(-16px) scale(1.7); opacity: .2; }
  55%  { transform: translateY(2px) scaleX(1.12) scaleY(.78); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes taRibbon {
  0%   { transform: translateX(-14px) rotate(-12deg) scaleX(.08); opacity: .15; transform-origin: left center; }
  100% { transform: translateX(0) rotate(0) scaleX(1); opacity: 1; transform-origin: left center; }
}
@keyframes taEcho {
  0%   { transform: translate(-12px, 6px) rotate(-8deg) scale(.6); opacity: .2; filter: blur(.5px); }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; filter: blur(0); }
}
@keyframes taPrism {
  0%   { transform: scale(.8); opacity: .4; text-shadow: -4px 0 #ff2d55, 4px 0 #2ee6a6, 0 3px #4da3ff; }
  100% { transform: scale(1); opacity: 1; text-shadow: 0 0 transparent; }
}
@keyframes taBounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes taSlideUp { from { transform: translateY(10px); opacity: .3; } to { transform: translateY(0); opacity: 1; } }
@keyframes taFade { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes taShake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes taBlink { 50% { opacity: 0; } }
@keyframes taNeon { from { filter: brightness(1); text-shadow: 0 0 4px currentColor; } to { filter: brightness(1.3); text-shadow: 0 0 12px currentColor, 0 0 20px currentColor; } }
@keyframes taWave { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes taHue { to { filter: hue-rotate(360deg); } }
@keyframes taZoomIn { from { transform: scale(1.3); opacity: .4; } to { transform: scale(1); opacity: 1; } }
@keyframes taDropIn { from { transform: translateY(-12px); opacity: .3; } to { transform: translateY(0); opacity: 1; } }
@keyframes taRiseIn { from { transform: translateY(10px); opacity: .3; } to { transform: translateY(0); opacity: 1; } }
@keyframes taRotateIn { from { transform: rotate(-12deg) scale(.85); opacity: .4; } to { transform: rotate(0) scale(1); opacity: 1; } }
@keyframes taBlurIn { from { opacity: .2; filter: blur(3px); } to { opacity: 1; filter: blur(0); } }
@keyframes taElastic { 0% { transform: scale(.4); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes taFlip { from { transform: scaleY(.15); opacity: .4; } to { transform: scaleY(1); opacity: 1; } }
@keyframes taSwing { 0%,100% { transform: rotate(0); } 25% { transform: rotate(8deg); } 75% { transform: rotate(-8deg); } }
@keyframes taStretch { from { transform: scaleX(1.6); opacity: .5; } to { transform: scaleX(1); opacity: 1; } }
@keyframes taGlideL { from { transform: translateX(-14px); opacity: .3; } to { transform: translateX(0); opacity: 1; } }
@keyframes taGlideR { from { transform: translateX(14px); opacity: .3; } to { transform: translateX(0); opacity: 1; } }
@keyframes taWordPop { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }
@keyframes taSpin { from { transform: rotate(-40deg); opacity: .4; } to { transform: rotate(0); opacity: 1; } }
@keyframes taBeat { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@keyframes taJelly { 0%,100% { transform: scale(1,1); } 50% { transform: scale(1.2,.8); } }
@keyframes taPulseColor { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.4); } }
@keyframes taBoxPulse { 0%,100% { box-shadow: inset 0 0 0 1.5px transparent; } 50% { box-shadow: inset 0 0 0 1.5px var(--accent); } }

/* style tab */
.style-font-select { width: 100%; padding: 10px 12px; font-size: 15px; border-radius: 10px; margin-bottom: 8px; }
.font-preview { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; font-size: 17px; margin-bottom: 16px; }
.sl-label { display: block; font-size: 13.5px; color: var(--text); margin: 14px 0; }
.sl-label output { float: right; color: var(--text-dim); font-size: 13px; }
.sl-label .sl-dim { color: var(--text-dim); font-size: 12px; }
.sl-label input { margin-top: 8px; }

.chk-card { display: flex; gap: 10px; background: var(--accent-soft); border: 1px solid transparent; border-radius: 10px; padding: 12px; margin: 10px 0; cursor: pointer; align-items: flex-start; }
.chk-card:has(input:checked) { border-color: var(--accent); }
.chk-card input { accent-color: var(--accent); margin-top: 3px; }
.chk-card b { font-size: 13.5px; display: block; }
.chk-card small { color: var(--text-dim); font-size: 12px; line-height: 1.5; }

.sw-label { font-size: 13.5px; margin: 16px 0 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid var(--border); padding: 0; }
.swatch.active { border-color: #fff; outline: 2px solid var(--accent); }
/* ปุ่ม “ไม่ใช้สี” — วงกลมโปร่ง + เส้นทแยง */
.swatch-none {
  position: relative;
  background:
    linear-gradient(to top left,
      transparent calc(50% - 1.2px),
      #f87171 calc(50% - 1.2px),
      #f87171 calc(50% + 1.2px),
      transparent calc(50% + 1.2px)),
    repeating-conic-gradient(#2a3140 0% 25%, #1a1f28 0% 50%) 0 0 / 8px 8px;
  overflow: hidden;
}
.swatch-none::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.28);
  pointer-events: none;
}
.swatch-none.active {
  outline-color: #f87171;
  border-color: rgba(248, 113, 113, 0.7);
}
.swatch-custom { display: flex; align-items: center; justify-content: center; background: var(--bg-3); color: var(--text); font-size: 13px; position: relative; overflow: hidden; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.toggle-row { display: flex; gap: 10px; margin-top: 18px; }
.tgl { background: var(--bg-3); border: 1px solid var(--border); color: var(--text-dim); padding: 9px 16px; border-radius: 9px; cursor: pointer; font-family: inherit; font-size: 13.5px; }
.tgl.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---- Bottom / timeline ---- */
.ed-bottom {
  flex: 0 0 auto; border-top: 1px solid var(--border);
  background: rgba(10, 12, 16, 0.9); backdrop-filter: blur(10px);
}
.transport { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.play-btn {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent);
  color: var(--accent-ink); border: none; font-size: 15px; cursor: pointer; flex: 0 0 auto;
  box-shadow: 0 0 0 0 rgba(52, 227, 163, 0.25);
  transition: box-shadow 0.2s, transform 0.12s;
}
.play-btn:hover { box-shadow: 0 0 18px 2px rgba(52, 227, 163, 0.28); }
.play-btn:active { transform: scale(0.96); }
.loop-btn { font-size: 16px; opacity: .55; }
.loop-btn.on { opacity: 1; color: var(--accent); border-color: rgba(52, 227, 163, 0.5); background: var(--accent-soft); }
.time-label { font-family: monospace; font-size: 13px; color: var(--accent); min-width: 170px; }
.speed-label { font-family: monospace; font-size: 12.5px; color: var(--text-dim); min-width: 34px; }
.speed-slider { width: 90px !important; flex: 0 0 auto; }

.timeline { position: relative; height: 104px; margin: 0 14px 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: crosshair; user-select: none; }
.ruler { position: absolute; top: 0; left: 0; right: 0; height: 16px; font-size: 10px; color: var(--text-dim); }
.ruler span { position: absolute; top: 1px; transform: translateX(2px); }
.ruler i { position: absolute; top: 0; bottom: -88px; width: 1px; background: var(--border); font-style: normal; }
#waveCanvas { position: absolute; top: 16px; left: 0; width: 100%; height: 34px; }
.chips { position: absolute; top: 54px; left: 0; right: 0; height: 44px; }
.chip { position: absolute; top: 4px; height: 36px; background: var(--bg-4); border: 1px solid var(--border); border-radius: 7px; font-size: 10.5px; line-height: 1.25; padding: 3px 8px; overflow: hidden; cursor: grab; color: var(--text); touch-action: none; }
.chip:hover, .chip.current { border-color: rgba(52, 227, 163, 0.5); }
.chip.current { background: var(--accent-soft); box-shadow: 0 0 0 1px rgba(52, 227, 163, 0.12); }
.chip.editing { cursor: text; z-index: 5; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(52, 227, 163, 0.25); overflow: visible; }
.chip small { color: var(--text-dim); margin-right: 3px; }
.chip-text { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; pointer-events: none; }
.chip.editing .chip-text { pointer-events: auto; white-space: normal; overflow: visible; background: var(--bg-2); }
.chip-handle { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 2; }
.chip-handle-l { left: 0; }
.chip-handle-r { right: 0; }
.chip-handle:hover { background: rgba(52, 227, 163, 0.35); }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); pointer-events: none; box-shadow: 0 0 8px rgba(52, 227, 163, 0.45); }
.playhead::before { content: ''; position: absolute; top: 0; left: -4px; border: 5px solid transparent; border-top-color: var(--accent); }

/* ================= Settings modal ================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  /* เหนือ mob-nav (z=200) และ ed-bottom */
  z-index: 300;
  padding: 16px;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}
.modal-overlay[hidden] { display: none; }

/* ยืนยันหักโควต้า */
.modal-quota { max-width: 400px; }
.quota-confirm-lead {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
}
.quota-confirm-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-3);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qc-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13.5px;
  color: var(--text-dim);
}
.qc-row b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 14.5px;
}
.qc-row.qc-after b { color: var(--accent); }
.quota-confirm-note {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-mute);
}
.modal {
  background: linear-gradient(180deg, rgba(52, 227, 163, 0.05), transparent 40%), var(--bg-2);
  border: 1px solid var(--border); border-radius: var(--radius-xl);
  padding: 22px; width: 100%; max-width: 460px;
  max-height: min(90vh, 90dvh);
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h2 { font-size: 19px; margin: 0; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer;
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.modal-close:hover { color: var(--text); background: var(--bg-3); }
.set-label { display: block; font-size: 13px; color: var(--text-dim); margin: 16px 0 8px; }
.set-label a { color: var(--accent); }
.provider-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.provider-card { background: var(--bg-3); border: 2px solid var(--border); border-radius: 12px; padding: 12px; cursor: pointer; color: var(--text); font-family: inherit; text-align: left; }
.provider-card.active {
  border-color: rgba(52, 227, 163, 0.55);
  background: linear-gradient(180deg, rgba(52, 227, 163, 0.08), transparent), var(--bg-3);
  box-shadow: 0 0 0 1px rgba(52, 227, 163, 0.12);
}
.provider-card b { display: block; font-size: 15px; margin-bottom: 4px; }
.provider-card small { color: var(--text-dim); font-size: 11.5px; line-height: 1.5; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-family: inherit; font-size: 14px; }
.key-row input:focus { outline: none; border-color: var(--accent); }
.key-eye { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; padding: 0 10px; flex: 0 0 auto; }
.key-status { font-size: 12.5px; margin-top: 5px; min-height: 16px; }
.key-status.ok { color: #4ade80; }
.key-status.bad { color: #f87171; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn-primary, .modal-actions .btn-secondary { flex: 1; }
.settings-msg { text-align: center; font-size: 13px; color: var(--text-dim); margin-top: 12px; min-height: 18px; }
.settings-msg.ok { color: #4ade80; }

/* มือถือ: modal กะทัดรัด / ชีตล่าง ไม่กินเต็มจอ */
@media (max-width: 640px) {
  .modal-overlay {
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    background: rgba(0, 0, 0, 0.55);
  }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: min(78dvh, 78vh);
    margin: 0;
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  }
  /* แถบจับด้านบน (ชีต) */
  .modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 99px;
    background: var(--border);
    margin: 0 auto 10px;
  }
  .modal-head { margin-bottom: 10px; }
  .modal-head h2 { font-size: 16px; }
  .modal-close { width: 32px; height: 32px; font-size: 16px; }
  .set-label {
    font-size: 12px;
    margin: 10px 0 6px;
  }
  .provider-row { gap: 8px; }
  .provider-card {
    padding: 8px 9px;
    border-radius: 10px;
    border-width: 1.5px;
  }
  .provider-card b { font-size: 13px; margin-bottom: 2px; }
  .provider-card small { font-size: 10.5px; line-height: 1.35; }
  .key-row { gap: 6px; }
  .key-row input {
    padding: 8px 10px;
    font-size: 13px;
    border-radius: 8px;
  }
  .key-eye { padding: 0 8px; font-size: 14px; }
  .key-status { font-size: 11.5px; min-height: 14px; margin-top: 3px; }
  .modal-actions {
    gap: 8px;
    margin-top: 14px;
  }
  .modal-actions .btn-primary,
  .modal-actions .btn-secondary {
    padding: 10px 12px;
    font-size: 13px;
    border-radius: 10px;
  }
  .settings-msg { font-size: 12px; margin-top: 8px; min-height: 16px; }
}

/* ---- display mode + preset packs ---- */
.mode-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.mode-btn { background: var(--bg-3); border: 1.5px solid var(--border); color: var(--text-dim); padding: 9px 6px; border-radius: 9px; cursor: pointer; font-family: inherit; font-size: 13px; }
.mode-btn.active {
  color: var(--accent); border-color: rgba(52, 227, 163, 0.5); background: var(--accent-soft);
}

.pack-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  width: 100%; max-width: 100%; min-width: 0; overflow-x: hidden;
}
@media (min-width: 1400px) { .pack-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.pack-card {
  background: var(--bg-3); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 8px 10px; cursor: pointer; color: var(--text); font-family: inherit;
  text-align: center; min-width: 0; max-width: 100%; overflow: hidden;
  transition: border-color .15s, background .15s, transform .12s;
}
.pack-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.pack-card.active {
  border-color: rgba(52, 227, 163, 0.55);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px rgba(52, 227, 163, 0.2);
}
.pack-emoji { font-size: 22px; display: block; margin-bottom: 5px; line-height: 1.2; }
.pack-card b { display: block; font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px; }
.pack-card small {
  color: var(--text-dim); font-size: 10px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; white-space: normal;
}

/* ---- template groups ---- */
.tpl-group {
  grid-column: 1 / -1; font-size: 12px; font-weight: 600; color: var(--accent-2);
  margin-top: 8px; padding-bottom: 2px; border-bottom: 1px solid var(--border);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.swatch.active { outline-color: var(--accent); }
