:root {
  --bg: #f5efe3;
  --bg2: #efe0cf;
  --card: rgba(255, 255, 255, 0.82);
  --card-strong: #fffaf3;
  --ink: #1f1a17;
  --muted: #6d6258;
  --accent: #7c4e2a;
  --accent-2: #2f6658;
  --line: rgba(70, 48, 27, 0.12);
  --shadow: 0 20px 50px rgba(70, 48, 27, 0.12);
  --radius: 24px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(124, 78, 42, 0.18), transparent 34%),
    radial-gradient(circle at bottom right, rgba(47, 102, 88, 0.15), transparent 32%),
    linear-gradient(180deg, var(--bg), var(--bg2));
}

.shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 20px 16px 96px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.hero-actions {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 52px);
  line-height: 1.02;
}

.subtitle {
  margin: 10px 0 0;
  max-width: 60ch;
  color: var(--muted);
  line-height: 1.6;
}

.hero-badge {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.mobile-only {
  display: none;
}

.layout {
  display: grid;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(14px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.controls, .editor, .list, .card {
  padding: 16px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sync-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-top: 8px;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.sync-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.chip {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
  color: var(--accent);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.chip.active {
  background: var(--accent);
  color: white;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

input, textarea, select, button {
  font: inherit;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: rgba(124, 78, 42, 0.45);
  box-shadow: 0 0 0 4px rgba(124, 78, 42, 0.12);
}

.card-head, .panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.card h2 {
  margin: 2px 0 0;
  font-size: clamp(28px, 5vw, 48px);
}

.small, .panel-title p, .progress, .count-text {
  margin: 0;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meta-grid div, .meaning-block {
  padding: 12px 14px;
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.meta-grid span, .meaning-block span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.meta-grid strong {
  font-size: 15px;
  line-height: 1.45;
}

.summary-lines {
  display: grid;
  gap: 10px;
}

.summary-line {
  padding: 12px 14px;
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.summary-line span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.summary-line strong {
  display: block;
  font-size: 15px;
  line-height: 1.55;
}

.meaning-block p {
  margin: 0;
  font-size: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.raw-details {
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.raw-details summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 700;
}

.raw-details pre {
  white-space: pre-wrap;
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  overflow: auto;
  max-height: 300px;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.full {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 14px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:hover {
  transform: translateY(-1px);
}

.primary {
  background: linear-gradient(135deg, var(--accent), #a96d3f);
  color: white;
  box-shadow: 0 14px 28px rgba(124, 78, 42, 0.22);
}

.ghost, .toolbar button {
  background: rgba(255,255,255,0.84);
  color: var(--ink);
  border: 1px solid var(--line);
}

.list-view {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  max-height: 380px;
  overflow: auto;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.72);
  display: grid;
  gap: 6px;
}

.list-item.active {
  background: rgba(124, 78, 42, 0.10);
  border-color: rgba(124, 78, 42, 0.28);
}

.list-item strong {
  font-size: 15px;
}

.list-item span {
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: linear-gradient(180deg, rgba(245,239,227,0.08), rgba(245,239,227,0.95));
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.book-picker {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
}

.book-picker[hidden] {
  display: none !important;
}

.book-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 10, 0.42);
  backdrop-filter: blur(6px);
}

.book-picker-sheet {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100vw - 24px));
  max-height: min(78vh, 760px);
  overflow: auto;
  margin: 12px;
  padding: 16px;
  border-radius: 24px 24px 18px 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 250, 243, 0.96);
  box-shadow: 0 -24px 60px rgba(20, 14, 10, 0.2);
}

.book-picker-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.book-picker-head h3 {
  margin: 2px 0 0;
  font-size: 20px;
}

.book-picker-grid {
  display: grid;
  gap: 10px;
}

.book-option {
  text-align: left;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  display: grid;
  gap: 4px;
}

.book-option.active {
  background: rgba(124, 78, 42, 0.12);
  border-color: rgba(124, 78, 42, 0.26);
}

.book-option strong {
  font-size: 16px;
}

.book-option span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

section[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .shell {
    padding: 12px 12px 88px;
  }

  .hero {
    flex-direction: column;
    align-items: start;
    margin-bottom: 12px;
    gap: 10px;
  }

  .hero-actions {
    display: flex;
  }

  .subtitle {
    display: none;
  }

  .hero h1 {
    font-size: clamp(24px, 8vw, 36px);
  }

  .hero-badge {
    padding: 8px 10px;
    font-size: 12px;
  }

  .row,
  .editor-grid,
  .meta-grid {
    display: none;
  }

  .sync-row {
    display: grid;
    gap: 8px;
  }

  .sync-actions {
    justify-content: stretch;
  }

  .sync-actions button {
    flex: 1 1 0;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .controls .chips {
    display: none;
  }

  .controls {
    display: block;
  }

  .card,
  .editor,
  .list {
    padding: 12px;
  }

  .card h2 {
    font-size: clamp(22px, 7vw, 34px);
  }

  .stack {
    gap: 10px;
  }

  .summary-lines {
    gap: 8px;
  }

  .summary-line,
  .meaning-block,
  .meta-grid div {
    padding: 10px 12px;
    border-radius: 16px;
  }

  .summary-line strong,
  .meaning-block p,
  .meta-grid strong {
    font-size: 14px;
    line-height: 1.45;
  }

  .raw-details {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
  }

  .panel-title h3 {
    margin: 0;
  }

  .actions {
    margin-top: 12px;
  }

  .actions button,
  .toolbar button,
  .sync-actions button {
    padding: 10px 12px;
  }

  .book-picker {
    align-items: end;
  }

  .book-picker-sheet {
    width: calc(100vw - 16px);
    max-height: 80vh;
    margin: 8px;
    padding: 14px;
  }

  .book-picker-head {
    flex-direction: column;
  }

  .list-view {
    max-height: none;
  }
}
