:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: #0f172a; color: #fff;
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: .2px; }
.logo { color: #60a5fa; }

.container { max-width: 760px; margin: 0 auto; padding: 16px 12px 48px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.card.narrow { max-width: 420px; margin: 40px auto; }
h1 { font-size: 1.3rem; margin: 0 0 6px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions.end { justify-content: flex-end; }

.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 10px; padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer;
  min-height: 44px; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.danger:hover:not(:disabled) { background: #fef2f2; }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: .9rem; }
.btn.tiny { padding: 4px 10px; min-height: 32px; font-size: .82rem; }
.btn.block { width: 100%; }
.topbar .btn.ghost { color: #fff; border-color: #334155; }
.topbar .btn.ghost:hover { background: #1e293b; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field span { font-size: .85rem; font-weight: 600; color: #334155; }
.field em { font-weight: 400; color: var(--muted); font-style: normal; }
input[type="text"], input[type="password"], input[type="search"] {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, .btn:focus-visible, .dropzone:focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
input[name="account_id"], input[name="api_key"] { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.span-2 { grid-column: 1 / -1; }

.dropzone {
  margin-top: 14px; padding: 22px 12px; text-align: center; color: var(--muted);
  border: 2px dashed #cbd5e1; border-radius: 12px; cursor: pointer; user-select: none;
}
.dropzone.over { border-color: var(--primary); background: #eff6ff; color: var(--primary); }

.status { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: #eff6ff; color: #1e3a8a; }
.status.error { background: #fef2f2; color: #991b1b; }
.status.success { background: #f0fdf4; color: #166534; }
.spinner {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 3px solid #bfdbfe; border-top-color: var(--primary); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.msg { margin: 8px 0 0; font-size: .92rem; }
.msg.error { color: var(--danger); }
.msg.info { color: #1e3a8a; background: #eff6ff; padding: 8px 10px; border-radius: 8px; }

.video-wrap { background: #000; border-radius: 12px; overflow: hidden; }
video { display: block; width: 100%; max-height: 60vh; object-fit: contain; }

.review-head, .list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.list-head h2 { margin: 0; }
.list-head input { max-width: 260px; }
.preview { display: block; max-width: 100%; max-height: 260px; margin: 6px auto 12px; border-radius: 10px; border: 1px solid var(--line); }
.review-list { display: flex; flex-direction: column; gap: 12px; }
.entry { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #f8fafc; }
.entry.saved { border-color: #bbf7d0; background: #f0fdf4; }
pre { white-space: pre-wrap; word-break: break-word; background: #f8fafc; padding: 10px; border-radius: 8px; border: 1px solid var(--line); }
details summary { cursor: pointer; color: var(--muted); margin-top: 10px; }

.badge { display: inline-block; min-width: 26px; padding: 1px 8px; border-radius: 999px; background: #e0e7ff; color: #3730a3; font-size: .8rem; text-align: center; vertical-align: middle; }
.cred-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.cred { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.cred-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.cred-label { word-break: break-word; }
.cred-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0; }
.cred-row .k { width: 86px; flex: none; color: var(--muted); font-size: .85rem; }
.cred-row code { flex: 1 1 140px; min-width: 0; word-break: break-all; font-size: .95rem; background: #f1f5f9; padding: 4px 8px; border-radius: 6px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.toast.error { background: var(--danger); }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 auto; }
  .actions.end .btn { flex: 0 0 auto; }
  .list-head input { max-width: none; }
  .card { padding: 14px; }
  .cred-row { flex-wrap: wrap; }
  .cred-row .k { width: 100%; }
  .cred-row code { flex: 1 1 0; }
}
