:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #7b8794;
  --border: #e4e7eb;
  --accent: #2563eb;
  --accent-soft: #eef4ff;
  --green: #16a34a;
  --green-soft: #eafaf0;
  --red: #dc2626;
  --red-soft: #fdecec;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.75;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- sidebar ---------- */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
}

.sidebar-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.progress-summary {
  font-size: 13px;
  color: var(--muted);
}

.progress-summary b { color: var(--accent); }

.nav-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.nav-item .num {
  flex: 0 0 auto;
  min-width: 30px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.nav-item.active .num { color: var(--accent); }

.nav-item .t {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}

.dot.done { background: var(--green); }
.dot.partial { background: #f59e0b; }

/* ---------- main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
}

.icon-btn:hover { background: var(--bg); }

.pos {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.spacer { flex: 1; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: #1d4ed8; }

.btn.ghost { background: transparent; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 40px;
}

.passage-title {
  margin: 0 0 18px;
  font-size: 22px;
  font-weight: 700;
}

.passage-text {
  font-size: 17px;
  line-height: 2.1;
  max-width: 820px;
  margin: 0 auto;
  color: #2c3642;
}

/* ---------- blanks ---------- */
.blank {
  display: inline;
  white-space: nowrap;
}

.blank .prefix {
  color: var(--text);
  font-weight: 500;
}

.blank-input {
  display: inline-block;
  width: auto;
  font-size: 16px;
  font-family: inherit;
  color: var(--accent);
  border: none;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  padding: 0 4px 2px;
  margin: 0 2px;
  outline: none;
  text-align: left;
}

.blank-input:focus {
  background: var(--accent-soft);
  border-radius: 3px 3px 0 0;
}

.blank-input.correct {
  color: var(--green);
  border-bottom-color: var(--green);
  background: var(--green-soft);
  border-radius: 3px 3px 0 0;
}

.blank-input.incorrect {
  color: var(--red);
  border-bottom-color: var(--red);
  background: var(--red-soft);
  border-radius: 3px 3px 0 0;
}

.reveal {
  font-size: 14px;
  font-weight: 600;
  margin-left: 4px;
}

.reveal.ok { color: var(--green); }
.reveal.bad { color: var(--red); }

/* ---------- actions ---------- */
.actions {
  padding: 16px 40px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 66px;
}

.score {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.score.good { color: var(--green); }
.score.mid { color: #d97706; }
.score.bad { color: var(--red); }

.hint {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- responsive ---------- */
.backdrop { display: none; }

#toggleSidebar { display: none; }

@media (max-width: 720px) {
  #toggleSidebar { display: inline-block; }

  .backdrop {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 19;
  }
  .backdrop.show { display: block; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    margin-left: -300px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
  }
  .sidebar.open { margin-left: 0; }
  .content { padding: 20px 18px; }
  .actions { padding: 14px 18px; }
  .passage-text { font-size: 16px; }
}
