:root {
  --bg: #0f1117;
  --bg2: #161a23;
  --bg3: #1d2330;
  --border: #2a3142;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #7c9cff;
  --accent2: #5f7fe8;
  --danger: #e5637a;
  --warn: #e8b45f;
  --ok: #58c98b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; }

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: filter .15s;
}
button:hover { filter: brightness(1.2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
button.warn { background: var(--warn); border-color: var(--warn); color: #222; }
button.danger { background: transparent; border-color: var(--border); color: var(--danger); }
button.ghost { background: transparent; }

input, select, textarea {
  font: inherit;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.7; }

/* ── 登入 ── */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 30% -10%, #1b2233 0%, var(--bg) 60%);
}
.card {
  width: min(420px, 92vw);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }
.card input, .card button { width: 100%; }

/* ── 主版面 ── */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 270px; min-width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head { padding: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-head h2 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; }
#story-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
#story-list li {
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; margin-bottom: 2px;
}
#story-list li:hover { background: var(--bg3); }
#story-list li.active { background: #24304a; }
#story-list .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#story-list .m { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.editor { flex: 1; display: flex; flex-direction: column; padding: 14px; gap: 10px; overflow: hidden; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.title-input { flex: 2; min-width: 200px; font-weight: 700; font-size: 16px; }
.toolbar select, .toolbar input:not(.title-input) { flex: 1; min-width: 140px; }

#idea { min-height: 64px; }
#story { flex: 1; min-height: 200px; font-size: 16px; }

#thinking-box {
  border: 1px dashed var(--border); border-radius: 8px;
  padding: 8px 10px; max-height: 110px; overflow-y: auto;
  font-size: 12px; color: var(--muted); line-height: 1.5;
}
#thinking-box label { font-weight: 600; display: block; margin-bottom: 4px; }

.direction-row { display: flex; gap: 8px; flex-wrap: wrap; }
.direction-row input { flex: 1; min-width: 220px; }

.statusbar { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 2px 4px; }
#status.busy { color: var(--accent); }
#status.err { color: var(--danger); }
#status.ok { color: var(--ok); }

@media (max-width: 760px) {
  .app { flex-direction: column; height: auto; }
  .sidebar { width: 100%; max-height: 34vh; border-right: none; border-bottom: 1px solid var(--border); }
  .editor { min-height: 60vh; }
}