:root {
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --surface-muted: #F3EFE8;
  --ink: #1C2430;
  --ink-soft: #525D6D;
  --ink-muted: #848D9A;
  --accent: #B84A39;
  --teal: #1D6A5B;
  --border: rgba(28, 36, 48, 0.10);
  --border-strong: rgba(28, 36, 48, 0.20);
  --shadow: 0 2px 14px rgba(28, 36, 48, 0.045);
  --radius: 16px;
  --serif: Georgia, "Times New Roman", "Songti SC", "STSong", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.serif-title { font-family: var(--serif); font-weight: 700; letter-spacing: -0.015em; line-height: 1.28; }
.muted-text { color: var(--ink-soft); font-size: 15px; margin: 0; }
.muted-small { color: var(--ink-muted); font-size: 13px; }
.error-text { color: var(--accent); font-size: 14px; margin-top: 10px; }

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(250, 248, 245, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 18px; color: var(--ink); }

/* Container */
.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px calc(48px + env(safe-area-inset-bottom));
}

/* Buttons */
button { font-family: inherit; cursor: pointer; border: none; background: none; }

.btn-primary {
  background: var(--ink);
  color: #fff;
  padding: 13px 22px;
  min-height: 48px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  transition: opacity .15s ease, transform .1s ease;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-pill {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  padding: 8px 16px;
  min-height: 40px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}
.btn-pill:hover { border-color: var(--ink); }

.btn-pill-sm {
  background: var(--surface-muted);
  color: var(--ink);
  padding: 6px 13px;
  min-height: 36px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.btn-ghost {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 4px;
  min-height: 44px;
}

.btn-text {
  color: var(--ink-muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 6px 8px;
}
.btn-text:hover { color: var(--ink); }

/* Home View */
.home-header { margin-bottom: 24px; }
.week-kicker {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.home-title { font-size: clamp(26px, 4vw, 32px); margin: 0 0 8px; }

.article-list { display: flex; flex-direction: column; gap: 14px; }

.article-card, .editor-entry-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: border-color .18s ease, transform .15s ease;
}
.article-card:hover, .editor-entry-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.card-meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-soft);
}
.pill-accent { background: rgba(184, 74, 57, 0.11); color: var(--accent); }
.pill-done { background: rgba(29, 106, 91, 0.12); color: var(--teal); }

.card-title { margin: 0 0 6px; font-size: 20px; color: var(--ink); }
.card-hook { margin: 0; font-size: 14.5px; color: var(--ink-soft); line-height: 1.5; }
.card-arrow { font-size: 20px; color: var(--ink-muted); flex-shrink: 0; }
.divider-space { height: 22px; }

/* Studio View */
.studio-header { margin-bottom: 18px; }
.studio-title { margin: 0 0 6px; font-size: clamp(24px, 3.6vw, 30px); }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 14px;
  gap: 4px;
  margin-bottom: 18px;
}
.seg-btn {
  padding: 10px 8px;
  min-height: 44px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: all .15s ease;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.workspace {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mission-bar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #FCFBF9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.mission-text { font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }

/* Chat Feed */
.chat-feed {
  padding: 20px 18px;
  min-height: 320px;
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.ai { align-self: flex-start; }
.msg.user { align-self: flex-end; align-items: flex-end; }

.bubble {
  padding: 13px 16px;
  border-radius: 16px;
  font-size: 15.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.msg.ai .bubble {
  background: var(--surface-muted);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.msg.user .bubble {
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-img {
  max-width: 200px;
  border-radius: 10px;
  margin-bottom: 8px;
  display: block;
}
.msg-actions { margin-top: 4px; display: flex; align-items: center; gap: 10px; }
.speak-btn {
  font-size: 12.5px;
  color: var(--ink-muted);
  padding: 4px 6px;
  font-weight: 600;
}
.speak-btn:hover { color: var(--ink); }

.typing-dots { color: var(--ink-muted); font-size: 14px; font-style: italic; }

/* Composer */
.photo-preview-bar {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: #FCFBF9;
  display: flex;
  align-items: center;
  gap: 12px;
}
.photo-preview-bar img {
  width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border);
}
.photo-preview-info { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-soft); }

.recording-bar {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: #FDF3F1;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s infinite;
  flex-shrink: 0;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.btn-stop-rec {
  background: var(--accent); color: #fff; padding: 8px 14px; min-height: 38px;
  border-radius: 999px; font-size: 13.5px; font-weight: 700;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--surface-muted);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: #EAE4D9; }
.composer textarea {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 15.5px;
  line-height: 1.4;
  resize: none;
  min-height: 46px;
  max-height: 130px;
  background: #FCFBF9;
  color: var(--ink);
}
.composer textarea:focus { outline: none; border-color: var(--ink); background: #fff; }

.btn-send {
  background: var(--ink);
  color: #fff;
  height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.btn-send:disabled { opacity: 0.45; }

/* Story Pane (Apple Books feel) */
.story-empty {
  padding: 46px 26px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}
.story-focus-badge {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--teal);
  background: rgba(29, 106, 91, 0.1);
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.story-empty h2 { margin: 0 0 10px; font-size: 24px; }
.story-empty p { margin-bottom: 22px; }

.story-reader { padding: 22px 26px 26px; }
.story-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.prose {
  font-family: var(--serif);
  font-size: 18.5px;
  line-height: 1.85;
  color: var(--ink);
}
.prose h3 { font-size: 24px; margin: 0 0 16px; line-height: 1.3; }
.prose p { margin: 0 0 16px; }
.prose .vocab-word {
  font-weight: 700;
  color: var(--teal);
  border-bottom: 1.5px dashed rgba(29, 106, 91, 0.55);
  cursor: pointer;
  padding: 0 2px;
}

.vocab-peek {
  margin: 14px 0 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #F2F7F5;
  border: 1px solid rgba(29, 106, 91, 0.22);
}
.vocab-peek-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.vocab-peek-head strong { font-family: var(--serif); font-size: 18px; color: var(--teal); }
.vocab-peek-en { font-size: 14.5px; color: var(--ink); }
.vocab-peek-cn { font-size: 13.5px; color: var(--ink-soft); margin-top: 2px; }

.story-discuss {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.discuss-label {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 10px;
}
.story-qa-feed { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.compact-composer { border-top: none; padding: 0; }

/* Junior Editor */
.editor-desk {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.field-label { display: block; font-size: 13.5px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 16px; }
.text-field {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 15.5px;
  background: #FCFBF9;
  color: var(--ink);
}
.text-field:focus { outline: none; border-color: var(--ink); background: #fff; }
.serif-input { font-family: var(--serif); font-size: 18px; font-weight: 700; }
.body-field { min-height: 220px; line-height: 1.7; resize: vertical; }
.editor-actions { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.editor-feedback {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.feedback-body { font-size: 15.5px; line-height: 1.7; white-space: pre-wrap; }

/* Overlays & Modals */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(28, 36, 48, 0.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  width: 100%;
  max-width: 660px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}
.pin-card { max-width: 390px; text-align: center; padding: 30px 24px; }
.pin-eyebrow { font-size: 12.5px; font-weight: 700; color: var(--accent); letter-spacing: 0.06em; margin-bottom: 8px; }
.pin-form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.pin-form input {
  text-align: center; font-size: 20px; letter-spacing: 0.2em;
  padding: 12px; border: 1px solid var(--border-strong); border-radius: 12px;
}
.modal-top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.modal-top-actions { display: flex; align-items: center; gap: 10px; }

/* Newspaper Clipping Preview */
.newspaper-sheet {
  background: #FBF8F1;
  border: 1px solid #D5CCB8;
  padding: 26px 24px;
  color: #161616;
  font-family: var(--serif);
}
.np-masthead {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.12em;
  border-bottom: 3px double #161616;
  padding-bottom: 8px;
}
.np-subline {
  display: flex; justify-content: space-between; font-family: var(--sans);
  font-size: 11px; letter-spacing: 0.08em; color: #555;
  padding: 6px 0; border-bottom: 1px solid #161616; margin-bottom: 16px;
}
.np-headline { font-size: 25px; line-height: 1.25; margin: 0 0 14px; }
.np-columns {
  column-count: 2; column-gap: 24px; font-size: 15px; line-height: 1.7; text-align: justify;
  white-space: pre-wrap;
}

/* Parent Report */
.parent-content { font-size: 14.5px; line-height: 1.7; }
.parent-stat-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px;
}
.stat-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
.stat-num { font-size: 22px; font-weight: 800; color: var(--ink); }
.parent-actions {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 90;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

@media (max-width: 600px) {
  .container { padding: 20px 14px 48px; }
  .story-reader { padding: 18px 16px; }
  .np-columns { column-count: 1; }
  .parent-stat-row { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden; }
  #newspaperSheet, #newspaperSheet * { visibility: visible; }
  #newspaperSheet { position: absolute; left: 0; top: 0; width: 100%; border: none; }
}
