:root {
  --bg: #f4f8ff;
  --bg-alt: #eef6f2;
  --text: #14223a;
  --muted: #4e5e79;
  --surface: rgba(255, 255, 255, 0.8);
  --surface-strong: rgba(255, 255, 255, 0.95);
  --border: rgba(20, 34, 58, 0.12);
  --border-strong: rgba(20, 34, 58, 0.2);
  --accent: #1f8f78;
  --accent-strong: #14745f;
  --danger: #be4458;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-lg: 0 18px 40px -24px rgba(21, 52, 120, 0.5);
  --shadow-md: 0 12px 24px -18px rgba(21, 52, 120, 0.35);
  --font-main: "IBM Plex Sans", "Avenir Next", "PingFang SC", "Noto Sans CJK SC",
    "Microsoft YaHei", sans-serif;
  --font-code: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow-x: hidden;
  background: linear-gradient(155deg, var(--bg) 0%, var(--bg-alt) 100%);
  color: var(--text);
  font-family: var(--font-main);
}

.bg-layer {
  position: fixed;
  pointer-events: none;
  inset: auto;
  width: 40vmax;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(16px);
  opacity: 0.18;
  z-index: 0;
}

.bg-layer-a {
  top: -18vmax;
  right: -8vmax;
  background: radial-gradient(circle at center, #47a58f 0%, transparent 72%);
}

.bg-layer-b {
  bottom: -16vmax;
  left: -12vmax;
  background: radial-gradient(circle at center, #2f82b8 0%, transparent 76%);
}

.page {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 18px 60px;
}

.hero {
  padding: 24px 24px 20px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(31, 143, 120, 0.14), rgba(47, 130, 184, 0.12));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.hero-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.5vw, 2.2rem);
  line-height: 1.2;
}

.hero-tip {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.notice {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(190, 68, 88, 0.35);
  background: rgba(255, 245, 247, 0.9);
  color: #7f2230;
}

.notice p {
  margin: 0;
  line-height: 1.5;
}

.manual-load-btn {
  display: inline-flex;
  margin-top: 10px;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid rgba(190, 68, 88, 0.35);
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.85);
}

/* ── Cards grid ── */

#phasesRoot {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

/* ── Cards with step badge ── */

.card {
  position: relative;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateY(8px);
  opacity: 0;
  animation: enter 340ms ease forwards;
  animation-delay: var(--delay, 0ms);
}

body.no-enter-anim .card {
  animation: none !important;
  transform: none !important;
  opacity: 1 !important;
}

@keyframes enter {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.card-head {
  min-height: 0;
}

.card-head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 1.04rem;
  line-height: 1.32;
  flex: 1;
}

.card-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.card-icon-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #fff;
  color: #1f3457;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.icon-btn:hover {
  background: rgba(47, 130, 184, 0.08);
  border-color: rgba(47, 130, 184, 0.28);
}

.clear-input-btn:hover {
  background: rgba(47, 130, 184, 0.12);
  border-color: rgba(47, 130, 184, 0.34);
  color: #1e6089;
}

.delete-btn {
  color: #9d3040;
  border-color: rgba(190, 68, 88, 0.32);
}

.delete-btn:hover {
  background: rgba(190, 68, 88, 0.12);
  border-color: rgba(190, 68, 88, 0.38);
}

.card-input {
  min-height: 125px;
  resize: vertical;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 0.94rem;
  line-height: 1.5;
  font-family: var(--font-main);
  color: var(--text);
  background: var(--surface-strong);
  outline: none;
}

.card-input:focus {
  border-color: rgba(47, 130, 184, 0.5);
  box-shadow: 0 0 0 3px rgba(47, 130, 184, 0.18);
}

.card-actions {
  display: flex;
  gap: 8px;
}

.card-actions button {
  flex: 1;
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  transition: transform 80ms ease, filter 140ms ease, box-shadow 140ms ease;
}

.card-actions button:active {
  transform: translateY(1px);
}

.copy-btn {
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 10px 18px -12px rgba(31, 143, 120, 0.8);
}

.copy-btn:hover {
  filter: brightness(1.04);
}

.phase-select-btn {
  background: rgba(47, 130, 184, 0.1);
  color: #1e6089;
  border-color: rgba(47, 130, 184, 0.24);
}

.phase-select-btn:hover {
  background: rgba(47, 130, 184, 0.16);
}

.card-actions button.secondary {
  background: rgba(47, 130, 184, 0.1);
  color: #1e6089;
  border-color: rgba(47, 130, 184, 0.24);
}

.card-actions button.secondary:hover {
  background: rgba(47, 130, 184, 0.16);
}

/* Phase move popup menu */
.phase-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 8px;
  z-index: 10;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 140px;
}

.phase-menu .phase-option {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.86rem;
  text-align: left;
  color: var(--text);
  border-radius: 0;
}

.phase-menu .phase-option:hover {
  background: rgba(47, 130, 184, 0.08);
}

.edit-panel {
  padding: 10px;
  border-radius: 10px;
  border: 1px dashed var(--border-strong);
  background: rgba(255, 255, 255, 0.72);
}

.edit-panel label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.edit-panel label + label {
  margin-top: 8px;
}

.edit-panel input,
.edit-panel textarea {
  width: 100%;
  margin-top: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 10px;
  font-size: 0.9rem;
  color: var(--text);
  font-family: var(--font-main);
}

.edit-panel textarea {
  min-height: 120px;
  resize: vertical;
}

.edit-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.edit-actions button {
  flex: 1;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 600;
  cursor: pointer;
}

.save-edit-btn {
  background: rgba(31, 143, 120, 0.1) !important;
  border-color: rgba(31, 143, 120, 0.28) !important;
  color: #166854;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-actions button {
  width: auto;
  white-space: nowrap;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  color: #1f3457;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.hero-actions button:hover {
  background: rgba(255, 255, 255, 0.98);
  border-color: var(--border-strong);
}

.lang-toggle-btn {
  width: 48px !important;
  min-width: 48px !important;
  padding: 0 !important;
  text-align: center;
  font-weight: 700 !important;
  letter-spacing: 0.02em;
}

/* ── Pool ── */

.pool-zone {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.pool-zone > summary {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  cursor: pointer;
  font-weight: 700;
}

.pool-zone > summary::-webkit-details-marker {
  display: none;
}

.pool-zone > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  transition: transform 120ms ease;
}

.pool-zone[open] > summary::before {
  transform: rotate(90deg);
}

.pool-count {
  font-size: 0.82rem;
  color: var(--muted);
}

.cards-pool {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

/* ── Trash ── */

.zone {
  margin-top: 32px;
}

.trash-zone {
  margin-top: 32px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.trash-zone > summary {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  cursor: pointer;
  font-weight: 700;
}

.trash-zone > summary::-webkit-details-marker {
  display: none;
}

.trash-zone > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  transition: transform 120ms ease;
}

.trash-zone[open] > summary::before {
  transform: rotate(90deg);
}

.trash-zone .clear-trash-btn {
  margin-left: auto;
}

.cards-trash {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.clear-trash-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid rgba(190, 68, 88, 0.32);
  background: rgba(190, 68, 88, 0.1);
  color: #9d3040;
  font-weight: 600;
  cursor: pointer;
}

/* ── Modal ── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(8, 16, 28, 0.45);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  box-shadow: var(--shadow-lg);
}

.modal-panel h3 {
  margin: 0 0 8px;
  font-size: 1.02rem;
}

.meta-template-panel {
  margin: 2px 0 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.7);
}

.meta-template-panel > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

.meta-template-panel > summary::-webkit-details-marker {
  display: none;
}

.meta-template-panel > summary::before {
  content: "▸";
  margin-right: 8px;
  transition: transform 120ms ease;
}

.meta-template-panel[open] > summary::before {
  transform: rotate(90deg);
}

.meta-status {
  font-size: 0.8rem;
  color: var(--muted);
}

.meta-status.success {
  color: var(--accent-strong);
}

.meta-status.error {
  color: var(--danger);
}

.modal-panel label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.modal-panel label + label {
  margin-top: 8px;
}

.modal-panel input,
.modal-panel textarea {
  width: 100%;
  margin-top: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 10px;
  font-size: 0.9rem;
  color: var(--text);
  font-family: var(--font-main);
}

.modal-panel textarea {
  min-height: 120px;
  resize: vertical;
}

#metaTemplateInput {
  margin-top: 8px;
  min-height: 280px;
  font-family: var(--font-code);
  font-size: 0.8rem;
  line-height: 1.5;
  background: rgba(245, 248, 255, 0.95);
}

#metaNeedInput {
  min-height: 110px;
}

.add-form-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.add-form-actions button {
  flex: 1;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 600;
  cursor: pointer;
}

.create-btn {
  background: rgba(31, 143, 120, 0.1) !important;
  border-color: rgba(31, 143, 120, 0.3) !important;
  color: #166854;
}

.add-status {
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.add-status.error {
  color: var(--danger);
}

.add-status.success {
  color: var(--accent-strong);
}

.copy-status {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.copy-status.success {
  color: var(--accent-strong);
}

.copy-status.error {
  color: var(--danger);
}

.prompt-preview {
  margin-top: 2px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.prompt-preview summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.83rem;
}

.usage-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.prompt-preview pre {
  margin: 8px 0 0;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.8rem;
  line-height: 1.5;
  padding: 10px;
  border-radius: 10px;
  background: rgba(15, 26, 44, 0.92);
  color: #dce9ff;
  font-family: var(--font-code);
}

.hidden {
  display: none !important;
}

.empty-tip {
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── Drag and drop ── */

.card.draggable {
  cursor: grab;
}

.card.dragging {
  opacity: 0.48;
}

.card.drag-over {
  outline: 2px dashed rgba(31, 143, 120, 0.5);
  outline-offset: 2px;
}

.phase.drag-phase-active {
  background: rgba(31, 143, 120, 0.03);
  border-radius: var(--radius-lg);
}

/* ── Trash drop target ── */

.trash-zone.drop-target {
  outline: 2px dashed rgba(190, 68, 88, 0.5);
  outline-offset: 2px;
  border-radius: var(--radius-lg);
}

/* ── Footer ── */

.page-footer {
  margin-top: 32px;
  padding: 10px 2px 2px;
  color: var(--muted);
  font-size: 0.85rem;
}

.page-footer a {
  color: #1e6089;
  text-decoration: none;
  border-bottom: 1px solid rgba(30, 96, 137, 0.28);
}

.page-footer a:hover {
  border-bottom-color: rgba(30, 96, 137, 0.55);
}

/* ── Responsive ── */

@media (max-width: 1180px) {
  #phasesRoot,
  .cards-pool {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  #phasesRoot,
  .cards-pool {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .page {
    padding: 22px 12px 48px;
  }

  .hero {
    padding: 18px 16px;
  }

  .hero-head {
    align-items: flex-start;
    flex-direction: column;
  }

  #phasesRoot,
  .cards-pool {
    grid-template-columns: 1fr;
  }
}
