:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* ---------- ボタン・入力 ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
input[type=password], input[type=search], textarea, select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOS のズーム防止 */
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
select { width: auto; }
textarea { resize: vertical; margin: 10px 0; }

/* ---------- ログイン ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #1e293b, #334155); }
.login-card { background: #fff; padding: 28px 24px; border-radius: 16px; width: 100%; max-width: 360px; display: grid; gap: 12px; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.login-card h1 { font-size: 22px; text-align: center; }
.login-card p { text-align: center; margin: 0; }

/* ---------- レイアウト ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: #1e293b; color: #fff;
}
.layout {
  max-width: 1200px; margin: 0 auto; padding: 14px;
  display: grid; gap: 14px;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "dash dash"
    "up   memo"
    "list list";
}
.layout > .dashboard { grid-area: dash; }
.layout > section:nth-of-type(2) { grid-area: up; }
.layout > section:nth-of-type(3) { grid-area: memo; }
.layout > .list-card { grid-area: list; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.08); min-width: 0; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "dash" "up" "memo" "list"; padding: 10px; gap: 10px; }
  .card { padding: 12px; }
}

/* ---------- ダッシュボード ---------- */
.viewer-empty { border: 2px dashed var(--line); border-radius: 10px; padding: 50px 16px; text-align: center; color: var(--muted); }
.viewer-title { font-weight: 600; margin-bottom: 8px; word-break: break-all; }
.stage { background: #000; border-radius: 10px; overflow: hidden; display: grid; place-items: center; }
.stage img, .stage video { width: 100%; max-height: 60vh; object-fit: contain; display: block; }
.controls { margin-top: 12px; display: grid; gap: 10px; }
.seek-row { display: flex; align-items: center; gap: 10px; }
.seek-row input[type=range] { flex: 1; height: 32px; accent-color: var(--primary); }
.frame-info { text-align: center; color: var(--muted); font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: center; }
.btn-row .btn { flex: 1 1 auto; min-width: 64px; }
.btn.play { min-width: 110px; }
.label { font-size: 13px; color: var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 12px; font: inherit; font-size: 14px; cursor: pointer; min-height: 40px; border-right: 1px solid var(--line); touch-action: manipulation; }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--primary); color: #fff; }

/* ---------- アップロード ---------- */
.drop {
  display: flex; align-items: center; justify-content: center; gap: 12px; text-align: center;
  border: 2px dashed #93c5fd; background: #eff6ff; border-radius: 10px; padding: 22px 12px; cursor: pointer;
}
.drop.over { background: #dbeafe; border-color: var(--primary); }
.drop input { display: none; }
.drop-icon { font-size: 28px; }
.upload-list { display: grid; gap: 6px; margin-top: 10px; }
.up-item { font-size: 13px; }
.up-item .name { display: flex; justify-content: space-between; gap: 8px; }
.up-item .name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.up-item.done .bar > div { background: #16a34a; }
.up-item.fail .bar > div { background: var(--danger); }

/* ---------- メモ ---------- */
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 10px; }
.memo-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; max-height: 360px; overflow-y: auto; }
.memo-list li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 4px; }
.memo-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.memo-text { white-space: pre-wrap; word-break: break-word; }
.time-chip { background: #dbeafe; color: var(--primary-d); border: 0; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.link-btn { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: 12px; padding: 4px; }

/* ---------- 一覧 ---------- */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.list-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 12px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
.item { border: 2px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: pointer; display: flex; flex-direction: column; }
.item.selected { border-color: var(--primary); box-shadow: 0 0 0 3px #bfdbfe; }
.thumb { position: relative; aspect-ratio: 16 / 10; background: #0f172a; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.badge { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.memo-badge { left: auto; right: 6px; }
.item-body { padding: 8px; display: grid; gap: 4px; flex: 1; }
.item-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 11px; color: var(--muted); }
.item-foot { display: flex; justify-content: flex-end; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 30px; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(100px);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  transition: transform .25s; z-index: 100; max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
