/* Writing Station — calm, focused, mobile-first. */
:root {
  --editor-size: 20px;
  --editor-lh: 1.7;
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #24211c;
  --text-soft: #6b6455;
  --muted: #97907f;
  --border: #e4e0d6;
  --accent: #7a5c3e;
  --accent-soft: #ede4d8;
  --danger: #b0473a;
  --shadow: 0 1px 3px rgba(40,33,20,.06), 0 6px 24px rgba(40,33,20,.05);
  --radius: 12px;
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --ui-font: var(--sans);
}
:root[data-theme='dark'] {
  --bg: #16150f; --surface: #201e18; --surface-2: #2a271f;
  --text: #e9e5da; --text-soft: #b3ac9c; --muted: #837c6c;
  --border: #34302650; --border: #35322a; --accent: #c8a678; --accent-soft: #322c22;
  --danger: #d4796c; --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.35);
}
:root[data-theme='paperwhite'] {
  /* Kindle-style e-ink: warm off-white, soft ink, minimal contrast glare. */
  --bg: #e8e4db; --surface: #efece4; --surface-2: #e3ded3;
  --text: #33302a; --text-soft: #5f5b51; --muted: #8b867a;
  --border: #d3cec1; --accent: #55503f; --accent-soft: #ddd8cb;
  --danger: #8a4a3f; --shadow: none;
}
:root[data-font='sans'] { --reading-font: var(--sans); }
:root[data-font='serif'] { --reading-font: var(--serif); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.center { display: grid; place-items: center; min-height: 60dvh; }
.muted { color: var(--muted); }
.container { max-width: 900px; margin: 0 auto; padding: 22px 20px 80px; width: 100%; }

/* Buttons */
.btn { font: inherit; font-family: var(--ui-font); border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 12px; border-radius: 9px; cursor: pointer; line-height: 1;
  transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn.lg { padding: 12px 18px; font-size: 16px; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
:root[data-theme='dark'] .btn.primary, :root[data-theme='paperwhite'] .btn.primary { color: #fff; }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { display: block; width: 100%; margin: 6px 0; text-align: center; }
.btn.icon { padding: 6px 10px; font-size: 18px; line-height: 1; }
.btn.icon.sm { font-size: 14px; padding: 4px 7px; }
.btn.fmt { font-family: var(--serif); font-weight: 700; min-width: 30px; }
.btn.fmt:nth-child(2) { font-style: italic; }
.btn.on { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 3px; }

/* Login */
.login-wrap { flex: 1; display: grid; place-items: center; padding: 24px; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 40px 34px; width: min(400px, 92vw); text-align: center; }
.brand-mark { font-size: 40px; }
.login-box h1 { margin: 8px 0 4px; font-family: var(--serif); font-weight: 600; letter-spacing: .2px; }
.login-box p { margin: 0 0 22px; }
.input-lg { width: 100%; padding: 13px 14px; font-size: 16px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg); color: var(--text); margin-bottom: 12px; }
.input-lg:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.login-err { color: var(--danger); min-height: 20px; margin-top: 10px; font-size: 14px; }
.login-box .btn.lg { width: 100%; }
.login-box .btn.sm { margin-top: 14px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
:root[data-theme='paperwhite'] .topbar { backdrop-filter: none; background: var(--bg); }
.tb-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-title { font-family: var(--serif); font-size: 18px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.project .tb-title { cursor: pointer; }
.tabs { display: flex; gap: 2px; margin: 0 auto; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tab { border: none; background: transparent; color: var(--text-soft); padding: 6px 16px; border-radius: 8px;
  cursor: pointer; font: inherit; font-family: var(--ui-font); font-size: 14px; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tb-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* Not-syncing banner */
.sync-banner { padding: 11px 16px; text-align: center; font-size: 13.5px; cursor: pointer; line-height: 1.4; }
.sync-banner.warn { background: #8a4a3f; color: #fff; }
:root[data-theme='dark'] .sync-banner.warn { background: #b0473a; }
.sync-banner:hover { filter: brightness(1.08); }

/* Sync badge */
.sync-badge { border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  font-size: 12px; padding: 5px 10px; border-radius: 20px; cursor: pointer; white-space: nowrap; }
.sync-badge.s-ok { color: #2f7d4f; } .sync-badge.s-error { color: var(--danger); }
.sync-badge.s-syncing { color: var(--accent); }

/* Library */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.proj-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; box-shadow: var(--shadow); transition: transform .1s, border-color .12s;
  display: flex; flex-direction: column; gap: 8px; min-height: 150px; }
.proj-del { position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity .12s;
  background: var(--surface-2); border-color: transparent; line-height: 1; }
.proj-card:hover .proj-del { opacity: .6; }
.proj-del:hover { opacity: 1 !important; color: var(--danger); }
.proj-title { padding-right: 30px; }
@media (hover: none) { .proj-del { opacity: .5; } }
.proj-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.proj-title { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.proj-syn { font-size: 14px; color: var(--text-soft); flex: 1; }
.proj-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-soft); }
.proj-updated { font-size: 12px; }
.proj-card.new { align-items: center; justify-content: center; border-style: dashed; color: var(--muted);
  box-shadow: none; background: transparent; }
.proj-card.new .plus { font-size: 34px; line-height: 1; }

/* Project body */
.proj-body { flex: 1; display: flex; min-height: 0; }

/* Write layout */
.write-layout { flex: 1; display: flex; min-height: 0; width: 100%; }
.chapters { width: 240px; border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; overflow-y: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.chapter-list { padding: 0 8px 16px; }
.chap-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 10px;
  border-radius: 8px; cursor: pointer; }
.chap-item:hover { background: var(--surface-2); }
.chap-item.active { background: var(--accent-soft); }
.chap-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chap-words { font-size: 12px; }

.editor-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap; }
.chap-title-input { flex: 1; min-width: 120px; border: none; background: transparent; color: var(--text);
  font-family: var(--serif); font-size: 18px; font-weight: 600; padding: 4px 0; }
.chap-title-input:focus { outline: none; border-bottom: 2px solid var(--accent); }
.tb-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chapters-toggle { display: none; }

.editor-scroll { flex: 1; overflow-y: auto; display: flex; justify-content: center; }
.editor { max-width: 720px; width: 100%; padding: 40px 28px 40vh; font-family: var(--reading-font);
  font-size: var(--editor-size); line-height: var(--editor-lh); color: var(--text); outline: none; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor p { margin: 0 0 1em; }
.editor:focus { outline: none; }

.editor-foot { display: flex; align-items: center; gap: 12px; padding: 8px 18px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-soft); background: var(--surface); }
.editor-foot .dot { color: var(--muted); }
.editor-foot .goal { margin-left: auto; color: var(--accent); }
.editor-foot .btn { margin-left: auto; }

/* Focus mode hides everything but the words */
:root[data-focus='on'] .topbar,
:root[data-focus='on'] .chapters,
:root[data-focus='on'] .editor-toolbar,
:root[data-focus='on'] .editor-foot { display: none; }
:root[data-focus='on'] .editor { padding-top: 8vh; }
.focus-exit { display: none; }
:root[data-focus='on'] .focus-exit { display: block; position: fixed; top: 14px; right: 14px; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft); border-radius: 20px;
  padding: 7px 14px; font-size: 13px; cursor: pointer; opacity: .35; transition: opacity .15s; box-shadow: var(--shadow); }
:root[data-focus='on'] .focus-exit:hover { opacity: 1; }

/* Outline */
.outline-head { display: flex; align-items: center; justify-content: space-between; }
.outline h2 { font-family: var(--serif); margin: 4px 0; }
.notes { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.note-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); }
.note-card-head { display: flex; align-items: center; gap: 8px; }
.note-title { flex: 1; border: none; background: transparent; color: var(--text); font-size: 16px; font-weight: 600;
  font-family: var(--serif); padding: 2px 0; }
.note-title:focus { outline: none; }
.note-body, .synopsis { width: 100%; border: none; background: transparent; color: var(--text-soft); resize: none;
  font-family: var(--reading-font); font-size: 15px; line-height: 1.6; padding: 8px 0 0; }
.note-body:focus, .synopsis:focus { outline: none; }
.synopsis-card label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.synopsis { min-height: 44px; }

/* Stats */
.stats h3 { font-family: var(--serif); margin: 26px 0 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.stat-grid.small { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.stat-big { font-family: var(--serif); font-size: 30px; font-weight: 600; margin: 6px 0 2px; }
.stat-sub { font-size: 12.5px; }
.session-log { display: flex; flex-direction: column; }
.session-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; padding: 10px 4px;
  border-bottom: 1px solid var(--border); font-size: 14px; align-items: center; }
.sr-words { color: var(--accent); font-variant-numeric: tabular-nums; }
.sr-dur { font-size: 13px; }
.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 130px; }
.bar-wrap { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.empty { background: var(--border); }
.chart-cap { font-size: 12px; margin-top: 8px; }

/* Settings drawer */
.overlay { position: fixed; inset: 0; background: rgba(20,17,10,.35); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { width: min(400px, 92vw); background: var(--surface); height: 100%; overflow-y: auto; box-shadow: var(--shadow);
  padding: 18px 20px 40px; animation: slidein .18s ease; }
@keyframes slidein { from { transform: translateX(20px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-head h2 { font-family: var(--serif); margin: 0; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.set-row > label { font-size: 15px; }
.segmented { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg { border: none; background: transparent; color: var(--text-soft); padding: 6px 12px; border-radius: 7px; cursor: pointer; font: inherit; font-family: var(--ui-font); font-size: 13px; }
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.slider input { width: 150px; accent-color: var(--accent); }
.switch { width: 46px; height: 26px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); position: relative; cursor: pointer; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--accent); border-color: transparent; }
.switch.on::after { transform: translateX(20px); }
.drawer-section { margin-top: 18px; }
.drawer-foot { font-size: 12.5px; margin-top: 20px; line-height: 1.5; }

/* Mobile */
@media (max-width: 720px) {
  .tb-title { max-width: 34vw; }
  .tabs { margin: 0; }
  .chapters { position: fixed; z-index: 15; top: 52px; bottom: 0; left: 0; width: 78vw; max-width: 300px;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .write-layout.show-chapters .chapters { transform: none; }
  .chapters-toggle { display: inline-flex; }
  .editor { padding: 24px 18px 40vh; }
  .editor-toolbar { padding: 8px 12px; gap: 6px; }
  .container { padding: 16px 14px 80px; }
  .session-row { grid-template-columns: 1fr auto; }
  .sr-dur { display: none; }
}
