:root {
  --bg: #16161d;
  --bg-2: #1f1f28;
  --bg-3: #2a2a37;
  --fg: #dcd7ba;
  --fg-dim: #9e9b86;
  --accent: #7e9cd8;
  --accent-2: #ffa066;
  --ok: #98bb6c;
  --warn: #e6c384;
  --err: #e46876;
  --jp-font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "Noto Sans CJK JP", system-ui, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font-family: var(--jp-font); font-size: 16px; line-height: 1.5; }
body { min-height: 100vh; min-height: 100dvh; -webkit-font-smoothing: antialiased; }

.hidden { display: none !important; }
.muted { color: var(--fg-dim); font-size: 0.9em; }
.error { color: var(--err); min-height: 1em; margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--fg);
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  border-radius: 6px;
  padding: 10px 12px;
  min-height: 44px;
}
button { cursor: pointer; background: var(--bg-3); transition: background 0.12s; }
button:hover:not(:disabled) { background: #353546; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

textarea { min-height: 6em; width: 100%; resize: vertical; }
input[type="search"], input[type="text"], input[type="password"] { width: 100%; }
select { min-width: 120px; }

/* Login */
.gate { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 2rem; letter-spacing: 0.02em; }
.login p.muted { margin: 0 0 8px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; letter-spacing: 0.06em; }
.topbar .tabs { flex: 1; display: flex; gap: 4px; overflow-x: auto; }
.topbar .tabs a {
  padding: 10px 14px; border-radius: 6px;
  color: var(--fg-dim); min-height: 44px; display: flex; align-items: center;
}
.topbar .tabs a.active { color: var(--fg); background: var(--bg-3); }
.icon-btn { min-width: 44px; min-height: 44px; padding: 8px; background: transparent; border: none; font-size: 1.2em; }

/* Views */
.view { padding: 14px; max-width: 920px; margin: 0 auto; }
.section { display: flex; flex-direction: column; gap: 14px; }
.section h2 { margin: 0 0 4px; font-size: 1.2rem; color: var(--fg); }
.back { display: inline-block; color: var(--fg-dim); margin-bottom: 8px; }

/* Upload */
.upload-form { display: flex; flex-direction: column; gap: 12px; }
.file-drop {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 2px dashed var(--bg-3);
  border-radius: 8px; padding: 28px; min-height: 100px;
  cursor: pointer; text-align: center; color: var(--fg-dim);
}
.file-drop input { display: none; }
.status-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.status-list li {
  display: flex; justify-content: space-between; gap: 12px;
  background: var(--bg-2); padding: 10px 12px; border-radius: 6px;
}
.status-list .s-pending { color: var(--warn); }
.status-list .s-processing { color: var(--accent); }
.status-list .s-done { color: var(--ok); }
.status-list .s-failed { color: var(--err); }

/* Search row */
.search-row { display: flex; gap: 8px; flex-wrap: wrap; }
.search-row input[type="search"] { flex: 1; min-width: 180px; }

/* Feed */
.feed-list { display: flex; flex-direction: column; gap: 12px; }
.feed-card {
  background: var(--bg-2); border-radius: 8px; overflow: hidden;
  border: 1px solid var(--bg-3);
}
.feed-card .thumb-wrap { background: #000; }
.feed-card img { display: block; width: 100%; max-height: 360px; object-fit: contain; }
.feed-card .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.feed-card .jp { white-space: pre-wrap; font-size: 1.05em; line-height: 1.55; }
.feed-card .en { color: var(--fg-dim); white-space: pre-wrap; }
.feed-card .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--fg-dim); font-size: 0.85em; }
.feed-card .badge { padding: 2px 8px; border-radius: 999px; background: var(--bg-3); font-size: 0.8em; }
.feed-card .badge.s-pending { background: #3d362a; color: var(--warn); }
.feed-card .badge.s-processing { background: #2a3344; color: var(--accent); }
.feed-card .badge.s-done { background: #2d3a26; color: var(--ok); }
.feed-card .badge.s-failed { background: #412529; color: var(--err); }
.feed-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Mined */
.subtabs { display: flex; gap: 6px; }
.subtabs button { flex: 1; background: var(--bg-2); }
.subtabs button.active { background: var(--bg-3); color: var(--accent); }
.mined-list { display: flex; flex-direction: column; gap: 6px; }
.mined-row {
  display: grid;
  grid-template-columns: minmax(80px, 140px) 1fr auto;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-2); border-radius: 6px;
  align-items: center;
}
.mined-row .surface { font-size: 1.15em; font-weight: 600; }
.mined-row .reading { display: block; color: var(--fg-dim); font-size: 0.85em; margin-top: 2px; }
.mined-row .meaning { color: var(--fg); overflow: hidden; text-overflow: ellipsis; }
.mined-row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 0.85em; color: var(--fg-dim); white-space: nowrap; }
.stars { letter-spacing: 1px; color: var(--warn); }

.pager { display: flex; gap: 8px; justify-content: center; padding: 8px 0; }
.pager button { min-width: 80px; }

/* Entry detail */
.entry-head { background: var(--bg-2); padding: 16px; border-radius: 8px; display: flex; flex-direction: column; gap: 6px; }
.entry-head .surface { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.entry-head .reading { color: var(--fg-dim); font-size: 1.05em; }
.entry-head .meaning { font-size: 1.05em; }
.entry-head .type { display: inline-block; text-transform: uppercase; font-size: 0.7em; color: var(--accent-2); letter-spacing: 0.1em; }
.mastery { display: flex; gap: 6px; flex-wrap: wrap; }
.mastery button { flex: 1; min-width: 48px; }
.mastery button.on { background: var(--accent); color: #1a1a24; border-color: var(--accent); }
.notes-block { display: flex; flex-direction: column; gap: 4px; }
.notes-block label { color: var(--fg-dim); font-size: 0.9em; }
.links-block { display: flex; gap: 8px; flex-wrap: wrap; }
.links-block a { background: var(--bg-2); padding: 10px 14px; border-radius: 6px; min-height: 44px; display: inline-flex; align-items: center; }
.links-block a:hover { background: var(--bg-3); text-decoration: none; }

.occurrences { display: flex; flex-direction: column; gap: 10px; }
.occ {
  background: var(--bg-2); border-radius: 8px; overflow: hidden; border: 1px solid var(--bg-3);
  display: grid; grid-template-columns: 120px 1fr; gap: 0;
}
.occ .thumb { background: #000; aspect-ratio: 4/3; }
.occ .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.occ .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 0.95em; }
.occ .sentence { white-space: pre-wrap; }
.occ .date { color: var(--fg-dim); font-size: 0.8em; }

@media (max-width: 520px) {
  .mined-row { grid-template-columns: 1fr auto; }
  .mined-row .meaning { grid-column: 1 / -1; color: var(--fg-dim); font-size: 0.9em; }
  .occ { grid-template-columns: 90px 1fr; }
}

/* Saved indicator */
.saved-pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.75em; background: var(--bg-3); color: var(--fg-dim);
  opacity: 0; transition: opacity 0.2s;
}
.saved-pill.show { opacity: 1; }

/* Loading */
.loading { text-align: center; color: var(--fg-dim); padding: 40px 0; }
