:root {
    --bg: #0f0f0f;
    --bg-2: #171717;
    --bg-3: #1f1f1f;
    --line: #2a2a2a;
    --line-2: #383838;
    --text: #e8e6e1;
    --text-2: #a8a39a;
    --text-3: #6b6760;
    --accent: #d64545;
    --accent-dim: #a32f2f;
    --ok: #6b8e4e;
    --err: #c0392b;
    --font-head: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  }
  html, body { background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }

  /* (topbar/topnav styles live in /assets/theme.css) */

  /* Layout */
  .wrap { max-width: 1400px; margin: 0 auto; padding: 28px 32px 80px; }

  /* Tabs */
  .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 24px; }
  .tab {
    background: transparent; border: none; color: var(--text-2);
    padding: 12px 22px; font-family: var(--font-body); font-size: 14px; font-weight: 500;
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: all 0.15s; letter-spacing: 0.01em;
  }
  .tab:hover { color: var(--text); }
  .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
  .tab .num { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); margin-left: 6px; vertical-align: middle; }

  /* Tab forms — hidden by default, .active shows */
  .tab-form { display: none; }
  .tab-form.active { display: block; }

  .grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; }
  @media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

  /* Panels */
  .panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; padding: 22px; }
  .panel h2 { font-family: var(--font-head); font-size: 17px; font-weight: 500; margin-bottom: 18px; color: var(--text); }
  .panel h2 .meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); margin-left: 10px; font-weight: 400; }

  /* Form */
  .field { margin-bottom: 16px; }
  .field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
  .field label .hint { color: var(--text-3); font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 6px; }
  textarea, input[type=text], input[type=number], select {
    width: 100%; background: var(--bg-3); border: 1px solid var(--line); border-radius: 4px;
    color: var(--text); padding: 10px 12px; font-family: var(--font-body); font-size: 14px;
    transition: border-color 0.15s;
  }
  select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23a8a39a' d='M6 8L0 0h12z'/></svg>");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 36px; cursor: pointer;
  }
  textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
  textarea:focus, input:focus { outline: none; border-color: var(--accent); }
  textarea::placeholder, input::placeholder { color: var(--text-3); }
  .counter { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); text-align: right; margin-top: 4px; }

  .chips { display: flex; flex-wrap: wrap; gap: 6px; }
  .chip {
    background: var(--bg-3); border: 1px solid var(--line); color: var(--text-2);
    padding: 6px 12px; border-radius: 4px; font-size: 12px; font-family: var(--font-mono);
    cursor: pointer; transition: all 0.15s; user-select: none;
  }
  .chip:hover { color: var(--text); border-color: var(--line-2); }
  .chip.active { background: var(--accent); border-color: var(--accent); color: white; }

  /* Compact language chips for TTS voice picker */
  .lang-chips {
    display: flex; flex-wrap: wrap; gap: 4px;
    max-height: 92px; overflow-y: auto;
    margin-bottom: 8px; padding: 2px 0;
  }
  .lang-chips::-webkit-scrollbar { width: 4px; }
  .lang-chips::-webkit-scrollbar-track { background: transparent; }
  .lang-chips::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 2px; }
  .lang-chip {
    background: var(--bg-3); border: 1px solid var(--line); color: var(--text-2);
    padding: 4px 10px; border-radius: 12px; font-size: 11px;
    font-family: var(--font-mono); cursor: pointer; transition: all 0.12s;
    user-select: none; white-space: nowrap; line-height: 1.4;
  }
  .lang-chip:hover { color: var(--text); border-color: var(--line-2); background: var(--bg-2); }
  .lang-chip.active { background: var(--accent); border-color: var(--accent); color: white; }
  .lang-chip .count { opacity: 0.55; margin-left: 4px; font-size: 10px; }
  .lang-chip.active .count { opacity: 0.85; }

  .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

  .btn {
    background: var(--accent); color: white; border: none; border-radius: 4px;
    padding: 12px 24px; font-family: var(--font-body); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all 0.15s; width: 100%; letter-spacing: 0.01em;
  }
  .btn:hover:not(:disabled) { background: #e85555; }
  .btn:disabled { background: var(--bg-3); color: var(--text-3); cursor: not-allowed; }
  .btn.secondary { background: transparent; color: var(--text-2); border: 1px solid var(--line); }
  .btn.secondary:hover:not(:disabled) { color: var(--text); border-color: var(--line-2); background: var(--bg-3); }
  .btn.danger { background: transparent; color: var(--err); border: 1px solid var(--line); }
  .btn.danger:hover:not(:disabled) { border-color: var(--err); background: rgba(192,57,43,0.08); }
  .btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

  /* Result */
  .result-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 360px; color: var(--text-3); text-align: center;
  }
  .result-empty .icon { font-size: 32px; opacity: 0.4; margin-bottom: 12px; }
  .result-empty .text { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.05em; }
  .result-body { display: none; }
  .result-body.active { display: block; }
  .preview {
    background: var(--bg-3); border-radius: 4px; padding: 12px; margin-bottom: 14px;
    display: flex; align-items: center; justify-content: center; min-height: 240px; max-height: 480px;
    overflow: hidden;
  }
  .preview img { max-width: 100%; max-height: 440px; border-radius: 2px; display: block; cursor: zoom-in; transition: opacity 0.15s; }
  .preview img:hover { opacity: 0.92; }
  .preview audio { width: 100%; }

  /* Lightbox (click image to expand) */
  .lightbox {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(8, 8, 10, 0.94);
    display: flex; align-items: center; justify-content: center;
    padding: 32px; cursor: zoom-out;
    animation: lb-fade 0.18s ease-out;
  }
  .lightbox[hidden] { display: none !important; }
  .lightbox-img {
    max-width: 95vw; max-height: 90vh;
    object-fit: contain; border-radius: 4px;
    box-shadow: 0 16px 60px rgba(0,0,0,0.7);
    cursor: default;
  }
  .lightbox-close {
    position: absolute; top: 18px; right: 22px;
    background: transparent; border: 1px solid var(--line);
    color: var(--text); font-size: 20px; line-height: 1;
    width: 40px; height: 40px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--font-body);
  }
  .lightbox-close:hover { background: var(--bg-3); border-color: var(--text-3); }
  .lightbox-caption {
    position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
    color: var(--text-3); font-family: var(--font-mono); font-size: 12px;
    max-width: 80vw; text-align: center;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    background: rgba(0,0,0,0.4); padding: 6px 12px; border-radius: 4px;
  }
  @keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
  .meta-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 12px; margin-bottom: 14px; padding: 12px; background: var(--bg-3); border-radius: 4px; }
  .meta-grid .k { color: var(--text-3); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em; }
  .meta-grid .v { color: var(--text); word-break: break-word; }
  .meta-grid .v.prompt { font-style: italic; color: var(--text-2); }
  .status {
    display: inline-block; padding: 3px 10px; border-radius: 3px;
    font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  }
  .status.pending { background: rgba(214,69,69,0.15); color: var(--accent); }
  .status.saved { background: rgba(107,142,78,0.15); color: var(--ok); }
  .status.discarded { background: rgba(107,103,96,0.15); color: var(--text-3); }
  .status.generating { background: rgba(214,69,69,0.15); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

  .err-box {
    background: rgba(192,57,43,0.08); border: 1px solid var(--err); border-radius: 4px;
    padding: 12px 14px; color: var(--err); font-family: var(--font-mono); font-size: 12px;
    margin-bottom: 14px; display: none;
  }
  .err-box.active { display: block; }

  /* History strip */
  .history { margin-top: 32px; }
  .history h3 { font-family: var(--font-head); font-size: 15px; font-weight: 500; margin-bottom: 12px; color: var(--text-2); }
  .history-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
  .history-row::-webkit-scrollbar { height: 6px; }
  .history-row::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

  /* ---- Quota bar ---- */
  .quota-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; margin-bottom: 16px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; font-family: var(--font-mono); font-size: 11px; align-items: center; }
  .quota-bar .q-label { color: var(--text-3); margin-right: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
  .quota-bar .q-model { color: var(--text-2); font-weight: 600; }
  .quota-bar .q-bar { display: inline-block; width: 60px; height: 8px; background: var(--line); border-radius: 4px; vertical-align: middle; margin: 0 6px; overflow: hidden; position: relative; }
  .quota-bar .q-fill { display: block; height: 100%; background: var(--accent); transition: width 0.3s; position: absolute; right: 0; top: 0; }
  .quota-bar .q-bar .q-divider { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--text-3); pointer-events: none; opacity: 0.7; }
  .quota-bar .q-bar .q-divider:nth-child(2) { left: calc(100% / 7 * 1); }
  .quota-bar .q-bar .q-divider:nth-child(3) { left: calc(100% / 7 * 2); }
  .quota-bar .q-bar .q-divider:nth-child(4) { left: calc(100% / 7 * 3); }
  .quota-bar .q-bar .q-divider:nth-child(5) { left: calc(100% / 7 * 4); }
  .quota-bar .q-bar .q-divider:nth-child(6) { left: calc(100% / 7 * 5); }
  .quota-bar .q-bar .q-divider:nth-child(7) { left: calc(100% / 7 * 6); }
  .quota-bar .q-pct { color: var(--text); font-weight: 600; min-width: 32px; display: inline-block; text-align: right; }
  .quota-bar .q-reset { color: var(--text-3); font-size: 10px; margin-left: 2px; white-space: nowrap; }
  .quota-bar .q-reset.urgent { color: var(--accent); }
  .quota-bar .q-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
  .quota-bar .q-chip.ok .q-fill { background: #6abe83; }
  .quota-bar .q-chip.warn .q-fill { background: #e0a540; }
  .quota-bar .q-chip.low .q-fill { background: var(--accent); }
  .quota-bar .q-refresh { margin-left: auto; color: var(--text-3); font-size: 10px; cursor: pointer; user-select: none; }
  .quota-bar .q-refresh:hover { color: var(--text-2); }
  .quota-bar.loading { opacity: 0.6; }

  /* ---- Vision result ---- */
  .text-preview { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 16px; max-height: 380px; overflow-y: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6; color: var(--text); white-space: pre-wrap; word-wrap: break-word; }
  .text-preview-empty { color: var(--text-3); font-style: italic; }
  .file-drop { border: 1.5px dashed var(--line-2); border-radius: 6px; padding: 18px; text-align: center; color: var(--text-3); font-size: 12px; cursor: pointer; transition: all 0.15s; background: var(--bg-2); }
  .file-drop:hover, .file-drop.drag { border-color: var(--accent); color: var(--text-2); background: var(--bg-3, var(--bg-2)); }
  .file-drop input[type=file] { display: none; }
  .file-drop .file-name { color: var(--text); font-family: var(--font-mono); font-size: 11px; margin-top: 6px; }
  .input-mode-toggle { display: flex; gap: 4px; margin-bottom: 8px; }
  .input-mode-toggle .chip { font-size: 11px; padding: 4px 10px; }
  .h-item {
    flex: 0 0 140px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px;
    cursor: pointer; overflow: hidden; transition: all 0.15s;
  }
  .h-item:hover { border-color: var(--accent); transform: translateY(-2px); }
  .h-item .h-thumb { width: 100%; aspect-ratio: 1; background: var(--bg-3); display: flex; align-items: center; justify-content: center; }
  .h-item .h-thumb img { width: 100%; height: 100%; object-fit: cover; }
  .h-item .h-thumb .placeholder { color: var(--text-3); font-family: var(--font-mono); font-size: 11px; }
  .h-item .h-info { padding: 6px 8px; font-size: 10px; color: var(--text-2); }
  .h-item .h-info .kind { font-family: var(--font-mono); color: var(--accent); text-transform: uppercase; }
  .h-item .h-info .stat { float: right; font-family: var(--font-mono); }

  .footer-note { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); margin-top: 20px; text-align: center; }
  .footer-note a { color: var(--text-2); text-decoration: none; }
  .footer-note a:hover { color: var(--accent); }
