:root {
  color-scheme: light;
  --ink: #18201d;
  --muted: #66716c;
  --line: #d8dfdb;
  --paper: #f7f9f7;
  --surface: #ffffff;
  --green: #18794e;
  --green-soft: #e7f4ed;
  --blue: #2563a9;
  --code: #151a18;
  --code-ink: #e9f1ed;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
  min-width: 230px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--ink);
  color: white;
  font: 700 14px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  border-radius: 6px;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 2px; }

.progress {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.progress-line { width: 100px; height: 4px; background: #e5e9e7; overflow: hidden; }
.progress-line i { display: block; width: 100%; height: 100%; background: var(--green); }

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.search-wrap {
  margin: 18px 16px 12px;
  height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
}

.search-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.search-icon { padding-left: 12px; color: var(--muted); font-size: 20px; }
.search-wrap input { border: 0; outline: 0; background: transparent; min-width: 0; flex: 1; padding: 0 10px; color: var(--ink); }
.search-wrap kbd { margin-right: 9px; padding: 2px 6px; border: 1px solid var(--line); color: var(--muted); background: white; font-size: 11px; }

.categories {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 0 0 auto;
  gap: 6px;
  padding: 0 16px 12px;
  position: relative;
  z-index: 2;
  background: var(--surface);
}

.category-button {
  min-width: 0;
  border: 1px solid var(--line);
  background: white;
  padding: 6px 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.category-button.active { border-color: var(--green); color: var(--green); background: var(--green-soft); }

.problem-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 18px;
}

.problem-item {
  width: 100%;
  border: 0;
  background: transparent;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  text-align: left;
  padding: 11px 10px;
  color: var(--ink);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.problem-item:hover { background: var(--paper); }
.problem-item.active { background: var(--green-soft); border-left-color: var(--green); }
.problem-number { color: var(--muted); font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.problem-name { min-width: 0; }
.problem-name strong { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.problem-name small { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }

.reader {
  width: min(980px, 100%);
  padding: 48px 56px 72px;
  margin: 0 auto;
}

.reader-head { display: flex; justify-content: space-between; gap: 28px; align-items: flex-start; }
.category-label { margin: 0 0 8px; color: var(--green); font-size: 13px; font-weight: 700; }
h1 { margin: 0; font-size: 32px; line-height: 1.25; letter-spacing: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.meta span { padding: 5px 8px; border: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.reader-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.command-button {
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
}
.command-button.primary { background: var(--green); color: white; border-color: var(--green); }
.command-button:hover { filter: brightness(0.97); }

.statement, .explanation, .code-section { margin-top: 42px; }
h2 { margin: 0 0 16px; font-size: 18px; letter-spacing: 0; }
.statement {
  padding: 18px 20px;
  border-left: 3px solid var(--blue);
  background: #eef4fa;
}
.statement h2 { margin-bottom: 10px; }
.statement p { margin: 0; color: #35475a; line-height: 1.75; font-size: 15px; }
.explanation p { margin: 0 0 10px; color: #35403b; line-height: 1.75; font-size: 15px; }
.explanation p:first-child { font-weight: 600; color: var(--ink); }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.section-heading span { color: var(--muted); font-size: 12px; }
pre {
  margin: 0;
  padding: 22px;
  overflow: auto;
  background: var(--code);
  color: var(--code-ink);
  border-left: 4px solid var(--green);
  tab-size: 4;
}
code { font: 13px/1.65 "Cascadia Code", "SFMono-Regular", Consolas, monospace; white-space: pre; }

.problem-nav {
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.problem-nav button {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  padding: 8px 0;
}
.problem-nav button:disabled { color: #adb5b1; cursor: default; }
.problem-nav span { color: var(--muted); font-size: 12px; }

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
}
.mobile-only, .sidebar-backdrop { display: none; }

@media (max-width: 820px) {
  .topbar { padding: 0 14px; gap: 12px; }
  .mobile-only { display: grid; place-items: center; }
  .brand { min-width: 0; }
  .progress-line { display: none; }
  .workspace { display: block; }
  .sidebar {
    position: fixed;
    z-index: 40;
    top: 64px;
    left: 0;
    width: min(88vw, 350px);
    transform: translateX(-102%);
    transition: transform 180ms ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 64px 0 0;
    border: 0;
    background: rgba(24, 32, 29, 0.34);
    z-index: 30;
  }
  .sidebar-backdrop.open { display: block; }
  .reader { padding: 32px 20px 56px; }
  .reader-head { display: block; }
  .reader-actions { margin-top: 22px; }
  h1 { font-size: 26px; }
}

@media (max-width: 480px) {
  .brand small { display: none; }
  .progress { font-size: 12px; }
  .reader-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .command-button { text-align: center; }
  pre { margin-left: -20px; margin-right: -20px; padding: 18px 20px; }
}
