/* style.css */
:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-soft: #11182b;
  --panel: rgba(20, 29, 49, 0.88);
  --panel-solid: #151e34;
  --border: rgba(155, 172, 207, 0.16);
  --text: #f4f7ff;
  --muted: #93a0ba;
  --faint: #65718a;
  --blue: #6da8ff;
  --blue-soft: rgba(109, 168, 255, 0.16);
  --gold: #f5c76b;
  --green: #63d2a2;
  --purple: #bd9cff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f4f9;
  --bg-soft: #e8edf5;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --border: rgba(44, 59, 86, 0.13);
  --text: #172239;
  --muted: #65718a;
  --faint: #8994a8;
  --blue: #3975d5;
  --blue-soft: rgba(57, 117, 213, 0.11);
  --gold: #ae7814;
  --green: #218a63;
  --purple: #7654c2;
  --shadow: 0 16px 42px rgba(42, 60, 93, 0.12);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 85% -10%, rgba(100, 146, 255, 0.13), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background .25s ease, color .25s ease;
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 42px) 38px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, #6da8ff, #9a7aff);
  color: white;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(109, 168, 255, .25);
}

h1, h2, p { margin: 0; }
h1 { font-size: 21px; letter-spacing: -.02em; }
h2 { font-size: 16px; letter-spacing: -.01em; }
.brand p { color: var(--muted); font-size: 12px; margin-top: 2px; }

.top-actions, .editor-tools, .timer-actions { display: flex; align-items: center; gap: 9px; }

.primary-button, .icon-button, .small-button, .text-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 15px;
  color: var(--text);
  background: transparent;
  transition: transform .15s ease, background .15s ease, border .15s ease;
}

.primary-button {
  background: var(--blue);
  color: #071326;
  font-weight: 750;
  box-shadow: 0 6px 18px rgba(109, 168, 255, .18);
}

.primary-button:hover, .small-button:hover, .icon-button:hover { transform: translateY(-1px); }
.icon-button, .small-button { border-color: var(--border); background: var(--panel); }
.small-button { min-height: 36px; padding: 0 11px; font-weight: 700; }
.text-button { min-height: 36px; padding: 0 8px; color: var(--muted); }
.text-button:hover { color: var(--text); background: var(--blue-soft); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 13px;
  margin-bottom: 18px;
}

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

.stat-card {
  position: relative;
  overflow: hidden;
  min-height: 125px;
  padding: 19px;
  border-radius: 15px;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--blue);
}
.stat-card.accent-gold::before { background: var(--gold); }
.stat-card.accent-green::before { background: var(--green); }
.stat-card.accent-purple::before { background: var(--purple); }

.stat-label, .eyebrow {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 30px;
  letter-spacing: -.04em;
}

.stat-card small { color: var(--muted); font-size: 12px; }

.workspace {
  display: grid;
  grid-template-columns: 225px minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

.panel { border-radius: 16px; }
.sidebar { min-height: 650px; display: flex; flex-direction: column; }
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 19px 18px 15px;
}
.panel-heading h2 { margin-top: 5px; }
.chapter-list { padding: 0 9px; }
.chapter-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 9px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
  color: var(--text);
  background: transparent;
}
.chapter-item:hover { background: var(--blue-soft); }
.chapter-item.active { background: var(--blue-soft); border-color: rgba(109, 168, 255, .22); }
.chapter-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.chapter-item.active .chapter-number { color: var(--blue); background: rgba(109, 168, 255, .16); }
.chapter-info { min-width: 0; }
.chapter-info strong, .chapter-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-info strong { font-size: 13px; }
.chapter-info small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.sidebar-footer {
  margin-top: auto;
  padding: 17px;
  border-top: 1px solid var(--border);
}
.sidebar-footer label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.goal-control { display: flex; align-items: center; gap: 8px; }
.goal-control input {
  width: 90px;
  height: 39px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg-soft);
}
.goal-control span { color: var(--muted); font-size: 12px; }
.mini-progress, .progress-track, .timer-track {
  height: 7px;
  margin-top: 13px;
  overflow: hidden;
  border-radius: 20px;
  background: var(--bg-soft);
}
.mini-progress span, .progress-track span, .timer-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  transition: width .3s ease;
}

.editor-panel { min-height: 650px; overflow: hidden; }
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 19px;
  border-bottom: 1px solid var(--border);
}
.chapter-title-wrap { min-width: 0; }
.chapter-title {
  width: min(100%, 300px);
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 19px;
  font-weight: 750;
}
.save-status { display: block; margin-top: 4px; color: var(--green); font-size: 11px; }
.prompt-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 17px 19px 0;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--blue-soft);
}
.prompt-bar p { margin-top: 5px; color: var(--text); font-size: 13px; line-height: 1.4; }
.editor-panel textarea {
  display: block;
  width: calc(100% - 38px);
  min-height: 450px;
  margin: 18px 19px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.75;
}
.editor-panel textarea::placeholder { color: var(--faint); }
.editor-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 19px 17px;
  border-top: 1px solid var(--border);
}
.live-metrics { display: flex; gap: 15px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
.live-metrics strong { color: var(--text); }
.autosave-note { color: var(--faint); font-size: 11px; }

.right-rail { display: grid; gap: 16px; }
.mission-card, .achievements-card, .timer-card { padding-bottom: 17px; }
.mission-card > p { padding: 0 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.mission-progress { padding: 17px 18px 0; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.complete-message { margin: 12px 18px 0; padding: 9px 10px; border-radius: 8px; color: var(--green); background: rgba(99, 210, 162, .1); font-size: 12px; }
.reward { color: var(--gold); font-size: 11px; font-weight: 800; }
.muted { color: var(--muted); font-size: 11px; }
.achievements { padding: 0 13px; }
.achievement {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 5px;
  border-bottom: 1px solid var(--border);
  opacity: .5;
}
.achievement:last-child { border-bottom: 0; }
.achievement.unlocked { opacity: 1; }
.achievement-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  color: var(--muted);
  background: var(--bg-soft);
  font-weight: 800;
}
.achievement.unlocked .achievement-mark { color: #13251d; background: var(--green); }
.achievement strong, .achievement small { display: block; }
.achievement strong { font-size: 12px; }
.achievement small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.timer-card { padding-left: 18px; padding-right: 18px; }
.timer-card .panel-heading { padding: 2px 0 8px; }
.timer-card h2 { font-size: 28px; letter-spacing: .03em; }
.timer-tip { margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.full-width { width: 100%; margin-top: 16px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 4;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease;
  font-size: 13px;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
body.focus-mode .sidebar, body.focus-mode .right-rail { display: none; }
body.focus-mode .workspace { grid-template-columns: minmax(0, 1fr); max-width: 980px; margin: auto; }
body.focus-mode .editor-panel { min-height: calc(100vh - 160px); }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 200px minmax(0, 1fr); }
  .right-rail { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); }
  .sidebar { min-height: 620px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 14px 12px 28px; }
  .topbar { align-items: flex-start; }
  .top-actions { flex-direction: column; align-items: stretch; }
  .top-actions button { min-height: 40px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .stat-card { min-height: 106px; padding: 14px; }
  .stat-card strong { font-size: 24px; }
  .workspace { display: flex; flex-direction: column; }
  .sidebar, .editor-panel, .right-rail { width: 100%; }
  .sidebar { min-height: 0; }
  .chapter-list { display: flex; overflow-x: auto; gap: 5px; padding-bottom: 7px; }
  .chapter-item { min-width: 145px; margin: 0; }
  .sidebar-footer { margin-top: 8px; }
  .right-rail { display: grid; grid-template-columns: 1fr; }
  .editor-panel textarea { min-height: 390px; font-size: 18px; }
  .editor-toolbar, .editor-footer, .prompt-bar { align-items: flex-start; }
  .editor-toolbar, .editor-footer { flex-direction: column; }
  .prompt-bar { flex-direction: column; }
  .prompt-bar .small-button { align-self: flex-end; }
}

@media (max-width: 380px) {
  .brand p { display: none; }
  .stats-grid { gap: 7px; }
  .stat-card small { font-size: 10px; }
  .stat-card strong { font-size: 21px; }
}
