/* ============================================================
   曖昧關係模擬器 — Vercel-inspired design system
   canvas-soft body / white cards / ink pills / mesh gradient
   ============================================================ */

:root {
  /* Surfaces */
  --canvas: #ffffff;
  --canvas-soft: #fafafa;
  --canvas-soft-2: #f5f5f5;

  /* Ink & text */
  --primary: #171717;
  --ink: #171717;
  --body: #4d4d4d;
  --mute: #888888;
  --on-primary: #ffffff;

  /* Lines */
  --hairline: #ebebeb;
  --hairline-strong: #a1a1a1;

  /* Accent */
  --link: #0070f3;
  --link-bg-soft: #d3e5ff;
  --cyan: #50e3c2;
  --pink: #ff0080;
  --violet: #7928ca;

  /* Gradient stops */
  --g-develop-start: #007cf0;
  --g-develop-end: #00dfd8;
  --g-preview-start: #7928ca;
  --g-preview-end: #ff0080;
  --g-ship-start: #ff4d4d;
  --g-ship-end: #f9cb28;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 100px;

  /* Spacing */
  --s-xs: 8px;
  --s-sm: 12px;
  --s-md: 16px;
  --s-lg: 24px;
  --s-xl: 32px;

  /* Stacked shadows + inset hairline (Vercel elevation ladder) */
  --sh-1: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  --sh-2: 0px 1px 1px #00000005, 0px 2px 2px #0000000a, inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  --sh-3: 0px 2px 2px #0000000a, 0px 8px 8px -8px #0000000a, inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  --sh-4: 0px 2px 2px #0000000a, 0px 8px 16px -4px #0000000a, inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas-soft);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

.mono-label,
.eyebrow,
.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 var(--s-xs);
  color: var(--mute);
  text-transform: uppercase;
}

/* ---------------- Nav ---------------- */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.nav-inner {
  max-width: 1400px;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--s-lg);
  display: flex;
  align-items: center;
  gap: var(--s-lg);
}
.nav-brand { display: flex; align-items: center; gap: var(--s-xs); }
.nav-logo {
  width: 20px; height: 20px; border-radius: var(--r-xs);
  background: conic-gradient(from 210deg, var(--g-develop-start), var(--g-develop-end),
    var(--g-preview-start), var(--g-preview-end), var(--g-ship-end), var(--g-develop-start));
}
.nav-name { font-weight: 600; letter-spacing: -0.4px; }
.badge-secondary {
  background: var(--canvas-soft-2);
  color: var(--body);
  font-size: 12px;
  line-height: 16px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.nav-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-sm); }
.conn {
  display: flex; align-items: center; gap: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px; color: var(--mute);
}
.dot { width: 7px; height: 7px; border-radius: 9999px; background: var(--hairline-strong); }
.dot.ok { background: #00a86b; }
.dot.bad { background: #ee0000; }

.nav-cta-login {
  font-family: inherit;
  font-size: 14px; font-weight: 500; letter-spacing: -0.28px;
  height: 28px; padding: 0 8px;
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.nav-cta-login:hover { background: var(--canvas-soft-2); }

/* ---------------- Layout ---------------- */
.app {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--s-lg);
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr);
  grid-template-areas: "story rail";
  gap: var(--s-lg);
  align-items: start;
}
.panel-story { grid-area: story; }
.rail {
  grid-area: rail;
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 112px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-lg);
}

.panel {
  background: var(--canvas);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
}

/* ---------------- Story panel ---------------- */
.panel-story {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 64px - 48px);
  overflow: hidden;
}
.story-head {
  position: relative;
  padding: var(--s-xl) var(--s-lg) var(--s-lg);
  overflow: hidden;
  border-bottom: 1px solid var(--hairline);
}
/* mesh gradient — hero-scale atmospheric backdrop only */
.story-head::before {
  content: "";
  position: absolute;
  inset: -60% -20% auto -20%;
  height: 320px;
  background:
    radial-gradient(closest-side at 22% 30%, var(--g-develop-start) 0%, transparent 70%),
    radial-gradient(closest-side at 55% 10%, var(--g-develop-end) 0%, transparent 70%),
    radial-gradient(closest-side at 78% 55%, var(--g-preview-start) 0%, transparent 72%),
    radial-gradient(closest-side at 92% 20%, var(--g-preview-end) 0%, transparent 70%),
    radial-gradient(closest-side at 8% 70%, var(--g-ship-end) 0%, transparent 70%);
  opacity: 0.5;
  filter: blur(6px);
  pointer-events: none;
}
.story-head > * { position: relative; }
.panel-title {
  margin: 0 0 6px;
  font-size: 32px;
  line-height: 40px;
  font-weight: 600;
  letter-spacing: -1.28px;
}
.panel-sub { margin: 0; color: var(--body); font-size: 14px; line-height: 20px; letter-spacing: -0.28px; }
.story-meta {
  position: absolute;
  top: var(--s-xl);
  right: var(--s-lg);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--body);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 4px 10px;
}

.stream {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-lg);
  display: flex;
  flex-direction: column;
  gap: var(--s-md);
  scroll-behavior: smooth;
}

.msg { max-width: 100%; animation: rise 0.28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg-gm { color: var(--ink); font-size: 15px; line-height: 26px; }
.msg-gm .scene {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--mute);
  display: block;
  margin-bottom: 6px;
}
.msg-gm p { margin: 0 0 10px; }
.msg-gm .dialog { color: var(--primary); }
.msg-gm em { color: var(--body); font-style: italic; }

.msg-player {
  align-self: flex-end;
  max-width: 82%;
  background: var(--canvas-soft-2);
  border-radius: var(--r-md);
  box-shadow: var(--sh-1);
  padding: 10px var(--s-sm);
  color: var(--ink);
  font-size: 14px;
  line-height: 22px;
}

/* 系統/通知卡片 — Instagram / KKT 事實條 */
.msg-notify {
  align-self: flex-start;
  display: flex;
  gap: var(--s-sm);
  align-items: flex-start;
  background: var(--canvas);
  border-radius: var(--r-md);
  box-shadow: var(--sh-2);
  padding: 10px var(--s-sm);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 18px;
  color: var(--body);
  max-width: 92%;
}
.msg-notify .tag {
  color: var(--ink);
  font-weight: 400;
}

.msg-error {
  background: #f7d4d6;
  color: #c50000;
  border-radius: var(--r-md);
  padding: 10px var(--s-sm);
  font-size: 13px;
  font-family: "JetBrains Mono", monospace;
}

.cursor::after {
  content: "▍";
  color: var(--mute);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 460px;
  color: var(--mute);
}
.empty-state h3 {
  font-size: 20px; line-height: 28px; font-weight: 600;
  letter-spacing: -0.6px; color: var(--ink); margin: 0 0 6px;
}
.empty-state p { margin: 0; font-size: 14px; line-height: 20px; }

/* ---------------- Composer ---------------- */
.composer {
  border-top: 1px solid var(--hairline);
  padding: var(--s-md) var(--s-lg) var(--s-lg);
  background: var(--canvas);
}
.composer-tools {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--s-xs);
}
.composer-tools .mono-label { color: var(--mute); }
.composer-row { display: flex; gap: var(--s-sm); align-items: flex-end; }

.form-input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  line-height: 22px;
  color: var(--ink);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input::placeholder { color: var(--mute); }
.form-input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 23, 23, 0.08); }

.quick-row { display: flex; flex-wrap: wrap; gap: var(--s-xs); margin-top: var(--s-sm); }

.turnstile-slot { margin-top: var(--s-sm); }
.turnstile-slot:empty { display: none; }

/* ---------------- Buttons ---------------- */
.btn-primary {
  font-family: inherit;
  font-size: 14px; font-weight: 500;
  height: 40px; padding: 0 20px;
  background: var(--primary);
  color: var(--on-primary);
  border: 0;
  border-radius: var(--r-pill);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  font-family: inherit;
  font-size: 14px; font-weight: 500;
  height: 40px; padding: 0 20px;
  background: var(--canvas);
  color: var(--ink);
  border: 0;
  box-shadow: var(--sh-1);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--canvas-soft-2); }
.btn-secondary.sm { height: 32px; padding: 0 16px; font-size: 13px; }

.tab-ghost {
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--canvas);
  border: 0;
  box-shadow: var(--sh-1);
  border-radius: 64px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.tab-ghost:hover { background: var(--canvas-soft-2); }

/* ---------------- State panel ---------------- */
.panel-state, .panel-setup { padding: var(--s-lg); }

.panel-title-sm {
  margin: 0 0 4px;
  font-size: 20px; line-height: 28px; font-weight: 600; letter-spacing: -0.6px;
}

.bars { display: flex; flex-direction: column; gap: var(--s-sm); margin-top: var(--s-md); }
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-head {
  display: flex; justify-content: space-between;
  font-size: 12px; line-height: 16px; color: var(--body);
}
.bar-head .val { font-family: "JetBrains Mono", monospace; color: var(--mute); }
.bar-track {
  height: 6px; border-radius: 9999px; background: var(--canvas-soft-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 9999px; width: 0;
  background: linear-gradient(90deg, var(--g-develop-start), var(--g-preview-end));
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.divider { height: 1px; background: var(--hairline); margin: var(--s-lg) 0; }

.relation-def {
  margin: 0;
  font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -0.96px;
}

.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-xs); }
.notes li {
  font-size: 13px; line-height: 20px; color: var(--body);
  padding-left: 14px; position: relative;
}
.notes li::before {
  content: ""; position: absolute; left: 0; top: 8px;
  width: 5px; height: 5px; border-radius: 9999px; background: var(--hairline-strong);
}
.notes li.empty { color: var(--mute); padding-left: 0; }
.notes li.empty::before { display: none; }

/* ---------------- Setup panel ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-top: var(--s-md); }
.field-label { font-size: 12px; line-height: 16px; color: var(--body); }
select.form-input { height: 40px; padding: 0 12px; appearance: none; cursor: pointer; }

.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 9999px;
  background: var(--canvas-soft-2); outline: none;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 9999px;
  background: var(--primary); cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.setup-actions { display: flex; gap: var(--s-xs); margin-top: var(--s-md); flex-wrap: wrap; }
.setup-actions .btn-primary, .setup-actions .btn-secondary { flex: 1; min-width: 120px; }
.panel-sub.tiny { font-size: 12px; margin-top: var(--s-xs); }

/* ---------------- Toast ---------------- */
.toast-wrap {
  position: fixed; bottom: var(--s-lg); right: var(--s-lg);
  display: flex; flex-direction: column; gap: var(--s-xs); z-index: 60;
}
.toast {
  background: var(--canvas);
  color: var(--ink);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  box-shadow: var(--sh-4);
  animation: rise 0.2s ease both;
}
.toast.err { color: #c50000; }

/* ---------------- Back to top ---------------- */
.to-top {
  position: fixed;
  bottom: var(--s-lg);
  left: var(--s-lg);
  z-index: 50;
  width: 40px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  background: var(--canvas);
  border: 0;
  border-radius: 9999px;
  box-shadow: var(--sh-3);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.to-top:hover { background: var(--canvas-soft-2); }
.to-top:active { transform: scale(0.94); }
.to-top.show { display: flex; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1024px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "story" "rail";
  }
  .panel-story { min-height: 70vh; }
  .rail {
    position: static;
    top: auto;
    max-height: none;
    overflow: visible;
  }
}
@media (max-width: 600px) {
  .app { padding: var(--s-sm); gap: var(--s-sm); }
  .panel-title { font-size: 26px; line-height: 32px; letter-spacing: -1px; }
  .story-meta { position: static; display: inline-block; margin-top: var(--s-xs); }
  .composer-row { flex-direction: column; align-items: stretch; }
  .composer-row .btn-primary { height: 44px; }
  .to-top { bottom: var(--s-sm); left: var(--s-sm); }
  :root { --s-lg: 16px; }
}
