:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --panel-soft: #f8f8f6;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #d9ddd9;
  --accent: #2d5f51;
  --accent-soft: #e8f1ee;
  --accent-strong: #21463c;
  --warning: #8a5a00;
  --danger: #9f2f2f;
  --shadow: 0 8px 28px rgba(27, 31, 35, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

body { min-height: 100vh; }
.app-shell { min-height: 100vh; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }

.topbar {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 244, 242, 0.96);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { font-weight: 760; letter-spacing: -0.02em; font-size: 1.08rem; }
.sync-status { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.sync-status[data-kind="ok"] { color: var(--accent); }
.sync-status[data-kind="warning"] { color: var(--warning); }
.sync-status[data-kind="error"] { color: var(--danger); }

.date-controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.date-chip {
  display: grid;
  grid-template-columns: auto auto;
  gap: 7px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px 5px 11px;
  background: var(--panel);
  font-size: 0.8rem;
}
.date-chip span { color: var(--muted); font-weight: 650; }
.date-chip input { border: 0; outline: 0; background: transparent; color: var(--text); width: 128px; }
.date-chip-active { border-color: #b7cfc7; background: var(--accent-soft); }

.top-actions { display: flex; gap: 8px; justify-content: flex-end; }
.icon-button, .button, .filter-button, .workbench-tab, .menu-row {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  cursor: pointer;
}
.icon-button { width: 38px; height: 38px; font-size: 1.25rem; display: grid; place-items: center; }
.icon-button:hover, .button:hover, .filter-button:hover, .workbench-tab:hover, .menu-row:hover { border-color: #b9beb9; }
.button { padding: 8px 12px; font-weight: 650; }
.button-primary { background: var(--accent); color: white; border-color: var(--accent); text-decoration: none; }
.button-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.button-quiet { background: var(--panel-soft); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.full-width { width: 100%; }

.filters {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.filter-button { padding: 6px 11px; font-size: 0.83rem; font-weight: 650; }
.filter-button.active { background: var(--text); color: white; border-color: var(--text); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(320px, 58vh) minmax(250px, 42vh);
  overflow: hidden;
}
.timeline-panel { min-height: 0; overflow: auto; padding: 12px 14px 22px; }
.timeline { max-width: 940px; margin: 0 auto; display: grid; gap: 12px; }
.date-group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 0 rgba(0,0,0,.02); }
.date-header { padding: 10px 12px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; background: var(--panel-soft); border-bottom: 1px solid var(--line); }
.date-title { font-weight: 760; letter-spacing: -0.01em; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.date-counts { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.date-badge { border-radius: 999px; padding: 2px 7px; font-size: .67rem; font-weight: 760; text-transform: uppercase; letter-spacing: .04em; }
.next-badge { background: #222; color: white; }
.active-badge { background: var(--accent-soft); color: var(--accent-strong); }

.content-section + .content-section { border-top: 1px solid var(--line); }
.section-heading { padding: 7px 12px 5px; color: var(--muted); font-size: .72rem; font-weight: 760; text-transform: uppercase; letter-spacing: .07em; }
.section-heading span { font-weight: 550; }
.content-card, .vocab-row {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.content-card:hover, .vocab-row:hover { background: #fafbf9; }
.reading-card { padding: 9px 12px 11px; border-top: 1px solid #edf0ed; }
.reading-title { font-weight: 720; margin-bottom: 2px; }
.source-line { color: var(--muted); font-size: .76rem; margin-bottom: 3px; }
.reading-excerpt { color: #4f565f; line-height: 1.42; font-size: .88rem; }

.vocab-list { border-top: 1px solid #edf0ed; }
.vocab-row { display: grid; grid-template-columns: minmax(105px, .82fr) minmax(0, 2.8fr); gap: 12px; padding: 7px 12px; border-bottom: 1px solid #edf0ed; }
.vocab-row:last-child { border-bottom: 0; }
.vocab-word { font-weight: 760; line-height: 1.45; word-break: break-word; }
.vocab-senses { min-width: 0; display: grid; gap: 1px; }
.sense-line { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 7px; row-gap: 1px; line-height: 1.4; }
.pos { color: var(--muted); font-size: .76rem; min-width: 1.7em; }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Segoe UI", sans-serif; font-size: .89rem; }
.ipa-us { color: var(--muted); font-size: .76rem; }
.meaning { font-size: .9rem; }

.empty-state { min-height: 42vh; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 24px; }
.empty-title { color: var(--text); font-weight: 760; margin-bottom: 4px; }

.workbench { min-height: 0; border-top: 1px solid var(--line); background: var(--panel); display: grid; grid-template-rows: auto minmax(0, 1fr); box-shadow: 0 -8px 26px rgba(0,0,0,.04); }
.workbench-tabs { display: flex; gap: 4px; padding: 7px 12px; border-bottom: 1px solid var(--line); }
.workbench-tab { padding: 5px 10px; border-color: transparent; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 680; }
.workbench-tab.active { color: var(--text); background: var(--panel-soft); border-color: var(--line); }
.workbench-pane { display: none; min-height: 0; overflow: auto; padding: 10px 12px 14px; }
.workbench-pane.active { display: block; }

.drop-zone { border: 1px dashed #b8bebb; border-radius: var(--radius-sm); background: var(--panel-soft); transition: .15s ease; }
.drop-zone.dragging { border-color: var(--accent); background: var(--accent-soft); }
#importText { display: block; width: 100%; min-height: 128px; max-height: 210px; resize: vertical; padding: 10px 11px; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.38; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.drop-hint { padding: 6px 10px 8px; color: var(--muted); font-size: .73rem; border-top: 1px dashed #d2d6d2; }
.import-preview { padding: 7px 1px 2px; font-size: .8rem; line-height: 1.45; }
.preview-main { color: var(--text); }
.preview-dates { color: var(--muted); margin-top: 2px; }
.preview-warnings, .import-warning { color: var(--warning); margin-top: 4px; }
.import-error { color: var(--danger); }
.workbench-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 7px; }

.details-content { max-width: 880px; margin: 0 auto; line-height: 1.48; }
.detail-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.detail-title-row h3 { margin: 0 0 8px; font-size: 1.12rem; }
.detail-date { color: var(--muted); font-size: .78rem; }
.detail-senses { display: grid; gap: 3px; padding: 4px 0 8px; }
.detail-meta { color: #4f565f; font-size: .82rem; margin: 6px 0; }
.tag { display: inline-block; padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; margin: 2px 3px 2px 0; background: var(--panel-soft); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.reading-full { white-space: pre-wrap; line-height: 1.58; padding: 8px 0; font-size: .93rem; }
.future-note { color: var(--muted); font-size: .72rem; margin-top: 10px; }

.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(15, 18, 20, .42); display: grid; place-items: center; padding: 18px; }
.modal { width: min(720px, 96vw); max-height: min(82vh, 820px); overflow: auto; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.auth-modal { width: min(420px, 94vw); }
.auth-modal h1 { margin: 0 0 7px; font-size: 1.25rem; }
.auth-modal p { margin: 0 0 10px; line-height: 1.4; }
.auth-modal input[type="password"], .search-modal input[type="search"] { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 11px; outline: 0; }
.auth-modal input:focus, .search-modal input:focus { border-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .8rem; margin: 9px 0 12px; }
.search-results { margin-top: 10px; display: grid; gap: 5px; }
.search-placeholder { padding: 18px 4px; }
.search-section-title { color: var(--muted); font-size: .7rem; font-weight: 760; text-transform: uppercase; letter-spacing: .06em; margin-top: 7px; }
.search-result { border: 1px solid var(--line); border-radius: 10px; padding: 8px 9px; text-align: left; background: var(--panel); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; }
.search-result:hover { background: var(--panel-soft); }
.search-result span { color: var(--muted); font-size: .75rem; }
.search-result small { grid-column: 1 / -1; color: #555d66; }
.menu-list { display: grid; gap: 6px; }
.menu-row { width: 100%; padding: 10px 11px; text-align: left; }
.menu-note { color: var(--muted); font-size: .72rem; line-height: 1.4; margin-top: 11px; }
.original-text { white-space: pre-wrap; word-break: break-word; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: .78rem; }

.snackbar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 150; background: #202423; color: white; border-radius: 999px; padding: 9px 11px 9px 14px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); font-size: .8rem; max-width: min(92vw, 720px); }
.snackbar button { border: 0; background: rgba(255,255,255,.14); color: white; border-radius: 999px; padding: 5px 9px; cursor: pointer; font-weight: 760; }

@media (max-width: 920px) {
  .topbar { grid-template-columns: 1fr auto; }
  .date-controls { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  .workspace { grid-template-rows: minmax(300px, 58vh) minmax(250px, 42vh); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .topbar { position: sticky; grid-template-columns: 1fr auto; padding: 10px 12px 7px; }
  .date-controls { grid-column: 1 / -1; overflow-x: auto; flex-wrap: nowrap; justify-content: flex-start; padding-bottom: 2px; }
  .date-chip { flex: 0 0 auto; }
  .desktop-import-button { display: none; }
  body.mobile-manage .desktop-import-button { display: inline-block; }
  .filters { position: sticky; top: 112px; z-index: 25; padding: 7px 12px; }
  .workspace { display: block; overflow: visible; }
  .timeline-panel { overflow: visible; padding: 9px 9px 34px; }
  .timeline { gap: 9px; }
  .date-group { border-radius: 12px; }
  .date-header { padding: 9px 10px; }
  .date-counts { display: none; }
  .reading-card { padding: 9px 10px 10px; }
  .vocab-row { grid-template-columns: 94px minmax(0, 1fr); gap: 8px; padding: 7px 10px; }
  .vocab-word { font-size: .93rem; }
  .sense-line { column-gap: 5px; }
  .meaning { font-size: .88rem; }
  .workbench { display: none; border: 1px solid var(--line); margin: 9px; border-radius: 12px; overflow: hidden; }
  body.mobile-manage .workbench { display: grid; }
  .detail-modal { width: min(620px, 96vw); max-height: 86vh; }
  .snackbar { bottom: 12px; border-radius: 12px; }
}

@media (max-width: 430px) {
  .date-chip input { width: 112px; }
  .top-actions { gap: 5px; }
  .icon-button { width: 36px; height: 36px; }
  .brand { font-size: 1rem; }
  .vocab-row { grid-template-columns: 82px minmax(0, 1fr); }
  .pos { min-width: 0; }
}
