@font-face {
  font-family: 'KoZ 028 Uni';
  src: url('/assets/fonts/KoZ028Uni.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-deep: #090e1a;
  --bg-stage: #151924;
  --card-bg: #1b2234;
  --card-elevated: #232d44;
  --mint: #10b981;
  --mint-bright: #34d399;
  --mint-dark: #047857;
  --cyan: #06b6d4;
  --cyan-bright: #22d3ee;
  --cyan-dark: #0e7490;
  --danger: #f43f5e;
  --text: #f8fafc;
  --muted: #94a3b8;
  --font-my: 'KoZ 028 Uni', 'Noto Sans Myanmar', 'Inter', system-ui, sans-serif;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sweep: cubic-bezier(0.65, 0, 0.35, 1);
}

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

html, body {
  height: 100%;
  overscroll-behavior-y: contain;
  font-family: var(--font-my);
  background:
    radial-gradient(circle at 12% 10%, rgba(16, 185, 129, 0.14), transparent 42%),
    radial-gradient(circle at 88% 88%, rgba(6, 182, 212, 0.14), transparent 42%),
    var(--bg-deep);
  color: var(--text);
  overflow: hidden;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; color: var(--cyan-bright); }

/* ==================== APP SHELL ==================== */
.app-root {
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
  gap: 8px;
}

.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(21, 25, 36, 0.9);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: 18px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; overflow: hidden; }
.brand-dot {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--mint-bright), var(--cyan));
  color: #022c22;
  display: grid; place-items: center; font-size: 16px;
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.5), 0 4px 0 var(--mint-dark);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.brand-name { font-weight: 800; font-size: 15.5px; letter-spacing: -0.02em; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 10px; color: var(--mint-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
@media (max-width: 480px) {
  .app-header { padding: 8px 10px; gap: 6px; }
  .brand-dot { width: 26px; height: 26px; font-size: 13px; }
  .brand-name { font-size: 13px; }
  .brand-sub { display: none; }
  .header-actions { gap: 4px; }
  .cost-chip { padding: 3px 6px; }
  .cost-usd { font-size: 12px; }
  .cost-tok { font-size: 9px; }
  .btn-sm { padding: 5px 7px; font-size: 10.5px; }
}
.cost-chip {
  background: rgba(16, 185, 129, 0.13);
  border: 1px solid rgba(52, 211, 153, 0.4);
  border-radius: 12px;
  padding: 4px 10px;
  text-align: right;
}
.cost-usd { font-size: 13.5px; font-weight: 800; color: var(--mint-bright); line-height: 1.1; }
.cost-tok { font-size: 9.5px; color: #a7f3d0; }

/* ==================== 4D TACTILE BUTTONS ==================== */
.btn-4d {
  position: relative;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
  transform: translate3d(0, 0, 0);
  transition: transform 0.18s var(--spring), box-shadow 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}
.btn-4d:disabled { opacity: 0.42; cursor: not-allowed; pointer-events: none; }
@media (hover: hover) {
  .btn-4d:hover:not(:disabled) { filter: brightness(1.08); transform: translate3d(0, -1px, 0); }
}
.btn-4d:active:not(:disabled) {
  transform: translate3d(0, 4px, 0) scale(0.96) !important;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.btn-pill {
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 13.5px;
  color: #022c22;
  background: linear-gradient(135deg, var(--mint-bright), var(--cyan));
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.55), 0 5px 0 var(--mint-dark), 0 10px 22px rgba(16,185,129,0.32);
}
.btn-pill:active:not(:disabled) {
  box-shadow: inset 0 2px 3px rgba(255,255,255,0.4), 0 1px 0 var(--mint-dark);
}

.btn-ghost {
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  background: var(--card-elevated);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.09);
  box-shadow: 0 4px 0 #0e1320, 0 6px 14px rgba(0,0,0,0.3);
}
.btn-ghost:active:not(:disabled) { box-shadow: 0 1px 0 #0e1320; }

.btn-sm { padding: 7px 11px; font-size: 11.5px; }
.btn-icon { width: 42px; height: 42px; padding: 0; font-size: 18px; flex-shrink: 0; }
.btn-full { width: 100%; }

/* ==================== NEON SHELL & DIAGONAL SWEEP ==================== */
.stage-shell {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: 24px;
  background: var(--bg-stage);
  border: 1.5px solid rgba(52, 211, 153, 0.55);
  box-shadow: 0 0 28px rgba(16, 185, 129, 0.16), 0 24px 55px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.diagonal-curtain {
  position: absolute;
  inset: -30%;
  background: linear-gradient(145deg, rgba(16,185,129,0.88), rgba(6,182,212,0.88) 55%, rgba(8,51,68,0.95));
  border-left: 2px solid var(--mint-bright);
  transform: translate3d(130%, 0, 0) skewX(-18deg);
  pointer-events: none;
  z-index: 40;
  will-change: transform;
}
.diagonal-curtain.sweeping {
  animation: diagonalSweep 0.72s var(--sweep) forwards;
}
@keyframes diagonalSweep {
  0%   { transform: translate3d(130%, 0, 0) skewX(-18deg); }
  45%  { transform: translate3d(0%, 0, 0) skewX(-12deg); }
  100% { transform: translate3d(-135%, 0, 0) skewX(-18deg); }
}

.view-panel {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(40px, 0, 0);
  filter: blur(8px);
  transition: transform 0.5s var(--sweep), opacity 0.45s ease, filter 0.45s ease;
  display: flex;
  flex-direction: column;
}
.view-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate3d(0, 0, 0);
  filter: blur(0px);
  z-index: 5;
}

.stagger-item {
  transition: transform 0.55s var(--spring), opacity 0.45s ease;
  transition-delay: calc(0.05s * var(--li, 0));
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.center-narrow { max-width: 620px; width: 100%; margin: 0 auto; }

/* ==================== 4D CLAY CARDS & INPUTS ==================== */
.clay-card {
  background: linear-gradient(165deg, #212b42, #161d2f);
  border-radius: 20px;
  padding: 18px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 14px 30px rgba(2,6,23,0.5), inset 0 2px 2px rgba(255,255,255,0.1);
}
.card-eyebrow { font-size: 11px; font-weight: 800; color: var(--mint-bright); letter-spacing: 0.06em; margin-bottom: 6px; }
.hero-title { font-size: 20px; font-weight: 800; line-height: 1.3; margin-bottom: 6px; }
.hero-desc { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }

.float-field { position: relative; margin: 12px 0; padding-top: 16px; }
.float-field input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid rgba(148,163,184,0.45);
  padding: 8px 36px 7px 0;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.25s ease;
}
.float-field label {
  position: absolute; left: 0; top: 22px;
  font-size: 13px; color: var(--muted); pointer-events: none;
  transition: transform 0.25s var(--spring), color 0.25s ease, font-size 0.25s ease;
}
.float-field input:focus,
.float-field input:not(:placeholder-shown) { border-bottom-color: var(--accent-bright, var(--mint-bright)); }
.float-field input:focus ~ label,
.float-field input:not(:placeholder-shown) ~ label {
  transform: translateY(-20px); font-size: 11px; color: var(--mint-bright); font-weight: 700;
}
.field-icon-btn {
  position: absolute; right: 2px; bottom: 6px;
  background: none; border: none; cursor: pointer; font-size: 16px; color: var(--muted);
}

.key-meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.key-action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 12px; }
.float-field input:disabled { opacity: 0.65; cursor: not-allowed; }
.key-saved-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: #a7f3d0;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 14px;
}
.meta-pill {
  font-size: 11px; color: var(--muted);
  background: rgba(15,23,42,0.7);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 4px 10px; border-radius: 999px;
}

.section-label { font-size: 12.5px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.btn-mode {
  flex-direction: column; align-items: flex-start; text-align: left;
  padding: 12px; border-radius: 16px;
  background: var(--card-elevated); color: var(--text);
  border: 1.5px solid rgba(255,255,255,0.08);
  box-shadow: 0 5px 0 #0e1320;
}
.btn-mode.active {
  background: linear-gradient(155deg, rgba(16,185,129,0.22), rgba(6,182,212,0.18));
  border-color: var(--mint-bright);
  box-shadow: 0 5px 0 var(--mint-dark), 0 0 18px rgba(16,185,129,0.25);
}
.mode-emoji { font-size: 20px; }
.mode-name { font-size: 13.5px; font-weight: 800; }
.mode-hint { font-size: 10.5px; color: var(--muted); font-weight: 500; line-height: 1.35; }

.error-banner {
  background: rgba(244,63,94,0.14);
  border: 1px solid rgba(244,63,94,0.5);
  color: #fda4af;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ==================== DEDICATED FULL-HEIGHT AI CHAT ==================== */
.chat-layout {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-topbar {
  flex-shrink: 0;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.72);
  border-bottom: 1px solid rgba(52,211,153,0.16);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.chat-status { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pulse-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--mint-bright); flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(52,211,153,0.5);
  animation: pulseDot 2s infinite;
}
@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0.45); }
  50% { box-shadow: 0 0 0 8px rgba(52,211,153,0); }
}
.chat-title { font-size: 13.5px; font-weight: 800; color: var(--cyan-bright); }
.chat-subtitle { font-size: 11px; color: var(--muted); }
.chat-top-actions { display: flex; gap: 8px; align-items: center; }

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: min(86%, 680px);
  padding: 12px 15px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msgPop 0.28s var(--spring) both;
}
@keyframes msgPop {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(0.97); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
.msg-ai {
  align-self: flex-start;
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.09);
  border-bottom-left-radius: 5px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}
.msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(16,185,129,0.26), rgba(6,182,212,0.22));
  border: 1px solid rgba(52,211,153,0.4);
  border-bottom-right-radius: 5px;
}
.msg-photo-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--mint-bright);
  background: rgba(16,185,129,0.14);
  padding: 3px 8px;
  border-radius: 8px;
}

.photo-attachment {
  flex-shrink: 0;
  margin: 0 14px 8px;
  padding: 8px 12px;
  background: var(--card-bg);
  border: 1px solid rgba(52,211,153,0.35);
  border-radius: 14px;
  display: flex; align-items: center; gap: 10px;
}
.photo-attachment img { width: 42px; height: 42px; object-fit: cover; border-radius: 8px; }
.photo-attach-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.photo-attach-title { font-size: 11.5px; color: var(--mint-bright); font-weight: 700; }

.clay-select {
  background: #0f172a;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 10px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
}

.chat-composer {
  flex-shrink: 0;
  padding: 10px 14px 12px;
  background: rgba(15, 23, 42, 0.85);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: flex-end; gap: 8px;
}
.chat-composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 110px;
  resize: none;
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  outline: none;
}
.chat-composer textarea:focus { border-color: var(--mint-bright); }
.btn-send { padding: 10px 18px; height: 42px; flex-shrink: 0; }

/* ==================== SCENES & CHARACTER SHEET ==================== */
.config-bar { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; }
.config-group { display: flex; flex-direction: column; gap: 8px; }
.config-label { font-size: 12px; font-weight: 700; color: var(--mint-bright); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-chip {
  padding: 8px 13px; border-radius: 12px; font-size: 12px;
  background: var(--card-elevated); color: var(--text);
  box-shadow: 0 3px 0 #0e1320;
}
.btn-chip.active {
  background: linear-gradient(135deg, var(--mint-bright), var(--accent, var(--mint)));
  color: #022c22;
  box-shadow: 0 3px 0 var(--mint-dark);
}

.section-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.section-title { font-size: 15px; font-weight: 800; }

.char-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.char-card {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.char-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.char-swatch { width: 18px; height: 18px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.3); }
.char-look { font-size: 11.5px; color: var(--muted); line-height: 1.45; }

.scene-list { display: flex; flex-direction: column; gap: 10px; }
.scene-item {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 16px;
  padding: 12px;
  display: flex; gap: 12px; align-items: flex-start;
}
.scene-thumb-canvas {
  width: 68px; height: 120px; border-radius: 10px; flex-shrink: 0;
  border: 1px solid rgba(52,211,153,0.4);
  background: #090e1a;
}
.scene-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.scene-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--mint-bright); font-weight: 700; }
.scene-vo { font-size: 13px; line-height: 1.55; }
.scene-sub { font-size: 11.5px; color: #cbd5e1; background: rgba(0,0,0,0.35); padding: 5px 8px; border-radius: 8px; }
.scene-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ==================== VOICES & EXPORT ==================== */
.voice-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.voice-row {
  background: rgba(15,23,42,0.72);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  padding: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}

.export-layout {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 780px) {
  .export-layout { grid-template-columns: 1fr; }
}
.preview-column { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.phone-stage-frame {
  width: min(100%, 280px);
  aspect-ratio: 9 / 16;
  border-radius: 22px;
  overflow: hidden;
  border: 2px solid rgba(52,211,153,0.6);
  box-shadow: 0 20px 44px rgba(0,0,0,0.6);
  background: #000;
}
#preview-canvas { width: 100%; height: 100%; display: block; }
.preview-controls { display: flex; gap: 10px; }

.export-summary {
  background: rgba(15,23,42,0.7);
  border-radius: 14px;
  padding: 12px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #cbd5e1;
  margin-bottom: 14px;
}
.progress-wrap { margin-bottom: 14px; }
.progress-bar-bg { height: 12px; border-radius: 999px; background: #0f172a; overflow: hidden; border: 1px solid rgba(255,255,255,0.1); }
.progress-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--mint), var(--cyan-bright)); transition: width 0.25s ease; }
.progress-status { font-size: 12px; color: var(--mint-bright); font-weight: 700; margin-top: 6px; }
.export-actions { display: flex; flex-direction: column; gap: 10px; }

/* ==================== STYLE PICKER TAB ==================== */
.style-layout {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 780px) {
  .style-layout { grid-template-columns: 1fr; }
}
.style-preview-col { display: flex; flex-direction: column; align-items: center; gap: 10px; position: sticky; top: 0; }
@media (max-width: 780px) { .style-preview-col { position: static; } }
#style-live-canvas { width: 100%; height: 100%; display: block; }
.style-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 10px;
}
.style-card-btn {
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  padding: 8px;
  border-radius: 15px;
  background: rgba(15, 23, 42, 0.78);
  border: 1.5px solid rgba(255,255,255,0.09);
  color: var(--text);
  box-shadow: 0 4px 0 #0b101c;
}
.style-card-btn.active {
  background: linear-gradient(155deg, rgba(16,185,129,0.25), rgba(6,182,212,0.2));
  border-color: var(--mint-bright);
  box-shadow: 0 4px 0 var(--mint-dark), 0 0 16px rgba(16,185,129,0.28);
}
.style-card-thumb { width: 100%; aspect-ratio: 9 / 16; border-radius: 10px; background: #090e1a; margin-bottom: 6px; }
.style-card-name { font-size: 12px; font-weight: 800; line-height: 1.25; }
.style-card-desc { font-size: 10px; color: var(--muted); font-weight: 500; line-height: 1.3; margin-top: 2px; }

/* ==================== BOTTOM DOCK ==================== */
.bottom-dock {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px;
  background: rgba(21, 25, 36, 0.92);
  border: 1px solid rgba(52, 211, 153, 0.22);
  border-radius: 18px;
}
.bottom-dock.bottom-dock-6 {
  grid-template-columns: repeat(6, 1fr);
}
@media (max-width: 480px) {
  .bottom-dock.bottom-dock-6 { gap: 4px; padding: 6px; }
  .bottom-dock.bottom-dock-6 .dock-btn { font-size: 9.5px; padding: 8px 2px; }
}
.dock-btn {
  padding: 9px 4px;
  border-radius: 12px;
  font-size: 11px;
  background: var(--card-elevated);
  color: var(--muted);
  box-shadow: 0 3px 0 #0e1320;
}
.dock-btn.active {
  background: linear-gradient(135deg, var(--mint-bright), var(--mint));
  color: #022c22;
  box-shadow: 0 3px 0 var(--mint-dark), 0 0 14px rgba(16,185,129,0.35);
}
