/* ─── Reset & base ────────────────────────────────────────────────────── */
:root {
  --card-max-width: 880px;
  --card-min-height: 70vh;
  --card-padding-y: 36px;
  --card-padding-x: 48px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #faf9f6;
  color: #1a1a1a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
a { color: #2952b3; text-decoration: none; }
a:hover { text-decoration: underline; }
kbd {
  font: inherit;
  font-size: 0.78em;
  background: #ececec;
  border: 1px solid #d4d4d4;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ─── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid #ececec;
  background: #fff;
  gap: 16px;
}
.topbar__left { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.topbar__right { display: flex; gap: 8px; justify-content: flex-end; }
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar h1 .muted { color: #999; font-weight: 400; }
.position { color: #666; font-size: 14px; font-variant-numeric: tabular-nums; }

.progress { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.progress__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  color: #555;
  background: #f3f1ed;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 120ms, border-color 120ms, background 120ms;
}
.progress__chip:hover { border-color: #d4d4d4; }
.progress__chip b { color: #1a1a1a; font-weight: 600; }
.progress__chip .dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.progress__chip[data-level="0"] .dot { background: #c5c5c5; }
.progress__chip[data-level="1"] .dot { background: #d9534f; }
.progress__chip[data-level="2"] .dot { background: #e8a93a; }
.progress__chip[data-level="3"] .dot { background: #4a9c5a; }
.progress__chip[data-level="4"] .dot { background: #6c8ebf; }
.progress__chip.is-off { opacity: 0.4; }
.progress__chip.is-off b,
.progress__chip.is-off span:not(.dot) { text-decoration: line-through; }

.btn {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid #d4d4d4;
  background: #fff;
  color: #333;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { background: #f5f3ee; }
.btn--active,
.btn.is-active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.btn--active:hover,
.btn.is-active:hover { background: #333; }
.btn--ghost.is-active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.btn--ghost { border-color: transparent; color: #888; }
.btn--ghost:hover { background: #f0eee8; color: #333; }
.btn--icon {
  padding: 6px 10px;
  font-size: 16px;
  line-height: 1;
}
.btn--search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #888;
}
.btn--search:hover { color: #333; }
.btn__kbd {
  font-size: 11px;
  background: #f3f1ed;
  border: 1px solid #e0ddd5;
  border-radius: 4px;
  padding: 1px 5px;
  color: #888;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ─── Search modal ────────────────────────────────────────────────────── */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.32);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  z-index: 100;
  animation: fadeIn 100ms ease;
}
.search-overlay[hidden] { display: none; }
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.search-modal {
  width: min(640px, 92vw);
  max-height: 70vh;
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.search-modal__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #ececec;
}
.search-input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  border: none;
  outline: none;
  background: transparent;
  color: #1a1a1a;
}
.search-input::placeholder { color: #aaa; }
.search-modal__close {
  font-size: 11px;
  background: #f3f1ed;
  border: 1px solid #e0ddd5;
  border-radius: 4px;
  padding: 2px 7px;
  color: #888;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  min-height: 0;
}
.search-results:empty::before {
  content: "type to search across titles, ids, problems, and notes";
  display: block;
  padding: 18px 22px;
  color: #aaa;
  font-size: 13px;
  font-style: italic;
}
.search-result {
  padding: 10px 18px;
  cursor: pointer;
  border-left: 2px solid transparent;
}
.search-result:hover { background: #faf9f6; }
.search-result.is-active {
  background: #f3f1ed;
  border-left-color: #1a1a1a;
}
.search-result__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 14px;
  margin-bottom: 2px;
}
.search-result__id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #888;
  min-width: 36px;
}
.search-result__title {
  font-weight: 600;
  color: #1a1a1a;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result__where {
  font-size: 11px;
  color: #888;
  background: #f3f1ed;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.search-result__snippet {
  font-size: 12.5px;
  color: #666;
  line-height: 1.45;
  margin-left: 46px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result__snippet mark {
  background: #fff3b8;
  color: #1a1a1a;
  padding: 0 2px;
  border-radius: 2px;
}
.search-result__title mark {
  background: #fff3b8;
  color: #1a1a1a;
  padding: 0 2px;
  border-radius: 2px;
}
.search-modal__hint {
  padding: 10px 18px;
  border-top: 1px solid #ececec;
  background: #faf9f6;
  font-size: 11px;
  color: #888;
  display: flex;
  gap: 14px;
  align-items: center;
}
.search-modal__hint kbd {
  font-size: 10px;
  padding: 1px 5px;
}

/* ─── Settings popover ────────────────────────────────────────────────── */
.settings-wrap { position: relative; }
.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
  padding: 14px 16px;
  z-index: 50;
}
.settings-panel[hidden] { display: none; }
.settings-panel__title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  margin-bottom: 10px;
}
.settings-row { margin-bottom: 12px; }
.settings-row:last-of-type { margin-bottom: 14px; }
.settings-row label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
}
.settings-row__val {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #888;
  font-variant-numeric: tabular-nums;
}
.settings-row input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: #1a1a1a;
}
.settings-panel__reset {
  width: 100%;
  font-size: 12px;
  padding: 6px 10px;
  text-align: center;
}

/* ─── Stage / card ────────────────────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 28px 16px;
  gap: 14px;
}
.nav {
  flex: 0 0 auto;
  width: 44px;
  border-radius: 50%;
  align-self: center;
  font-size: 28px;
  color: #999;
  height: 44px;
  background: #fff;
  border: 1px solid #ececec;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.nav:hover { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }

.card {
  width: 100%;
  max-width: var(--card-max-width);
  outline: none;
}
.card__inner {
  position: relative;
  width: 100%;
  min-height: var(--card-min-height);
}

.card__face {
  position: absolute;
  inset: 0;
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 12px;
  padding: var(--card-padding-y) var(--card-padding-x);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03), 0 8px 32px rgba(0,0,0,0.04);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  opacity: 1;
  visibility: visible;
  transition: opacity 220ms ease;
}

/* Show front by default; hide back. Flip toggles via .flipped on inner. */
.card__inner .card__back { opacity: 0; visibility: hidden; pointer-events: none; }
.card__inner.flipped .card__front { opacity: 0; visibility: hidden; pointer-events: none; }
.card__inner.flipped .card__back  { opacity: 1; visibility: visible; pointer-events: auto; }

.meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.title {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: -0.01em;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
}
.lc-link {
  font-size: 12px;
  color: #999;
  white-space: nowrap;
}
.lc-link:hover { color: #2952b3; }

.badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 999px;
  background: #ececec;
  color: #555;
}
.badge[data-difficulty="easy"]   { background: #e3f1e6; color: #2f7a3e; }
.badge[data-difficulty="medium"] { background: #fbeed1; color: #9b6a14; }
.badge[data-difficulty="hard"]   { background: #f7dcd9; color: #a52a25; }

.stats {
  font-size: 12px;
  color: #888;
  font-variant-numeric: tabular-nums;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  display: inline-flex;
  gap: 14px;
  align-items: baseline;
}
.stats:empty { display: none; }
.stats__num {
  color: #1a1a1a;
  font-weight: 600;
}

.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f3f1ed;
  color: #666;
}

.content {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.7;
  color: #2a2a2a;
  flex: 1;
}
.content p { margin: 0 0 14px; }
.content strong { font-weight: 600; }
.content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, "Roboto Mono", monospace;
  font-size: 0.88em;
  background: #f3f1ed;
  padding: 1px 6px;
  border-radius: 4px;
}
.content pre {
  background: #fafaf7;
  border: 1px solid #ececec;
  border-radius: 8px;
  padding: 16px 18px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.55;
  margin: 14px 0;
}
.content pre code {
  background: none;
  padding: 0;
  font-size: 14px;
}
.content blockquote {
  margin: 14px 0;
  padding: 4px 16px;
  border-left: 3px solid #d4d4d4;
  color: #555;
  font-style: italic;
}
.content ul, .content ol { padding-left: 24px; margin: 8px 0 16px; }
.content li { margin-bottom: 4px; }

.section { margin-bottom: 26px; }
.section h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ececec;
  letter-spacing: -0.005em;
}
.section__body { font-size: 17px; }

.hint {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: #aaa;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.loading { color: #999; font-style: italic; }
.error {
  background: #fdf2f1;
  color: #a52a25;
  border: 1px solid #f3d6d3;
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ─── Rate bar ────────────────────────────────────────────────────────── */
.ratebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #ececec;
  background: #fff;
  flex-wrap: wrap;
}
.ratebar__label { font-size: 13px; color: #666; }
.ratebar__hint { margin-left: auto; font-size: 11px; color: #aaa; }

.rate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid #d4d4d4;
  background: #fff;
  color: #555;
  transition: all 120ms;
}
.rate:hover { background: #f5f3ee; }
.rate .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.rate[data-level="1"] .dot { background: #d9534f; }
.rate[data-level="2"] .dot { background: #e8a93a; }
.rate[data-level="3"] .dot { background: #4a9c5a; }
.rate[data-level="4"] .dot { background: #6c8ebf; }
.rate--clear { color: #999; }

.rate--active { font-weight: 600; }
.rate[data-level="1"].rate--active { background: #d9534f; color: #fff; border-color: #d9534f; }
.rate[data-level="2"].rate--active { background: #e8a93a; color: #fff; border-color: #e8a93a; }
.rate[data-level="3"].rate--active { background: #4a9c5a; color: #fff; border-color: #4a9c5a; }
.rate[data-level="4"].rate--active { background: #6c8ebf; color: #fff; border-color: #6c8ebf; }
.rate.rate--active .dot { background: #fff; }

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr; gap: 8px; }
  .topbar__center { order: 3; }
  .topbar__right { justify-content: flex-start; flex-wrap: wrap; }
  .card__face { padding: 24px 22px; }
  .title { font-size: 22px; }
  .content { font-size: 16px; }
  .section h2 { font-size: 18px; }
  .nav { display: none; }
  .ratebar__hint { display: none; }
}
