/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface2: #1a1a1a;
  --surface3: #222222;
  --border: #2a2a2a;
  --border2: #3a3a3a;
  --accent: #e8ff47;
  --accent2: #ff5f3d;
  --text: #f0f0f0;
  --text2: #888888;
  --text3: #444444;
  --font-display: 'Syne', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --radius: 2px;
  --trans: 150ms ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── NOISE OVERLAY ── */
.noise {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.025;
}

/* ── UTILITY ── */
.hidden { display: none !important; }

/* ── GATE ── */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.gate-inner {
  width: 100%; max-width: 460px;
  border: 1px solid var(--border2);
  padding: 48px 40px;
  background: var(--surface);
  animation: fadeUp 0.4s ease both;
}
.gate-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 8px;
}
.gate-logo-x {
  font-size: 28px; color: var(--accent);
  animation: spin 8s linear infinite;
  display: inline-block;
}
.gate-logo-text {
  font-family: var(--font-display);
  font-weight: 800; font-size: 22px;
  letter-spacing: 0.04em;
}
.gate-sub {
  color: var(--text2); margin-bottom: 36px; font-size: 12px;
}
.field-label {
  display: block;
  font-size: 10px; letter-spacing: 0.12em;
  color: var(--text2); margin-bottom: 8px; font-weight: 700;
}
.api-input-row { display: flex; gap: 8px; margin-bottom: 16px; }
.api-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--font-mono); font-size: 13px;
  padding: 12px 14px; outline: none; border-radius: var(--radius);
  transition: border-color var(--trans);
}
.api-input:focus { border-color: var(--accent); }
.toggle-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); cursor: pointer; padding: 0 14px;
  border-radius: var(--radius); font-size: 16px;
  transition: border-color var(--trans), color var(--trans);
}
.toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
.enter-btn {
  width: 100%; background: var(--accent); color: var(--bg);
  border: none; font-family: var(--font-display);
  font-weight: 800; font-size: 14px; letter-spacing: 0.08em;
  padding: 16px; cursor: pointer; border-radius: var(--radius);
  transition: opacity var(--trans), transform var(--trans);
}
.enter-btn:hover { opacity: 0.85; transform: translateY(-1px); }
.enter-btn:active { transform: translateY(0); }
.gate-hint { color: var(--text3); font-size: 11px; margin-top: 16px; line-height: 1.6; }

/* ── APP ── */
.app { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100vh; }

/* HEADER */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 52px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  flex-shrink: 0;
}
.header-logo {
  font-family: var(--font-display); font-weight: 800; font-size: 15px;
  letter-spacing: 0.04em; color: var(--accent);
}
.header-right { display: flex; align-items: center; gap: 16px; }
.api-badge {
  font-size: 10px; letter-spacing: 0.12em; color: #4dff91;
}
.change-key-btn {
  background: none; border: 1px solid var(--border2);
  color: var(--text2); font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.1em;
  padding: 6px 12px; cursor: pointer; border-radius: var(--radius);
  transition: all var(--trans);
}
.change-key-btn:hover { border-color: var(--accent2); color: var(--accent2); }
.toggle-panel-btn {
  display: none;
  background: none; border: 1px solid var(--border2);
  color: var(--text2); font-size: 16px;
  width: 34px; height: 34px; cursor: pointer;
  border-radius: var(--radius); transition: all var(--trans);
  align-items: center; justify-content: center; line-height: 1;
}
.toggle-panel-btn:hover { border-color: var(--accent); color: var(--accent); }

/* MAIN LAYOUT */
.main {
  display: grid; grid-template-columns: 360px 1fr;
  flex: 1; overflow: hidden;
}

/* ── LEFT PANEL ── */
.panel-left {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
}

/* MODE TABS */
.mode-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mode-tab {
  background: none; border: none; border-right: 1px solid var(--border);
  color: var(--text2); font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.1em; font-weight: 700;
  padding: 14px 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all var(--trans); white-space: nowrap;
}
.mode-tab:last-child { border-right: none; }
.mode-tab .tab-icon { font-size: 14px; }
.mode-tab:hover { color: var(--text); background: var(--surface2); }
.mode-tab.active { color: var(--accent); background: var(--surface2); border-bottom: 2px solid var(--accent); }

/* MODE PANELS */
.mode-panel { display: none; padding: 20px; flex-direction: column; gap: 16px; }
.mode-panel.active { display: flex; }
.section-label {
  font-size: 9px; letter-spacing: 0.15em; color: var(--accent2);
  font-weight: 700; border-left: 2px solid var(--accent2); padding-left: 8px;
}

/* FIELDS */
.field { display: flex; flex-direction: column; gap: 8px; }
.prompt-input {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--font-mono); font-size: 13px;
  padding: 12px 14px; resize: vertical; min-height: 90px;
  outline: none; border-radius: var(--radius); line-height: 1.5;
  transition: border-color var(--trans);
}
.prompt-input:focus { border-color: var(--accent); }

/* UPLOAD ZONES */
.upload-zone {
  position: relative; border: 1px dashed var(--border2);
  background: var(--surface2); cursor: pointer;
  min-height: 130px; display: flex; align-items: center;
  justify-content: center; border-radius: var(--radius);
  overflow: hidden; transition: border-color var(--trans);
}
.upload-zone:hover { border-color: var(--accent); }
.upload-zone.has-image { border-style: solid; border-color: var(--border2); }
.upload-zone.small { min-height: 90px; flex: 1; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2; }
.upload-placeholder {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; color: var(--text3); font-size: 11px; letter-spacing: 0.06em;
  pointer-events: none; text-align: center; padding: 8px;
}
.upload-icon { font-size: 20px; color: var(--text2); }
.upload-preview {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: none; z-index: 1;
}
.upload-zone.has-image .upload-placeholder { display: none; }
.upload-zone.has-image .upload-preview { display: block; }
.remove-upload {
  position: absolute; top: 6px; right: 6px; z-index: 3;
  background: rgba(0,0,0,0.75); border: none; color: var(--text);
  width: 22px; height: 22px; cursor: pointer; font-size: 12px;
  border-radius: 50%; display: none; align-items: center; justify-content: center;
  line-height: 1; transition: background var(--trans);
}
.upload-zone.has-image .remove-upload { display: flex; }
.remove-upload:hover { background: var(--accent2); }
.mix-slots { display: flex; gap: 8px; }

/* SETTINGS */
.divider { height: 1px; background: var(--border); flex-shrink: 0; }
.settings { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* MODEL BUTTONS */
.select-group { display: flex; flex-direction: column; gap: 6px; }
.model-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); cursor: pointer; padding: 10px 14px;
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  border-radius: var(--radius); transition: all var(--trans);
}
.model-btn:hover { border-color: var(--border); color: var(--text); }
.model-btn.active { border-color: var(--accent); background: rgba(232,255,71,0.06); }
.model-name {
  font-family: var(--font-display); font-weight: 700; font-size: 13px;
  letter-spacing: 0.06em;
}
.model-btn.active .model-name { color: var(--accent); }
.model-id { font-size: 10px; color: var(--text3); }

/* RATIO GRID */
.ratio-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px;
}
.ratio-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); font-family: var(--font-mono); font-size: 10px;
  padding: 7px 4px; cursor: pointer; border-radius: var(--radius);
  transition: all var(--trans); text-align: center; letter-spacing: 0.04em;
}
.ratio-btn:hover { border-color: var(--border); color: var(--text); }
.ratio-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(232,255,71,0.06); }

/* RESOLUTION */
.res-group { display: flex; gap: 8px; }
.res-btn {
  flex: 1; background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); font-family: var(--font-display); font-weight: 700;
  font-size: 14px; letter-spacing: 0.08em;
  padding: 10px; cursor: pointer; border-radius: var(--radius);
  transition: all var(--trans);
}
.res-btn:hover { border-color: var(--border); color: var(--text); }
.res-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(232,255,71,0.06); }

/* ── DURATION BUTTONS (reuse res-btn style) ── */
.dur-btn {
  flex: 1; padding: 8px 6px; border: 1px solid var(--border2);
  background: var(--surface2); color: var(--text2);
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; border-radius: var(--radius); transition: var(--trans);
}
.dur-btn:hover { border-color: var(--border); color: var(--text); }
.dur-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(232,255,71,0.06); }

/* ── VIDEO RESULT ── */
.result-video { max-width: 100%; max-height: 70vh; border-radius: var(--radius); display: block; margin: 0 auto; }

/* ── VIDEO POLLING NOTE ── */
.video-poll-note {
  font-size: 10px; color: var(--text2); text-align: center;
  margin-top: 8px; font-family: var(--font-mono); letter-spacing: 0.06em;
}

/* GENERATE BUTTON */
.generate-btn {
  margin: 0 20px 20px; background: var(--accent); color: var(--bg);
  border: none; font-family: var(--font-display);
  font-weight: 800; font-size: 15px; letter-spacing: 0.06em;
  padding: 18px; cursor: pointer; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: opacity var(--trans), transform var(--trans);
  flex-shrink: 0; position: sticky; bottom: 0;
}
.generate-btn:hover { opacity: 0.88; transform: translateY(-1px); }
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-loader { animation: blink 0.7s steps(1) infinite; letter-spacing: 0.2em; }

/* ── RIGHT PANEL ── */
.panel-right {
  display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden;
}
.output-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 52px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.output-title { font-size: 10px; letter-spacing: 0.14em; color: var(--text2); font-weight: 700; }
.output-actions { display: flex; gap: 8px; }
.action-btn {
  background: none; border: 1px solid var(--border2);
  color: var(--text2); font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.1em; font-weight: 700;
  padding: 7px 14px; cursor: pointer; border-radius: var(--radius);
  transition: all var(--trans);
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn--danger:hover { border-color: var(--accent2); color: var(--accent2); }

/* REMEMBER KEY */
.remember-row { margin-bottom: 4px; }
.remember-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--text2); font-size: 11px; cursor: pointer;
  user-select: none;
}
.remember-check { accent-color: var(--accent); cursor: pointer; width: 14px; height: 14px; }
.remember-label:hover { color: var(--text); }

.output-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: auto; padding: 32px; position: relative;
}

/* EMPTY STATE */
.output-empty { text-align: center; animation: fadeUp 0.5s ease both; }
.empty-graphic {
  display: flex; gap: 8px; justify-content: center; margin-bottom: 24px;
}
.empty-square {
  width: 40px; height: 40px; border: 1px solid var(--border2);
  animation: pulse 2s ease-in-out infinite;
}
.empty-square:nth-child(2) { animation-delay: 0.3s; width: 60px; height: 60px; }
.empty-square:nth-child(3) { animation-delay: 0.6s; width: 40px; height: 40px; }
.empty-text { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty-sub { color: var(--text3); font-size: 12px; }

/* LOADING */
.output-loading { text-align: center; }
.loading-grid {
  display: grid; grid-template-columns: repeat(2, 80px); gap: 4px;
  justify-content: center; margin-bottom: 24px;
}
.loading-cell {
  height: 80px; background: var(--surface2);
  animation: loadingFlash 1.2s ease-in-out infinite;
}
.loading-cell:nth-child(1) { animation-delay: 0s; }
.loading-cell:nth-child(2) { animation-delay: 0.2s; }
.loading-cell:nth-child(3) { animation-delay: 0.4s; }
.loading-cell:nth-child(4) { animation-delay: 0.6s; }
.loading-text { font-size: 12px; letter-spacing: 0.1em; color: var(--text2); }
.loading-dots::after {
  content: ''; animation: dots 1.5s steps(4) infinite;
}

/* RESULT */
.output-result { display: flex; flex-direction: column; align-items: center; gap: 16px; max-height: 100%; }
.result-img {
  max-width: 100%; max-height: calc(100vh - 220px);
  object-fit: contain; border: 1px solid var(--border);
  animation: fadeUp 0.4s ease both;
}
.result-meta { font-size: 10px; color: var(--text3); letter-spacing: 0.1em; }

/* ERROR */
.output-error { text-align: center; }
.error-icon { font-size: 32px; margin-bottom: 12px; color: var(--accent2); }
.error-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; margin-bottom: 8px; color: var(--accent2); }
.error-msg { color: var(--text2); font-size: 12px; max-width: 400px; line-height: 1.6; }

/* RE-EDIT BAR */
.reedit-bar {
  border-top: 1px solid var(--border); padding: 16px 24px;
  background: var(--surface); flex-shrink: 0;
  animation: slideUp 0.3s ease both;
}
.reedit-label { font-size: 9px; letter-spacing: 0.15em; color: var(--accent2); font-weight: 700; margin-bottom: 10px; }
.reedit-input-row { display: flex; gap: 10px; align-items: flex-end; }
.reedit-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--font-mono); font-size: 13px;
  padding: 10px 14px; outline: none; resize: none; border-radius: var(--radius);
  line-height: 1.5; transition: border-color var(--trans);
}
.reedit-input:focus { border-color: var(--accent); }
.reedit-submit {
  background: var(--surface3); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--font-display); font-weight: 700;
  font-size: 12px; letter-spacing: 0.08em;
  padding: 10px 18px; cursor: pointer; border-radius: var(--radius);
  white-space: nowrap; transition: all var(--trans);
}
.reedit-submit:hover { border-color: var(--accent); color: var(--accent); }

/* ── ANIMATIONS ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.6; }
}
@keyframes loadingFlash {
  0%, 100% { background: var(--surface2); }
  50% { background: var(--surface3); }
}
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
  100% { content: ''; }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel-left { max-height: 55vh; border-right: none; border-bottom: 1px solid var(--border); }
  .panel-right { min-height: 45vh; }
}

@media (max-width: 640px) {
  .toggle-panel-btn { display: flex; }
  .api-badge { display: none; }
  .header { padding: 0 16px; }
  .header-logo { font-size: 12px; }
  .change-key-btn { font-size: 9px; padding: 5px 8px; }

  .gate-inner { padding: 32px 24px; }

  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; position: relative; }
  .panel-left {
    max-height: 60vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease;
  }
  .panel-left.mobile-collapsed {
    max-height: 0;
    overflow: hidden;
    border-bottom: none;
    opacity: 0;
  }
  .panel-right { min-height: 0; flex: 1; }

  .output-header { padding: 0 12px; height: 44px; }
  .output-actions { gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
  .action-btn { font-size: 9px; padding: 5px 8px; letter-spacing: 0.06em; }

  .output-area { padding: 16px; }
  .result-img { max-height: calc(100vh - 180px); }

  .reedit-bar { padding: 12px 16px; }
  .reedit-input-row { flex-direction: column; gap: 8px; }
  .reedit-submit { width: 100%; padding: 12px; }

  .mode-panel { padding: 16px; }
  .settings { padding: 16px; }
  .generate-btn { margin: 0 16px 16px; padding: 16px; }

  .mix-slots { flex-wrap: wrap; }
  .upload-zone.small { min-width: calc(50% - 4px); }

  .ratio-grid { grid-template-columns: repeat(5, 1fr); }
}