/* ---------- Warm Minimal ----------
   One palette (warm neutrals + a single clay accent), one radius system
   (12px surfaces / inputs / buttons, pill chips), borders instead of shadows,
   generous whitespace, system CJK-friendly sans. Light + dark via tokens. */
:root {
  --bg: #f4efe8;
  --surface: #fbf8f3;
  --surface-2: #efe8df;
  --text: #2b2521;
  --muted: #7d7169;
  --faint: #a89c92;
  --border: #e3d9cd;
  --border-strong: #cfc2b3;
  --accent: #b9603f;
  --accent-ink: #fbf8f3;
  --accent-soft: #f3dfd4;
  --danger: #a6453a;
  --danger-soft: #f6e2de;
  --ok: #4f7a5c;
  --r: 12px;
  --shadow: 0 1px 2px rgba(74, 56, 40, .05), 0 10px 30px -18px rgba(74, 56, 40, .25);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a17; --surface: #262220; --surface-2: #2f2a26;
    --text: #efe8df; --muted: #a79b90; --faint: #786e65;
    --border: #3a3430; --border-strong: #4d453f;
    --accent: #d98a67; --accent-ink: #1d1a17; --accent-soft: #3d2b23;
    --danger: #e0877a; --danger-soft: #3d2622; --ok: #8fbf9b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -18px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
.ico { display: inline-block; vertical-align: -0.2em; flex: none; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
  padding: calc(10px + var(--safe-top)) 16px 10px; display: flex; align-items: center; gap: 8px; min-height: 56px; }
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .iconbtn { background: transparent; border: 1px solid transparent; color: var(--text); width: 40px; height: 40px; border-radius: var(--r);
  display: inline-flex; align-items: center; justify-content: center; flex: none; margin: -4px 0; }
.topbar .iconbtn:hover { background: var(--surface-2); }
.topbar .iconbtn:active { transform: scale(.96); }
.page { max-width: 960px; margin: 0 auto; padding: 20px 16px calc(96px + var(--safe-bottom)); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 500; font-size: 15px; min-height: 44px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { background: color-mix(in srgb, var(--text) 88%, var(--bg)); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.accent:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.sm { padding: 7px 12px; min-height: 36px; font-size: 13px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface); font-size: 16px; outline: none; transition: border-color .15s ease, box-shadow .15s ease; }
.field input::placeholder, .field textarea::placeholder { color: var(--faint); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; letter-spacing: -0.01em; }
.card h2 .hint { font-weight: 400; margin-left: 6px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 32px 26px 26px; }
.login .logo { width: 56px; height: 56px; border-radius: 14px; margin: 0 0 18px; display: block; }
.login h1 { font-size: 22px; margin: 0 0 6px; font-weight: 600; letter-spacing: -0.02em; }
.login p { color: var(--muted); margin: 0 0 22px; font-size: 14px; line-height: 1.5; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- search + filters ---------- */
.search { position: relative; margin-bottom: 12px; }
.search .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input { width: 100%; padding: 12px 14px 12px 42px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); font-size: 16px; outline: none; transition: border-color .15s ease, box-shadow .15s ease; }
.search input::placeholder { color: var(--faint); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border-strong); background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap; transition: all .15s ease; }
.chip:hover { color: var(--text); background: var(--surface-2); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 5px; font-size: 12px; font-variant-numeric: tabular-nums; }
.count { color: var(--muted); font-size: 13px; margin: 6px 2px 14px; }
.count a { color: var(--accent); }

/* ---------- card grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; padding: 0; text-align: left; display: flex; flex-direction: column;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease; }
.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.tile:active { transform: translateY(0); }
.tile .thumb { background: var(--surface-2); width: 100%; aspect-ratio: 1.6; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 8px; }
.tile .thumb img { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 3px; }
.tile .meta { padding: 12px 14px 14px; }
.tile .name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .name.none { color: var(--faint); font-weight: 400; }
.tile .en { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .company { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .cat { display: inline-block; margin-top: 8px; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 72px 20px; }
.empty .big { color: var(--faint); margin-bottom: 14px; }
.empty .title { font-weight: 600; color: var(--text); margin-bottom: 4px; }

.fab { position: fixed; right: 18px; bottom: calc(18px + var(--safe-bottom)); z-index: 20; width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: 0 8px 22px -8px rgba(74, 56, 40, .5); display: flex; align-items: center; justify-content: center; transition: transform .12s ease; }
.fab:active { transform: scale(.94); }

/* ---------- capture / review ---------- */
.capture { display: flex; flex-direction: column; gap: 12px; }
.capture .big-btn { padding: 28px 16px; font-size: 16px; flex-direction: column; gap: 10px; }
.capture .big-btn .ico { width: 32px; height: 32px; }
.capture .hint { padding: 4px 4px 0; }
.progress { text-align: center; padding: 64px 20px; color: var(--muted); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); margin: 0 auto 18px; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-top-color: var(--border); } .tile, .btn, .fab { transition: none; } }

.preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; display: flex; align-items: center; justify-content: center; position: relative; padding: 14px; min-height: 180px; }
.preview img { max-width: 100%; max-height: 60vh; display: block; box-shadow: var(--shadow); border-radius: 3px; }
.preview.portrait img { max-height: 68vh; }
.preview .tag { position: absolute; top: 10px; left: 10px; background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border); color: var(--muted); font-size: 11.5px; padding: 3px 9px; border-radius: 999px; }
.tools { display: flex; gap: 8px; margin: 10px 0 16px; flex-wrap: wrap; }
.tools .btn { flex: 1; }

.detail-meta { font-size: 12.5px; color: var(--muted); margin-top: 12px; line-height: 1.5; }

/* ---------- front / back sides ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 2px 8px; min-height: 28px; }
.side-head .hint { font-weight: 400; }
.side-head .side-actions { display: flex; gap: 2px; }
.side-block { margin-top: 10px; }
.progress.compact { padding: 28px 16px; }
.tile .cat.sides { background: var(--surface-2); color: var(--muted); margin-left: 4px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 50; max-width: 90vw; text-align: center; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }

@media (min-width: 700px) {
  .page { padding-top: 28px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
  .two-col { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; align-items: start; }
  .chips { margin: 0; padding-left: 0; padding-right: 0; }
}
