:root {
  --bg: #14110f;
  --bg-raised: #1e1a17;
  --bg-input: #100d0b;
  --line: #332c26;
  --text: #f0e9e1;
  --muted: #9b8f84;
  --accent: #c9713f;
  --accent-dim: #8a4a26;
  --danger: #a83a3a;
  --ok: #6d8f5a;
  --tabbar: 62px;
}

* { box-sizing: border-box; }

/* Rules below set display on .assist-menu, .tabs, .row etc, which would
   otherwise beat the UA stylesheet's [hidden] { display: none }. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

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

/* ------------------------------------------------------------- login */

.screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.brand {
  font-size: 30px; margin: 0; letter-spacing: -0.5px;
  font-family: Georgia, "Times New Roman", serif;
}
.brand-sub { color: var(--muted); margin: 4px 0 28px; font-size: 14px; }
#login-form { display: grid; gap: 10px; }

/* ------------------------------------------------------------ layout */

#app { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--line);
}
.progress { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width .3s ease;
}
.progress-text {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); margin-top: 6px;
}
.save-state { transition: opacity .2s; }
.save-state.saving { color: var(--accent); }
.save-state.saved { color: var(--ok); }

main { padding: 16px; max-width: 720px; margin: 0 auto; }

/* -------------------------------------------------------------- card */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.card-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  background: var(--accent-dim); color: #fff;
  padding: 4px 9px; border-radius: 999px;
}
.chip.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.card h2 {
  font-size: 21px; line-height: 1.3; margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif; font-weight: 600;
}
.help { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.help.center { text-align: center; }

/* Context + tips panels inside the focus card */

.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-input);
  margin-bottom: 10px;
  overflow: hidden;
}
.panel > summary {
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before {
  content: '▸';
  font-size: 11px;
  transition: transform .15s;
  flex: none;
}
.panel[open] > summary::before { transform: rotate(90deg); }
/* Capped so opening a panel never buries the textarea. */
.panel-body {
  padding: 0 12px 12px;
  max-height: 45vh;
  overflow-y: auto;
}

.ctx-entry { margin-bottom: 10px; }
.ctx-entry:last-child { margin-bottom: 0; }
.ctx-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin-bottom: 3px;
}
.ctx-text {
  font-size: 14px;
  white-space: pre-wrap;
  color: var(--text);
  opacity: .88;
}
.tips-body { font-size: 14px; white-space: pre-wrap; opacity: .9; }

.status-strip {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}
.status-strip .linkbtn { font-size: 13px; }

.draft-flag {
  font-size: 13px; color: var(--accent);
  border-left: 2px solid var(--accent); padding-left: 10px; margin-bottom: 12px;
}

textarea, input[type="password"], input[type="text"], select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  resize: vertical;
}
textarea:focus, input:focus, select:focus {
  outline: none; border-color: var(--accent);
}

/* ------------------------------------------------------------ buttons */

.btn {
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  min-height: 46px;
  cursor: pointer;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.wide { width: 100%; }
.btn.grow { flex: 1; }
.btn.tiny { min-height: 36px; padding: 7px 11px; font-size: 13px; border-radius: 8px; }

.row { display: flex; gap: 8px; margin-top: 14px; }

.linkbtn {
  background: none; border: 0; color: var(--muted);
  padding: 10px 4px; cursor: pointer; font-size: 14px;
}
.card-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px;
}
.counter { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------- assist */

.assist-menu { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.assist {
  margin-top: 14px;
  border: 1px dashed var(--accent-dim);
  border-radius: 10px;
  padding: 12px;
  background: rgba(201, 113, 63, .06);
}
.assist-out { white-space: pre-wrap; font-size: 14.5px; min-height: 22px; }
.assist-out.thinking::after { content: '▊'; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.assist-actions { display: flex; gap: 8px; margin-top: 10px; }

/* -------------------------------------------------------------- board */

.section { margin-bottom: 22px; }
.section > h2 {
  font-size: 15px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); margin: 0 0 4px;
}
.section > .help { margin-bottom: 10px; font-size: 13px; }

details.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--bg-raised);
  overflow: hidden;
}
details.item > summary {
  padding: 13px 14px;
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 10px;
  font-size: 15px;
}
details.item > summary::-webkit-details-marker { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.filled { background: var(--ok); }
.dot.draft { background: var(--accent); }
.item-body { padding: 0 14px 14px; }
.item-body .qtext { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.summary-label { flex: 1; }
.group-head {
  font-size: 13px; color: var(--accent); margin: 14px 0 6px;
  text-transform: uppercase; letter-spacing: .08em;
}

/* ----------------------------------------------------------- timeline */

.beat {
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-raised); padding: 12px; margin-bottom: 8px;
}
.beat-top { display: flex; align-items: center; gap: 8px; }
.beat-title { flex: 1; font-weight: 600; }
.beat-act { font-size: 11px; color: var(--muted); }
.beat p { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.beat-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.tag.thread { border-color: var(--accent-dim); color: var(--accent); }
.arrows { display: flex; gap: 4px; }
.arrows button {
  background: var(--bg-input); border: 1px solid var(--line); color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
}

/* ------------------------------------------------------------- export */

.panel-head h2 { margin: 0 0 4px; font-size: 20px; }
.export-grid { display: grid; gap: 8px; margin-bottom: 14px; }
#export-out { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0 14px; }
#view-export .btn.wide { margin-bottom: 8px; }

.done-card { text-align: center; padding: 40px 20px; }
.done-card h2 { font-family: Georgia, serif; }

/* --------------------------------------------------------------- tabs */

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex;
  background: var(--bg-raised);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0; height: var(--tabbar);
  justify-content: center;
}
.tab span { font-size: 18px; line-height: 1; }
.tab.active { color: var(--accent); }

/* -------------------------------------------------------------- misc */

.error { color: var(--danger); font-size: 14px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom));
  background: var(--bg-raised); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 40;
}

@media (min-width: 700px) {
  .card h2 { font-size: 24px; }
  main { padding: 24px 16px; }
}
