:root {
  --ink: #101815;
  --paper: #f2efe7;
  --panel: #faf8f1;
  --line: rgba(16, 24, 21, .14);
  --moss: #254b3c;
  --mint: #b6d1bc;
  --coral: #df6b48;
  --dark: #0e1413;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Manrope', Arial, sans-serif;
  --mono: 'DM Mono', monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--sans); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
.brand-mark { display: inline-grid; width: 30px; height: 30px; place-items: center; color: var(--paper); background: var(--ink); border-radius: 50%; font-family: var(--mono); font-size: 10px; letter-spacing: -.1em; margin-right: 9px; vertical-align: middle; }
.primary-button { min-height: 46px; border: 0; padding: 0 22px; color: var(--paper); background: var(--ink); font-weight: 700; font-size: 14px; }
.primary-button:hover { background: var(--moss); }
.ghost-button { border: 1px solid var(--line); background: transparent; color: inherit; padding: 7px 14px; font-size: 12px; font-weight: 600; }
.ghost-button:hover { border-color: var(--coral); color: var(--coral); }

/* ---------- Login ---------- */
.login-screen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--dark); z-index: 50; padding: 20px; }
.login-card { width: min(380px, 100%); padding: 38px 32px; background: var(--panel); display: grid; gap: 14px; }
.login-brand { font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: -.04em; }
.login-sub { margin: -8px 0 6px; color: #68726a; font-size: 13px; }
.login-card input { border: 1px solid var(--line); padding: 13px 14px; font-size: 15px; background: #fff; outline: none; }
.login-card input:focus { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(37, 75, 60, .12); }
.login-error { min-height: 18px; margin: 0; color: #b3371d; font-size: 12px; }

/* ---------- App frame ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: -.04em; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-right select { border: 1px solid var(--line); background: #fff; padding: 7px 10px; font-size: 12px; font-weight: 600; }
.app-main { flex: 1; display: grid; grid-template-columns: 380px 1fr 300px; grid-template-areas: "chat preview media"; min-height: 0; }

/* ---------- Panels ---------- */
.media-panel, .chat-panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.chat-panel { grid-area: chat; border-right: 1px solid var(--line); }
.preview-panel { grid-area: preview; }
.media-panel { grid-area: media; border-left: 1px solid var(--line); }
.panel-title { padding: 14px 16px 10px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #68726a; }

/* ---------- Upload ---------- */
.upload-zone { margin: 0 14px; border: 1.5px dashed rgba(16,24,21,.3); padding: 26px 16px; text-align: center; background: rgba(255,255,255,.4); transition: border-color .15s, background .15s; cursor: pointer; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--moss); background: rgba(182, 209, 188, .25); }
.upload-icon { font-size: 26px; color: var(--moss); }
.upload-zone p { margin: 8px 0 0; font-size: 13px; line-height: 1.5; }
.upload-hint { color: #8a9188; font-size: 11px !important; }
.upload-progress { margin: 10px 14px 0; height: 4px; background: rgba(16,24,21,.1); }
.upload-progress-bar { height: 100%; width: 0; background: var(--moss); transition: width .2s; }

/* Visually hidden but still rendered: Android Firefox refuses to open
   file pickers on inputs that are display:none / hidden. */
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
label.upload-zone { display: block; }

/* ---------- Media list ---------- */
.media-list { flex: 1; overflow-y: auto; margin: 12px 0 0; padding: 0 10px 12px; list-style: none; }
.media-item { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid transparent; cursor: pointer; }
.media-item:hover { background: rgba(255,255,255,.6); }
.media-item.active { border-color: var(--moss); background: rgba(182,209,188,.3); }
.media-thumb { width: 56px; height: 40px; object-fit: cover; background: var(--dark); flex-shrink: 0; }
.media-thumb-placeholder { width: 56px; height: 40px; display: grid; place-items: center; background: var(--dark); color: var(--mint); font-size: 16px; flex-shrink: 0; }
.media-info { min-width: 0; }
.media-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-kind { font-family: var(--mono); font-size: 9px; color: #8a9188; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Preview ---------- */
.preview-panel { display: flex; flex-direction: column; min-height: 0; padding: 16px; }
.preview-frame { flex: 1; min-height: 0; display: grid; place-items: center; background: var(--dark); overflow: hidden; }
.preview-frame video { width: 100%; height: 100%; object-fit: contain; }
.preview-empty { color: #7d8a80; text-align: center; font-family: var(--serif); font-size: 20px; }
.preview-empty-sub { font-family: var(--sans); font-size: 13px; color: #5c6a61; }
.preview-meta { padding: 10px 2px 0; font-size: 12px; color: #68726a; min-height: 26px; }
.timeline { display: flex; align-items: center; gap: 12px; padding-top: 8px; min-width: 0; }
.timeline-label { color: #68726a; font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.timeline-track { flex: 1; min-width: 0; height: 32px; padding: 4px; background: #dcd8ce; }
.timeline-clip { width: 72%; height: 24px; overflow: hidden; padding: 4px 9px; color: var(--paper); background: var(--moss); font-family: var(--mono); font-size: 10px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Chat ---------- */
.chat-log { flex: 1; overflow-y: auto; padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 92%; padding: 10px 13px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.chat-msg.user { align-self: flex-end; background: var(--ink); color: var(--paper); }
.chat-msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.chat-msg.system { align-self: center; background: transparent; color: #8a9188; font-size: 11px; padding: 2px; text-align: center; }
.tool-chip { align-self: flex-start; font-family: var(--mono); font-size: 10px; color: var(--moss); background: rgba(182,209,188,.35); padding: 4px 9px; border-left: 2px solid var(--moss); max-width: 92%; word-break: break-word; }
.tool-chip.error { color: #b3371d; border-left-color: #b3371d; background: rgba(223,107,72,.15); }
.chat-composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.chat-composer textarea { flex: 1; resize: none; border: 1px solid var(--line); padding: 10px 12px; font-size: 13.5px; max-height: 110px; background: #fff; outline: none; }
.chat-composer textarea:focus { border-color: var(--moss); }
.send-button { width: 42px; border: 0; background: var(--ink); color: var(--paper); font-size: 16px; }
.send-button:hover { background: var(--moss); }
.chat-hints { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 12px; }
.hint-chip { border: 1px solid var(--line); background: transparent; font-size: 11px; padding: 5px 10px; color: var(--moss); font-weight: 600; }
.hint-chip:hover { border-color: var(--moss); }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: #8a9188; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- Mobile ---------- */
@media (max-width: 980px) {
  .app-main { grid-template-columns: 1fr; grid-template-rows: auto minmax(180px, 30vh) 1fr; grid-template-areas: "media" "preview" "chat"; overflow-y: auto; }
  .media-panel { border-left: 0; border-bottom: 1px solid var(--line); }
  .panel-title { padding: 8px 12px 4px; }
  .upload-zone { margin: 0 10px; padding: 10px; }
  .upload-icon { font-size: 16px; }
  .upload-zone p { margin: 3px 0 0; font-size: 11px; }
  .upload-hint { display: none; }
  .media-list { display: flex; overflow-x: auto; overflow-y: hidden; max-height: 96px; margin: 8px 0 0; padding: 0 10px 8px; gap: 4px; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
  .media-item { flex-direction: column; align-items: flex-start; width: 96px; flex-shrink: 0; }
  .media-thumb, .media-thumb-placeholder { width: 84px; height: 52px; }
  .chat-panel { border-right: 0; border-top: 1px solid var(--line); min-height: 320px; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .preview-panel { padding: 10px; }
  /* Stop double-tap zoom on controls and iOS/Android focus zoom on inputs. */
  button, .hint-chip, .upload-zone, .send-button { touch-action: manipulation; }
  #chat-input, .login-card input { font-size: 16px; }
}
