/* ==========================================================================
   Livezala Enterprise — AI Image Studio & Storyteller
   Universal Multi-Device Responsive Design System (Mobile, Tablet, Desktop)
   Design Tokens matching livezala.com & db.livezala.com
   ========================================================================== */

:root {
  --bg: #0a0a0a;
  --bg-side: #0f0f0f;
  --surface: #141414;
  --surface-2: #1a1a1a;
  --hover: #1f1f1f;
  --border: #232323;
  --border-2: #2e2e2e;
  --border-active: #ff8a3d;

  --text: #ededed;
  --text-2: #a3a3a3;
  --text-3: #6e6e6e;

  /* Livezala Signature Brand Accent: Vibrant Orange */
  --accent: #ff8a3d;
  --accent-soft: rgba(255, 138, 61, 0.12);
  --accent-glow: rgba(255, 138, 61, 0.28);
  --accent-hover: #ff9d5c;

  --btn-bg: #ededed;
  --btn-tx: #0a0a0a;
  --wm2: #a3a3a3;

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --font: 'Inter', 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --r-sm: 6px;
  --r: 8px;
  --r-lg: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --transition: 140ms ease;

  color-scheme: dark;
}

html.light {
  --bg: #fafafa;
  --bg-side: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --hover: #ededed;
  --border: #e5e5e5;
  --border-2: #d4d4d4;
  --border-active: #e8701f;

  --text: #171717;
  --text-2: #525252;
  --text-3: #8a8a8a;

  --accent: #e8701f;
  --accent-soft: rgba(232, 112, 31, 0.10);
  --accent-glow: rgba(232, 112, 31, 0.22);
  --accent-hover: #f18235;

  --btn-bg: #171717;
  --btn-tx: #ffffff;
  --wm2: #525252;

  --shadow: 0 6px 20px rgba(0, 0, 0, 0.08);

  color-scheme: light;
}

/* Base Resets */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 64px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Custom Sleek Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
}

a {
  color: inherit;
  text-decoration: none;
}
img {
  max-width: 100%;
  display: block;
}
b, strong {
  font-weight: 600;
}
::selection {
  background: var(--accent-soft);
  color: var(--text);
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

svg.i {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  vertical-align: -2px;
}

/* ==========================================================================
   OFFICIAL COMPACT HEADER (snav) — 1-Row on ALL Screen Sizes
   ========================================================================== */
.snav {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.snav-wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 54px;
  white-space: nowrap;
}

/* Livezala Logo B */
.lk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
}
svg.mk {
  display: block;
  flex: none;
  width: 24px;
  height: 24px;
  color: var(--text);
}
svg.mk .mkl { fill: currentColor; }
svg.mk .mkd { fill: var(--accent); }

.wm {
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.wm .wm2 {
  color: var(--wm2);
  font-weight: 500;
  font-size: 13.5px;
}

/* Mode Switcher Tabs (Segmented Control) */
.nav-tabs {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 3px;
  gap: 3px;
  flex-shrink: 0;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.nav-tab:hover {
  color: var(--text);
  background: var(--hover);
}

.nav-tab.active {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.nav-badge {
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}

.sp {
  flex: 1;
}

/* Header Right Actions */
.acts {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.staff {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 0 10px;
  height: 32px;
  border-radius: var(--r);
  transition: background var(--transition), color var(--transition);
}
.staff:hover {
  background: var(--hover);
  color: var(--text);
}

.lnk {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
  padding: 0 6px;
}
.lnk:hover {
  color: var(--accent);
}

/* Universal Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--r);
  border: 1px solid var(--btn-bg);
  background: var(--btn-bg);
  color: var(--btn-tx);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  user-select: none;
}
.btn:hover:not(:disabled) {
  filter: brightness(0.92);
}
.btn:active:not(:disabled) {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.sec {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-2);
}
.btn.sec:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--text-3);
  filter: none;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
  filter: none;
}

.btn.sm {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn.btn-accent {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
  filter: none;
}

/* Icon Buttons (.ibtn) */
.ibtn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  flex: none;
  transition: all var(--transition);
}
.ibtn:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--border-2);
}
.ibtn.sm {
  width: 26px;
  height: 26px;
}

/* Theme Toggle Moon/Sun */
.ibtn .sun { display: none; }
.ibtn .moon { display: block; }
html.light .ibtn .sun { display: block; }
html.light .ibtn .moon { display: none; }

.mtog { display: none; }
.mmenu { display: none; }

/* Tag Pill */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--surface-2);
  white-space: nowrap;
}

/* ==========================================================================
   WORKSPACE LAYOUT & ADAPTIVE FLOW (DESKTOP / TABLET / MOBILE)
   ========================================================================== */
.main-container {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  gap: 20px;
  min-height: 0;
}

.view-wrapper {
  display: flex;
  width: 100%;
  gap: 20px;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.panel-left {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}
.panel-left::-webkit-scrollbar {
  width: 6px;
}
.panel-left::-webkit-scrollbar-track {
  background: transparent;
}
.panel-left::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 99px;
}
.panel-left::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
}

.panel-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Panel Sections */
.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.section-title svg.i {
  color: var(--accent);
}

/* Form Inputs */
.select-input,
.text-input,
.prompt-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.select-input {
  height: 38px;
  padding: 0 10px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.text-input {
  height: 36px;
  padding: 0 10px;
}

.select-input:focus,
.text-input:focus,
.prompt-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Compact Model Pricing Badge */
.model-info {
  margin-top: 4px;
}
.model-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.model-price-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}
.model-price-pill.warning {
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.1);
}
.model-price-pill .thb-sub {
  color: var(--text-2);
  font-size: 11px;
  font-weight: 400;
}
.model-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.model-details-toggle {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-3);
  cursor: pointer;
}
.model-details-toggle summary {
  color: var(--accent);
  outline: none;
  user-select: none;
}
.model-details-body {
  margin-top: 4px;
  line-height: 1.5;
  padding-left: 6px;
  border-left: 2px solid var(--border-2);
}

/* ==========================================================================
   STYLE GRID & RATIO GRID — ORIGINAL DESKTOP MULTI-COLUMN GRID
   ========================================================================== */
.style-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.selected-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid rgba(255, 138, 61, 0.25);
}

.style-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  text-align: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.style-chip:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--text-3);
}
.style-chip:active {
  transform: scale(0.96);
  background: var(--hover);
}
.style-chip.active {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--accent);
}
.style-chip .emoji {
  font-size: 16px;
  line-height: 1;
}
.style-chip .label {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Ratio Chips */
.ratio-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  text-align: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.ratio-chip:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--text-3);
}
.ratio-chip:active {
  transform: scale(0.96);
}
.ratio-chip.active {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--accent);
}
.ratio-box {
  border: 1.5px solid currentColor;
  border-radius: 2px;
  display: inline-block;
  opacity: 0.85;
}
.ratio-label {
  font-size: 11px;
  white-space: nowrap;
}

/* Advanced Settings Accordion */
.adv-details {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-top: 4px;
}
.adv-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  outline: none;
}
.adv-summary:hover {
  color: var(--text);
  background: var(--hover);
}
.adv-arrow {
  transition: transform 0.2s ease;
  color: var(--text-3);
}
.adv-details[open] .adv-arrow {
  transform: rotate(180deg);
}
.adv-body {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}
.adv-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.count-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.count-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.count-chip:hover {
  background: var(--hover);
  color: var(--text);
}
.count-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
  border-radius: 2px;
  display: inline-block;
  opacity: 0.8;
}

/* Count & Seed Controls */
.count-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.count-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-input-row input {
  width: 70px;
}
.count-hint {
  font-size: 11.5px;
  color: var(--text-3);
}

.seed-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================================================
   CENTER: PROMPT & OUTPUT
   ========================================================================== */
.prompt-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prompt-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.prompt-label svg.i {
  color: var(--accent);
}

.prompt-hint {
  font-size: 11.5px;
  color: var(--text-3);
}

.prompt-input {
  resize: vertical;
  min-height: 95px;
  padding: 10px 12px;
  font-size: 13.5px;
}

/* Reference Upload Area */
.ref-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ref-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ref-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
}

.ref-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 50px;
}

.ref-dropzone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: var(--bg);
  border: 1.5px dashed var(--border-2);
  border-radius: var(--r);
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.ref-dropzone:hover,
.ref-dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.ref-thumb-box {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--border-2);
  background: var(--bg);
}
.ref-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ref-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* Generate Actions */
.prompt-actions {
  display: flex;
  justify-content: flex-end;
}

.btn-generate {
  height: 42px;
  padding: 0 24px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
}

/* Output Area */
.output-area {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 380px;
}

.output-placeholder {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-2);
  max-width: 400px;
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  width: 100%;
}

.output-card {
  position: relative;
  border-radius: var(--r);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #080808;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), border-color var(--transition);
}
.output-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.output-card img {
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: contain;
  cursor: pointer;
  display: block;
}

.output-card-actions {
  position: absolute;
  inset: auto 0 0 0;
  padding: 10px;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--transition);
}
.output-card:hover .output-card-actions {
  opacity: 1;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  z-index: 10;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-sub {
  font-size: 12.5px;
  color: var(--text-3);
  font-family: var(--mono);
}

/* ==========================================================================
   STORY MODE STYLES
   ========================================================================== */
.story-settings-panel {
  width: 360px;
}

.char-badge-status {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 6px;
}

.char-roster-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.char-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: all var(--transition);
}
.char-card:hover {
  background: var(--hover);
  border-color: var(--border-2);
}
.char-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.char-card-check {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.char-card-thumb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-2);
  flex-shrink: 0;
}

.char-card-info {
  flex: 1;
  min-width: 0;
}
.char-card-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char-card-desc {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-card-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* Character Form Box */
.char-form-box {
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 12px;
  margin-top: 8px;
}
.char-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.char-form-preview {
  display: flex;
  align-items: center;
  gap: 8px;
}
.char-form-preview img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-2);
}

.chaining-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  line-height: 1.45;
}
.chaining-label input[type="checkbox"] {
  accent-color: var(--accent);
  margin-top: 2px;
  width: 15px;
  height: 15px;
}

/* Story Center */
.story-main-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.story-input-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.story-input-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}
.story-input-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text);
}
.story-input-title svg.i {
  color: var(--accent);
}

.story-input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Story Status Bar */
.story-status-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 16px;
}
.story-status-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.story-progress-track {
  width: 100%;
  height: 5px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.story-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* Story Action Bar */
.story-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
.story-action-left {
  display: flex;
  align-items: center;
}
.story-action-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Scenes Container & Timeline Grid */
.story-scenes-container {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  overflow-y: auto;
}

.story-scenes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.scene-card {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition);
}
.scene-card:hover {
  border-color: var(--border-2);
}
.scene-card.generating {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.scene-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.scene-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}

.scene-card-img-wrap {
  position: relative;
  aspect-ratio: 16/9;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.scene-card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}
.scene-card-placeholder {
  color: var(--text-3);
  font-size: 11.5px;
}

.scene-card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.scene-caption-th {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  font-weight: 500;
}
.scene-prompt-en {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.4;
  background: var(--surface-2);
  padding: 6px 8px;
  border-radius: var(--r-sm);
  max-height: 60px;
  overflow-y: auto;
}

.scene-card-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

/* ==========================================================================
   FULLSCREEN STORY PLAYER
   ========================================================================== */
.story-player {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: #000000;
  color: #ffffff;
}

.story-player-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(16px);
}

.story-player-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 110;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}
.story-player-close:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.story-player-stage {
  position: relative;
  z-index: 105;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 16px;
  min-height: 0;
}

.story-player-img-wrap {
  max-height: calc(100vh - 200px);
  max-width: 92vw;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.85);
}
.story-player-img-wrap img {
  max-height: calc(100vh - 200px);
  max-width: 100%;
  object-fit: contain;
}

.story-player-caption-box {
  margin-top: 12px;
  text-align: center;
  max-width: 760px;
  padding: 0 16px;
}
.story-player-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.story-player-caption {
  font-size: 15.5px;
  line-height: 1.55;
  color: #f0f0f0;
}

.story-player-controls {
  position: relative;
  z-index: 105;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(15, 15, 15, 0.85);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-wrap: wrap;
}
.story-ctrl-btn {
  color: #fff !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
}
.story-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.15) !important;
}

.story-player-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
}

.story-player-timeline {
  position: relative;
  z-index: 105;
  display: flex;
  gap: 6px;
  padding: 8px 16px 12px;
  background: rgba(15, 15, 15, 0.85);
  justify-content: center;
  overflow-x: auto;
}
.story-dot {
  width: 10px;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.story-dot.active {
  background: var(--accent);
  width: 24px;
}

/* ==========================================================================
   LIGHTBOX MODAL
   ========================================================================== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(10px);
}
.lightbox-close-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 210;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.6);
}
.lightbox-content {
  position: relative;
  z-index: 205;
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lightbox-content img {
  max-width: 92vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--r);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}
.lightbox-actions {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   RIGHT DRAWER: GALLERY / HISTORY
   ========================================================================== */
.panel-right {
  width: 320px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100vh - 100px);
}
.panel-right-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.panel-right-content {
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

/* ==========================================================================
   DEDICATED FULLSCREEN GALLERY VIEW
   ========================================================================== */
.gallery-view-wrapper {
  display: block;
  width: 100%;
}

.gallery-full-container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gallery-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 20px;
}

.gallery-title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gallery-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.gallery-title-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
  flex-shrink: 0;
}

.gallery-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.01em;
}

.gallery-count-badge {
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px 9px;
}

.gallery-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin: 0;
  line-height: 1.5;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.gallery-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 10px;
  height: 36px;
}

.gallery-search-box svg.i {
  width: 15px;
  height: 15px;
  color: var(--text-3);
  flex-shrink: 0;
}

.gallery-search-input {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  width: 170px;
}

.gallery-loading {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 60px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.gallery-empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 60px 20px;
  min-height: 340px;
}

/* ==========================================================================
   MASONRY GRID — 100% PRESERVES NATURAL ASPECT RATIO (NO CROPPING)
   ========================================================================== */
.gallery-masonry {
  column-count: 4;
  column-gap: 16px;
  width: 100%;
}

@media (max-width: 1300px) {
  .gallery-masonry {
    column-count: 3;
    column-gap: 14px;
  }
}

@media (max-width: 850px) {
  .gallery-masonry {
    column-count: 2;
    column-gap: 10px;
  }
}

@media (max-width: 480px) {
  .gallery-masonry {
    column-count: 2;
    column-gap: 8px;
  }
}

.gallery-card {
  break-inside: avoid;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  position: relative;
}

@media (max-width: 600px) {
  .gallery-card {
    margin-bottom: 10px;
    border-radius: var(--r-sm);
  }
}

.gallery-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.gallery-card-img-wrap {
  position: relative;
  width: 100%;
  background: #000;
  cursor: pointer;
  overflow: hidden;
}

.gallery-card-img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.3s ease;
}

.gallery-card:hover .gallery-card-img {
  transform: scale(1.02);
}

.gallery-ratio-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 10.5px;
  font-family: var(--font-mono, monospace);
  font-weight: 600;
  color: #fff;
  pointer-events: none;
  z-index: 2;
}

.gallery-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.2) 60%, rgba(0,0,0,0) 100%);
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition);
  z-index: 3;
}

.gallery-card:hover .gallery-card-overlay {
  opacity: 1;
}

.gallery-zoom-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 99px;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
}

.gallery-zoom-hint svg.i {
  width: 14px;
  height: 14px;
}

.gallery-card-info {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

@media (max-width: 480px) {
  .gallery-card-info {
    padding: 8px 6px;
    gap: 6px;
  }
}

.gallery-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gallery-card-filename {
  font-size: 11.5px;
  font-family: var(--font-mono, monospace);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card-date {
  font-size: 10.5px;
  color: var(--text-3);
}

.gallery-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.gallery-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 11px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  flex: 1;
  text-align: center;
}

.gallery-action-btn:hover {
  background: var(--hover);
  border-color: var(--border-hover);
  color: var(--text);
}

.gallery-action-btn svg.i {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.gallery-delete-btn {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.25);
}

.gallery-delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

/* Legacy side panel gallery styles (fallback) */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.gallery-item {
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  background: #000;
  position: relative;
}
.gallery-item img {
  width: 100%;
  height: auto;
  max-height: 180px;
  object-fit: contain;
  display: block;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 40px);
}
.toast {
  padding: 9px 14px;
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.2s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--accent); }
@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   OFFICIAL FOOTER (sfoot)
   ========================================================================== */
.sfoot {
  margin-top: auto;
  padding: 28px 0 36px;
  border-top: 1px solid var(--border);
  background: var(--bg-side);
}

.sfoot-wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-3);
}

.sfoot .lk svg.mk {
  width: 20px;
  height: 20px;
}
.sfoot .wm {
  font-size: 13.5px;
}

.sfoot nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.sfoot nav a {
  color: var(--text-2);
  transition: color var(--transition);
}
.sfoot nav a:hover {
  color: var(--accent);
}

.sfoot .copy {
  width: 100%;
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 4px;
  line-height: 1.5;
}

/* ==========================================================================
   RESPONSIVE DESIGN BREAKPOINTS — TAILORED FOR ALL DEVICES
   ========================================================================== */

/* TABLETS (Portrait & Landscape: 600px - 1080px) */
@media (max-width: 1080px) {
  .main-container {
    padding: 12px;
  }
  .view-wrapper {
    flex-direction: column;
    gap: 14px;
  }

  .panel-left,
  .story-settings-panel {
    width: 100%;
    max-height: none;
    overflow: visible;
  }

  .output-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .panel-right {
    width: 100%;
    max-height: none;
  }
}

/* SMARTPHONES & SMALL TABLETS (< 768px) */
@media (max-width: 768px) {
  .snav-wrap {
    padding: 0 12px;
    height: 50px;
  }
  .wm .wm2 {
    display: none; /* Hide subtitle to keep header on 1 clean line */
  }
  .nav-tabs {
    padding: 2px;
  }
  .nav-tab {
    padding: 4px 8px;
    font-size: 11.5px;
    gap: 4px;
  }
  .nav-badge {
    display: none;
  }

  .snav .hide-m {
    display: none;
  }
  .mtog {
    display: inline-grid;
  }

  .mmenu.open {
    display: block;
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px 16px;
    box-shadow: var(--shadow);
    z-index: 60;
  }
  .mmenu a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text);
  }
  .mmenu a.staff {
    border: 0;
    padding: 10px 0 0;
    color: var(--text-2);
  }

  .story-input-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .story-action-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .story-action-right {
    width: 100%;
    justify-content: space-between;
  }
  .story-scenes-grid {
    grid-template-columns: 1fr;
  }

  /* Mobile Swipe for Style & Ratio chips (keeps mobile screen compact) */
  .style-grid,
  .ratio-grid {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding: 6px 2px 10px;
    scrollbar-width: none;
    touch-action: pan-x;
  }
  .style-grid::-webkit-scrollbar,
  .ratio-grid::-webkit-scrollbar {
    display: none;
  }
  .style-chip {
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 99px;
    font-size: 13px;
    white-space: nowrap;
  }
  .style-chip .label {
    font-size: 13px;
    max-width: none;
  }
  .ratio-chip {
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--r-sm);
    font-size: 12.5px;
    white-space: nowrap;
  }
}

/* SMALL SCREENS (< 480px) */
@media (max-width: 480px) {
  .snav-wrap {
    padding: 0 8px;
  }
  .output-grid {
    grid-template-columns: 1fr;
  }
  .story-player-img-wrap {
    max-height: 55vh;
  }
  .story-player-caption {
    font-size: 14px;
  }
}
