/* ============================================================
   StoryForge Design System v3 — "Cupertino"
   Apple Human Interface Guidelines (Dark Mode) compliant
   - SF system font stack, HIG dark semantic colors
   - iOS controls (switch / segmented control / pill buttons)
   - macOS sidebar with vibrancy, iMessage chat bubbles
   ============================================================ */

:root {
  /* HIG dark semantic colors */
  --bg: #000000;                          /* systemBackground */
  --panel: #1c1c1e;                       /* secondarySystemBackground */
  --panel2: #2c2c2e;                      /* tertiarySystemBackground */
  --panel3: #3a3a3c;                      /* quaternary fill */
  --fill: rgba(120,120,128,.24);          /* systemFill */
  --fill2: rgba(120,120,128,.32);
  --line: rgba(84,84,88,.42);             /* separator */
  --line2: rgba(84,84,88,.65);            /* opaqueSeparator */
  --text-hi: #ffffff;                     /* label */
  --text-mid: rgba(235,235,245,.6);       /* secondaryLabel */
  --text-low: rgba(235,235,245,.3);       /* tertiaryLabel */
  --accent: #0a84ff;                      /* systemBlue */
  --accent-hover: #409cff;
  --accent-dim: rgba(10,132,255,.16);
  --accent-2: #64d2ff;
  --green: #30d158;                       /* systemGreen */
  --red: #ff453a;                         /* systemRed */
  --orange: #ff9f0a;                      /* systemOrange */
  --radius: 12px;
  --radius-lg: 16px;
  --ease: cubic-bezier(.25,.1,.25,1);     /* Apple standard curve */
  --ease-spring: cubic-bezier(.32,1.25,.5,1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-mid);
  font-size: 15px;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(10,132,255,.35); }

/* scrollbar — thin, unobtrusive */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(120,120,128,.35); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120,120,128,.55); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- inputs ---------- */
input, textarea, select {
  width: 100%;
  background: var(--panel);
  border: 0.5px solid var(--line2);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  color: var(--text-hi);
  outline: none;
  font-family: inherit;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
  -webkit-appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--text-low); }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px rgba(10,132,255,.25);
}
input:disabled, textarea:disabled { opacity: .45; }
textarea { resize: vertical; line-height: 1.6; }
label { font-size: 13px; color: var(--text-mid); }

/* ---------- buttons (iOS filled / gray / tinted) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border-radius: 980px;                  /* Apple pill */
  font-size: 15px; font-weight: 590;
  cursor: pointer; border: none;
  background: var(--fill); color: var(--text-hi);
  transition: transform .15s var(--ease), background .2s var(--ease), opacity .2s var(--ease), filter .2s var(--ease);
  white-space: nowrap; user-select: none;
  font-family: inherit; letter-spacing: -0.01em;
}
.btn:hover { background: var(--fill2); }
.btn:active { transform: scale(.965); }
.btn:disabled { opacity: .35; pointer-events: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--fill); color: var(--accent); }
.btn-ghost:hover { background: var(--fill2); }
.btn-danger { background: rgba(255,69,58,.16); color: var(--red); }
.btn-danger:hover { background: rgba(255,69,58,.26); }
.btn-sm { padding: 6px 13px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; font-weight: 600; }

/* ---------- cards (inset grouped) ---------- */
.card {
  background: var(--panel);
  border: 0.5px solid var(--line);
  border-radius: var(--radius-lg);
  transition: border-color .25s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease);
}
.card-hover:hover {
  border-color: var(--line2);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.glass {
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

/* ---------- shell / sidebar (macOS vibrancy) ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: rgba(28,28,30,.62);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border-right: 0.5px solid var(--line);
  z-index: 40;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 14px;
}
.sidebar-brand span { font-size: 16px; font-weight: 700; color: var(--text-hi); letter-spacing: -0.02em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(180deg, #409cff, #0a84ff);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px;
  box-shadow: 0 1px 4px rgba(10,132,255,.4), inset 0 0.5px 0 rgba(255,255,255,.35);
}
.nav-section {
  padding: 16px 18px 6px;
  font-size: 11px; font-weight: 600; color: var(--text-low);
  letter-spacing: .04em;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  margin: 1px 10px; padding: 7px 10px;
  border-radius: 8px;
  font-size: 13.5px; font-weight: 500;
  color: var(--text-mid);
  background: none; border: none; cursor: pointer;
  width: calc(100% - 20px); text-align: left;
  transition: background .18s var(--ease), color .18s var(--ease);
  text-decoration: none; font-family: inherit; position: relative;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; color: var(--accent); }
.nav-item:hover { background: var(--fill); color: var(--text-hi); }
.nav-item.active { background: var(--fill2); color: var(--text-hi); font-weight: 600; }
.nav-item.active::before { content: none; }
.sidebar-footer {
  margin-top: auto; padding: 12px;
  border-top: 0.5px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  z-index: 39; opacity: 0; transition: opacity .25s var(--ease);
}
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--line);
}
.hamburger {
  display: none; width: 34px; height: 34px;
  border-radius: 8px; border: none;
  background: var(--fill); color: var(--text-hi);
  cursor: pointer; align-items: center; justify-content: center;
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .32s var(--ease-spring);
    background: rgba(28,28,30,.92);
    box-shadow: 8px 0 40px rgba(0,0,0,.5);
  }
  .shell.drawer-open .sidebar { transform: translateX(0); }
  .shell.drawer-open .sidebar-backdrop { display: block; opacity: 1; }
  .hamburger { display: inline-flex; }
}

/* ---------- animations ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn .4s var(--ease) both; }
.stagger > * { animation: fadeIn .45s var(--ease) both; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .06s; }
.stagger > *:nth-child(3) { animation-delay: .1s; }
.stagger > *:nth-child(4) { animation-delay: .14s; }
.stagger > *:nth-child(5) { animation-delay: .18s; }
.stagger > *:nth-child(6) { animation-delay: .22s; }

/* ---------- tabs (Safari-style underline) ---------- */
.tab-btn {
  position: relative; padding: 11px 2px; margin-right: 18px;
  background: none; border: none; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--text-mid);
  white-space: nowrap; font-family: inherit;
  transition: color .2s var(--ease);
}
.tab-btn:hover { color: var(--text-hi); }
.tab-btn.active { color: var(--text-hi); font-weight: 600; }
.tab-btn.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -0.5px;
  height: 2px; border-radius: 1px; background: var(--accent);
}
.tab-btn .req { color: var(--red); margin-right: 1px; }
.tab-btn .warn-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--orange); margin-left: 4px; vertical-align: 2px;
}

/* ---------- segmented control (iOS) ---------- */
.seg {
  display: inline-flex;
  background: var(--fill);
  border-radius: 9px; padding: 2px; gap: 2px;
  border: none;
}
.seg button {
  padding: 6px 15px; border-radius: 7px;
  font-size: 13px; font-weight: 500;
  color: var(--text-hi); background: none; border: none; cursor: pointer;
  transition: background .2s var(--ease), box-shadow .2s var(--ease);
  font-family: inherit;
}
.seg button:hover { color: var(--text-hi); }
.seg button.on, .seg button.active {
  background: var(--panel3);
  color: var(--text-hi); font-weight: 600;
  box-shadow: 0 3px 8px rgba(0,0,0,.25), 0 1px 1px rgba(0,0,0,.16), inset 0 0.5px 0 rgba(255,255,255,.12);
}

/* ---------- chips (tinted capsules) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 13px; border-radius: 980px;
  font-size: 13px; font-weight: 500;
  background: var(--fill); border: none; color: var(--text-mid);
  cursor: pointer; transition: background .18s var(--ease), color .18s var(--ease);
  font-family: inherit;
}
.chip:hover { background: var(--fill2); color: var(--text-hi); }
.chip.on, .chip.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(10,132,255,.4);
}

/* ---------- toggle (iOS switch) ---------- */
.toggle {
  position: relative; width: 46px; height: 28px; border-radius: 14px;
  background: var(--fill2); cursor: pointer; flex-shrink: 0;
  transition: background .25s var(--ease);
  border: none;
}
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 24px; height: 24px; border-radius: 50%; background: #fff;
  transition: left .25s var(--ease-spring);
  box-shadow: 0 2px 6px rgba(0,0,0,.35), 0 0.5px 1px rgba(0,0,0,.2);
}
.toggle.on, .toggle.active { background: var(--green); }
.toggle.on::after, .toggle.active::after { left: 20px; }

/* ---------- modal (iOS sheet) ---------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeBg .25s var(--ease) both;
}
@keyframes fadeBg { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel);
  border: 0.5px solid var(--line2);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  width: 100%; max-width: 560px; max-height: 88vh;
  overflow-y: auto;
  animation: modalIn .35s var(--ease-spring) both;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.94) translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- toast ---------- */
.toast-anim { animation: toastIn .35s var(--ease-spring) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.95); } to { opacity: 1; transform: none; } }

/* ---------- pill (status) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 980px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0;
}
.pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .9; }

/* ---------- stat cards ---------- */
.stat-card {
  background: var(--panel);
  border: 0.5px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative; overflow: hidden;
}
.stat-label { font-size: 12px; font-weight: 500; color: var(--text-mid); margin-bottom: 6px; }
.stat-value {
  font-size: 30px; font-weight: 700; color: var(--text-hi);
  letter-spacing: -0.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* ---------- tables (inset grouped list) ---------- */
.table-wrap {
  background: var(--panel);
  border: 0.5px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table.sf { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.sf th {
  text-align: left; padding: 11px 16px;
  font-size: 11.5px; font-weight: 600; color: var(--text-low);
  letter-spacing: .03em;
  border-bottom: 0.5px solid var(--line2);
  background: rgba(120,120,128,.08);
}
table.sf td {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--line);
  color: var(--text-mid); vertical-align: middle;
}
table.sf tr:last-child td { border-bottom: none; }
table.sf tbody tr { transition: background .15s var(--ease); }
table.sf tbody tr:hover { background: rgba(120,120,128,.08); }

/* ---------- login ---------- */
.login-bg {
  position: fixed; inset: 0; overflow: hidden;
  background:
    radial-gradient(ellipse 70% 55% at 50% -10%, rgba(10,132,255,.16), transparent 60%),
    radial-gradient(ellipse 55% 45% at 85% 100%, rgba(100,210,255,.08), transparent 60%),
    #000;
}
.login-orb {
  position: absolute; border-radius: 50%;
  filter: blur(90px); opacity: .5;
  animation: drift 22s ease-in-out infinite alternate;
}
.orb-1 { width: 420px; height: 420px; background: rgba(10,132,255,.28); top: -140px; left: -100px; }
.orb-2 { width: 360px; height: 360px; background: rgba(100,210,255,.16); bottom: -120px; right: -80px; animation-delay: -9s; }
@keyframes drift {
  from { transform: translate(0,0) scale(1); }
  to { transform: translate(50px,36px) scale(1.12); }
}

/* ---------- spinner ---------- */
.spinner {
  display: inline-block; width: 22px; height: 22px;
  border: 2.5px solid var(--fill2); border-top-color: var(--text-mid);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- dashed empty state ---------- */
.dashed-box {
  border: 1.5px dashed var(--line2);
  border-radius: var(--radius-lg);
  color: var(--text-mid);
  cursor: pointer;
  transition: border-color .2s var(--ease), background .2s var(--ease), color .2s var(--ease);
}
.dashed-box:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ---------- chat bubbles (iMessage) ---------- */
.chat-bubble-user {
  background: var(--accent);
  color: #fff;
  border-radius: 18px;
  border-bottom-right-radius: 5px;
  line-height: 1.5;
  animation: msgIn .3s var(--ease-spring) both;
}
.chat-bubble-ai {
  background: var(--panel2);
  color: var(--text-hi);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  line-height: 1.75;
  animation: msgIn .3s var(--ease-spring) both;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
.msg-in { animation: msgIn .3s var(--ease-spring) both; }
.narration-text { color: var(--text-mid); font-style: normal; }

.typing-dots span {
  display: inline-block; width: 7px; height: 7px; margin: 0 1.5px;
  border-radius: 50%; background: var(--text-low);
  animation: typing 1.3s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes typing { 0%, 60%, 100% { transform: none; opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- infobox bar ---------- */
.infobox-bar {
  background: rgba(28,28,30,.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  line-height: 1.9;
}

/* ---------- model picker ---------- */
.model-option {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 0.5px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  transition: background .18s var(--ease), border-color .18s var(--ease);
  font-family: inherit; width: 100%;
}
.model-option:hover { background: var(--panel2); }
.model-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(10,132,255,.14);
}
.provider-badge {
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; flex-shrink: 0;
  box-shadow: inset 0 0.5px 0 rgba(255,255,255,.3);
}

/* ---------- beat cards (novel editor) ---------- */
.beat-card {
  background: var(--panel);
  border: 0.5px solid var(--line);
  border-left-width: 3px;
  border-radius: 12px;
  transition: border-color .2s var(--ease);
}
.b-narration { border-left-color: #98989d; }
.b-dialogue { border-left-color: var(--accent); }
.b-still { border-left-color: var(--green); }
.b-choice { border-left-color: var(--orange); }
.b-user { border-left-color: #bf5af2; }

/* ---------- novel player (9:16 stage) ---------- */
.novel-stage {
  position: relative;
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  max-width: 480px; max-height: 100vh;
  overflow: hidden; background: #000;
  border-radius: 0;
}
@media (min-width: 500px) { .novel-stage { border-radius: 18px; } }
.novel-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transition: background-image .5s var(--ease);
}
.novel-dim {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.12) 0%, transparent 35%, rgba(0,0,0,.78) 100%);
}
.novel-textbox {
  position: absolute; left: 12px; right: 12px; bottom: 40px;
  min-height: 110px;
}
.novel-name { color: var(--accent-2); }
.novel-text { color: #fff; }
.novel-choice { transition: background .2s var(--ease); }
.novel-tap { animation: tapPulse 1.8s ease-in-out infinite; }
@keyframes tapPulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }

/* ---------- utility ---------- */
.line-clamp-2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- code / prompt inspector ---------- */
.code-block {
  background: #0d0d0f;
  border: 0.5px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.7;
  color: rgba(235,235,245,.75);
  white-space: pre-wrap; word-break: break-word;
  max-height: 420px; overflow-y: auto;
}
details.disclosure > summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0;
  font-size: 13px; font-weight: 600; color: var(--accent);
  user-select: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before {
  content: '\f054'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
  font-size: 10px; transition: transform .25s var(--ease);
}
details.disclosure[open] > summary::before { transform: rotate(90deg); }

/* ---- Inset grouped list (iOS Settings style) ---- */
.inset-group {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.ig-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--line);
}
.ig-row:last-child { border-bottom: none; }
.ig-label {
  font-size: 12px; font-weight: 600; color: var(--text-mid);
  flex-shrink: 0; min-width: 96px;
}
.ig-value {
  font-size: 12px; color: var(--text-hi); text-align: right; line-height: 1.55;
}
.ig-code {
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  font-size: 10.5px; color: var(--accent2);
  background: rgba(100,210,255,.1); border-radius: 5px; padding: 1.5px 6px;
}

/* ---- Numbered deploy steps ---- */
.step-num {
  width: 22px; height: 22px; flex-shrink: 0; margin-top: 1px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
}

/* ---- Context pipeline diagram ---- */
.pipeline {
  display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap;
}
.pl-node {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 8px 12px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  font-size: 11px; font-weight: 600; color: var(--text-hi); text-align: center;
}
.pl-node small { font-size: 9px; font-weight: 500; color: var(--text-low); }
.pl-node.pl-accent {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.pl-arrow { align-self: center; font-size: 9px; color: var(--text-low); }

@media (max-width: 640px) {
  .ig-row { flex-direction: column; gap: 3px; align-items: flex-start; }
  .ig-value { text-align: left; }
}
