:root {
  --bg: #070b16;
  --panel: rgba(18, 25, 47, 0.78);
  --panel-border: rgba(255, 255, 255, 0.085);
  --text: #eef2ff;
  --muted: #8f9bbd;
  --accent: #9db4ff;
  --accent-2: #ff9fbb;
  --accent-3: #7ef0cf;
  --radius: 22px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 720px at 8% -12%, #1b2752 0%, transparent 62%),
    radial-gradient(900px 620px at 108% 112%, #3a1c3f 0%, transparent 58%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
}

::selection { background: rgba(157, 180, 255, 0.35); }

.orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
}
.orb-a {
  width: 420px; height: 420px;
  left: -160px; top: 8%;
  background: radial-gradient(circle, rgba(90, 120, 255, 0.42), transparent 70%);
  animation: float-a 18s ease-in-out infinite alternate;
}
.orb-b {
  width: 380px; height: 380px;
  right: -140px; bottom: 2%;
  background: radial-gradient(circle, rgba(255, 120, 180, 0.3), transparent 70%);
  animation: float-b 22s ease-in-out infinite alternate;
}
@keyframes float-a { from { transform: translate3d(0, -30px, 0); } to { transform: translate3d(50px, 60px, 0); } }
@keyframes float-b { from { transform: translate3d(0, 20px, 0); } to { transform: translate3d(-60px, -50px, 0); } }

.app {
  position: relative;
  z-index: 1;
  max-width: 1420px;
  margin: 0 auto;
  padding: 26px 24px 34px;
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr);
  grid-template-areas:
    "head head"
    "side stage";
  gap: 18px;
  align-items: start;
}

/* ---------- header ---------- */

.topbar {
  grid-area: head;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 2px 4px 6px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 52px; height: 52px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 25px;
  font-weight: 900;
  color: #0a1024;
  background: linear-gradient(140deg, #b8c8ff 0%, #9db4ff 42%, #d7a8ff 100%);
  box-shadow: 0 12px 30px -10px rgba(140, 165, 255, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.brand-text h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-text h1 span {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.brand-text p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.stats {
  font-size: 13px;
  font-weight: 500;
  color: #cdd7ff;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(157, 180, 255, 0.1);
  border: 1px solid rgba(157, 180, 255, 0.22);
  white-space: nowrap;
}

/* ---------- panels ---------- */

.panel {
  background: linear-gradient(180deg, rgba(24, 32, 60, 0.88) 0%, rgba(12, 17, 34, 0.92) 100%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow:
    0 30px 70px -34px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.055);
  backdrop-filter: blur(16px);
}

.input-panel {
  grid-area: side;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.input-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(6, 10, 22, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.07);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.input-wrap:focus-within {
  border-color: rgba(157, 180, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(157, 180, 255, 0.1);
}

textarea {
  width: 100%;
  min-height: 78px;
  max-height: 200px;
  resize: vertical;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.65;
}
textarea::placeholder { color: rgba(143, 155, 189, 0.72); }

.btn-primary {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 11px;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 800;
  color: #0a1024;
  background: linear-gradient(135deg, #b7c6ff, #d9b4ff);
  box-shadow: 0 10px 22px -10px rgba(160, 180, 255, 0.9);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 14px 26px -10px rgba(160, 180, 255, 1); }
.btn-primary:active { transform: translateY(0); }

kbd {
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(10, 16, 36, 0.18);
  border: 1px solid rgba(10, 16, 36, 0.22);
}

.input-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 38px; height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 2px;
  transition: background 0.2s ease, border-color 0.2s ease;
  flex: none;
}
.switch-thumb {
  display: block;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #8f9bbd;
  transition: transform 0.2s ease, background 0.2s ease;
}
.switch input:checked + .switch-track {
  background: rgba(157, 180, 255, 0.32);
  border-color: rgba(157, 180, 255, 0.5);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(16px);
  background: #dbe4ff;
}
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 4px rgba(157, 180, 255, 0.22); }
.switch-label { font-size: 12.5px; color: #c3cdec; }

.hint { font-size: 11.5px; color: var(--muted); }

.chips-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.chips-title { font-size: 12px; font-weight: 700; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; }
.chips-title b {
  display: inline-block;
  min-width: 22px;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  text-align: center;
  color: #0a1024;
  background: #9db4ff;
  letter-spacing: 0;
}
.chips-actions { display: flex; gap: 4px; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 7px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease;
}
.link-btn:hover { color: #e6ecff; background: rgba(255, 255, 255, 0.06); }
.link-btn.danger:hover { color: #ffb1c4; background: rgba(255, 120, 150, 0.1); }

.chips {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  max-height: 238px;
  min-height: 46px;
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(157, 180, 255, 0.28) transparent;
}
.chips::-webkit-scrollbar { width: 6px; }
.chips::-webkit-scrollbar-thumb { background: rgba(157, 180, 255, 0.28); border-radius: 99px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 6px 9px 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.085);
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.chip:hover {
  background: rgba(157, 180, 255, 0.14);
  border-color: rgba(157, 180, 255, 0.42);
  transform: translateY(-1px);
}
.chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}
.chip-count {
  flex: none;
  font-size: 10.5px;
  font-weight: 800;
  color: #0a1024;
  background: #9db4ff;
  padding: 1px 6px;
  border-radius: 999px;
}
.chip-remove {
  flex: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.34);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1;
  padding: 0 1px;
  cursor: pointer;
  transition: color 0.15s ease;
}
.chip-remove:hover { color: var(--accent-2); }

.chips-empty {
  margin: 6px 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}

.local-note {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 11px;
  color: rgba(143, 155, 189, 0.72);
}
.local-note .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-3);
  box-shadow: 0 0 8px rgba(126, 240, 207, 0.8);
  flex: none;
}

/* ---------- stage ---------- */

.stage-panel {
  grid-area: stage;
  height: clamp(470px, calc(100vh - 206px), 800px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 0;
  flex-wrap: wrap;
}
.stage-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.stage-head p {
  margin: 3px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}
.stage-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
  color: #d7defa;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}
.btn-ghost:hover { background: rgba(157, 180, 255, 0.14); border-color: rgba(157, 180, 255, 0.38); transform: translateY(-1px); }
.btn-ghost.accent { color: #0a1024; background: linear-gradient(135deg, #a9e9d8, #b7c6ff); border-color: transparent; font-weight: 800; }
.btn-ghost.accent:hover { filter: brightness(1.06); background: linear-gradient(135deg, #b6f2e2, #c6d2ff); }

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  background: #070b18;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 30px 80px -50px rgba(120, 150, 255, 0.5);
  isolation: isolate;
}

#cloud {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: manipulation;
}

.tooltip {
  position: absolute;
  left: 0; top: 0;
  transform: translate(-50%, calc(-100% - 12px)) scale(0.94);
  padding: 6px 11px;
  border-radius: 9px;
  background: rgba(12, 18, 38, 0.94);
  border: 1px solid rgba(157, 180, 255, 0.35);
  box-shadow: 0 10px 26px -10px rgba(0, 0, 0, 0.9);
  color: #e9efff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 3;
}
.tooltip.show { opacity: 1; transform: translate(-50%, calc(-100% - 12px)) scale(1); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  z-index: 50;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(18, 25, 47, 0.96);
  border: 1px solid rgba(157, 180, 255, 0.34);
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.9);
  color: #e9efff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(90vw, 460px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */

@media (max-width: 1040px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "head" "side" "stage";
    padding: 20px 16px 28px;
    gap: 14px;
  }
  .stage-panel { height: min(72vh, 640px); }
  .chips { max-height: 180px; }
}

@media (max-width: 560px) {
  .app { padding: 16px 12px 24px; }
  .topbar { gap: 12px; }
  .brand-mark { width: 44px; height: 44px; border-radius: 13px; font-size: 21px; }
  .brand-text h1 { font-size: 21px; }
  .brand-text h1 span { display: none; }
  .brand-text p { font-size: 11.5px; }
  .stats { font-size: 11.5px; padding: 7px 12px; }
  .input-panel { padding: 16px; }
  .stage-panel { height: min(68vh, 560px); padding: 12px; }
  .stage-head h2 { font-size: 14px; }
  .btn-ghost { padding: 7px 10px; font-size: 11.5px; }
  .stage-actions { gap: 6px; }
  .chip-text { max-width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
