:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft JhengHei UI", system-ui, sans-serif;
  --academy-ink: #241b2e;
  --academy-muted: #6a5b73;
  --academy-parchment: rgba(255, 250, 239, 0.9);
  --academy-glass: rgba(255, 248, 239, 0.74);
  --academy-cream: #fff8ec;
  --academy-moss: #5f7a52;
  --academy-sage: #a8c395;
  --academy-lilac: #b79bd7;
  --academy-violet: #704c8c;
  --academy-rose: #c9829a;
  --academy-gold: #d8ac55;
  --academy-line: rgba(91, 65, 68, 0.18);
  --academy-shadow: 0 24px 70px rgba(32, 23, 42, 0.24);
}

* {
  scrollbar-color: rgba(112, 76, 140, 0.48) rgba(255, 248, 239, 0.4);
}

html {
  min-height: 100%;
  background: #1f1730;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--academy-ink);
  background:
    linear-gradient(180deg, rgba(24, 17, 38, 0.34), rgba(42, 29, 41, 0.58)),
    radial-gradient(circle at 13% 12%, rgba(255, 222, 151, 0.34), transparent 25%),
    url("./fairy-academy-courtyard.png") center / cover fixed no-repeat;
}

body::before,
body::after {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
}

body::before {
  background:
    radial-gradient(circle at 18% 22%, rgba(250, 220, 147, 0.55) 0 2px, transparent 3px),
    radial-gradient(circle at 77% 18%, rgba(209, 181, 239, 0.58) 0 2px, transparent 3px),
    radial-gradient(circle at 62% 78%, rgba(255, 239, 188, 0.45) 0 2px, transparent 3px),
    radial-gradient(circle at 28% 68%, rgba(174, 212, 162, 0.44) 0 1px, transparent 3px);
  background-size: 260px 220px, 320px 260px, 290px 240px, 230px 190px;
  animation: academyFloat 14s ease-in-out infinite alternate;
}

body::after {
  background:
    linear-gradient(90deg, rgba(24, 17, 38, 0.2), transparent 24%, transparent 70%, rgba(24, 17, 38, 0.3)),
    linear-gradient(180deg, transparent 48%, rgba(24, 17, 38, 0.3));
}

.app-shell {
  width: min(1480px, calc(100% - 34px));
  padding: 26px 0 38px;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  min-height: 118px;
  margin-bottom: 18px;
  border: 1px solid rgba(255, 248, 232, 0.5);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 248, 239, 0.84), rgba(239, 226, 247, 0.64)),
    linear-gradient(90deg, rgba(112, 76, 140, 0.12), rgba(95, 122, 82, 0.08));
  box-shadow: var(--academy-shadow);
  padding: 20px 24px;
  backdrop-filter: blur(18px);
}

.topbar::before {
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(112, 76, 140, 0.18);
  border-radius: 6px;
  pointer-events: none;
  content: "";
}

.brand-lockup {
  position: relative;
  z-index: 1;
  gap: 16px;
}

.brand-mark {
  width: 62px;
  height: 62px;
  border: 1px solid rgba(255, 251, 233, 0.76);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 239, 170, 0.95), transparent 32%),
    linear-gradient(135deg, var(--academy-violet), var(--academy-moss));
  box-shadow:
    0 18px 36px rgba(112, 76, 140, 0.28),
    inset 0 0 0 8px rgba(255, 248, 239, 0.14);
}

.brand-mark svg {
  filter: drop-shadow(0 0 12px rgba(255, 232, 158, 0.72));
}

.eyebrow {
  color: var(--academy-moss);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

h1 {
  max-width: 760px;
  color: #2b2035;
  font-family: Cambria, Georgia, serif;
  font-size: clamp(2.35rem, 4.8vw, 5.2rem);
  font-weight: 700;
  line-height: 0.9;
  text-shadow: 0 12px 32px rgba(112, 76, 140, 0.16);
}

h2 {
  color: #2b2035;
  font-family: Cambria, Georgia, serif;
  font-size: 1.34rem;
  font-weight: 700;
}

h3 {
  color: #342842;
  font-size: 0.98rem;
}

.ghost-button {
  position: relative;
  z-index: 1;
  min-height: 46px;
  border: 1px solid rgba(112, 76, 140, 0.2);
  background: rgba(255, 252, 244, 0.88);
  box-shadow: 0 14px 28px rgba(55, 38, 68, 0.14);
  color: var(--academy-violet);
  font-weight: 900;
}

.workspace {
  grid-template-columns: minmax(290px, 0.92fr) minmax(320px, 1fr) minmax(340px, 1.08fr);
  gap: 18px;
  min-width: 0;
}

.tool-panel,
.history-panel {
  border: 1px solid rgba(255, 248, 232, 0.56);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 252, 244, 0.9), rgba(247, 235, 224, 0.78)),
    rgba(255, 248, 239, 0.72);
  box-shadow: var(--academy-shadow);
  padding: 20px;
  min-width: 0;
  backdrop-filter: blur(20px);
}

.tool-panel::before,
.history-panel::before {
  height: 7px;
  background:
    linear-gradient(90deg, var(--academy-moss), var(--academy-gold), var(--academy-rose), var(--academy-lilac)),
    rgba(255, 248, 239, 0.8);
}

.tool-panel::after,
.history-panel::after {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 43% 36%, rgba(255, 234, 176, 0.45), transparent 0 18%, transparent 19%),
    radial-gradient(circle at 50% 50%, rgba(112, 76, 140, 0.08), transparent 62%);
  pointer-events: none;
  content: "";
}

.prompt-panel {
  min-height: 640px;
}

.attack-panel {
  min-height: 640px;
}

.result-panel,
.history-panel {
  min-height: 280px;
}

.panel-heading {
  position: relative;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 14px;
}

.panel-heading::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(90deg, rgba(112, 76, 140, 0.22), transparent);
  content: "";
}

.panel-heading > svg {
  color: var(--academy-violet);
  filter: drop-shadow(0 0 10px rgba(216, 172, 85, 0.32));
}

.field-label,
.rules-header span,
.run-strip span,
.score-grid span,
.history-list span,
.range-card span,
.evaluation-row span,
.history-empty {
  color: var(--academy-muted);
}

textarea,
input {
  max-width: 100%;
  min-width: 0;
  border: 1px solid rgba(112, 76, 140, 0.18);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.86);
  color: var(--academy-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

textarea {
  min-height: 184px;
  font-size: 0.94rem;
}

textarea:focus,
input:focus {
  border-color: rgba(112, 76, 140, 0.52);
  box-shadow: 0 0 0 4px rgba(216, 172, 85, 0.17);
}

.rule-row,
.range-card,
.run-strip,
.response-box,
.evaluation-row,
.score-grid div,
.history-list button,
.empty-state {
  border: 1px solid rgba(112, 76, 140, 0.14);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.76);
  box-shadow: 0 10px 26px rgba(55, 38, 68, 0.08);
}

.rule-row {
  grid-template-columns: 22px minmax(0, 1fr) 34px;
}

.rule-row svg {
  color: var(--academy-moss);
}

.icon-button {
  color: var(--academy-violet);
  background: rgba(183, 155, 215, 0.16);
}

.icon-button.add,
.run-button,
.template-tabs button.active,
.mode-toggle button.active {
  color: #fffaf0;
  background: linear-gradient(135deg, var(--academy-violet), var(--academy-moss));
  box-shadow: 0 14px 28px rgba(112, 76, 140, 0.22);
}

.template-tabs,
.mode-toggle {
  gap: 9px;
}

.template-tabs button,
.mode-toggle button {
  min-height: 38px;
  border: 1px solid rgba(112, 76, 140, 0.17);
  background: rgba(255, 252, 246, 0.74);
  color: #3a2b45;
}

.template-tabs button:hover,
.mode-toggle button:hover,
.ghost-button:hover,
.run-button:hover,
.icon-button:hover,
.history-list button:hover {
  transform: translateY(-1px);
}

.template-tabs button,
.mode-toggle button,
.ghost-button,
.run-button,
.icon-button,
.history-list button {
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.run-strip {
  padding: 15px;
}

.run-strip strong,
.score-grid strong,
.history-list strong {
  color: var(--academy-violet);
  font-family: Cambria, Georgia, serif;
}

.run-button {
  min-height: 48px;
  padding: 0 20px;
}

.score-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.score-grid div {
  min-height: 96px;
}

.score-grid strong {
  font-size: 2rem;
}

.response-box {
  background:
    linear-gradient(135deg, rgba(255, 252, 246, 0.86), rgba(237, 224, 246, 0.62)),
    rgba(255, 252, 246, 0.8);
}

.status-pill {
  min-width: 62px;
  border-radius: 999px;
}

.status-pill.pass {
  color: #385d36;
  background: rgba(134, 176, 103, 0.22);
}

.status-pill.warn {
  color: #795817;
  background: rgba(216, 172, 85, 0.25);
}

.status-pill.fail {
  color: #7a2d4a;
  background: rgba(201, 130, 154, 0.24);
}

.empty-state {
  min-height: 340px;
  background:
    radial-gradient(circle at 50% 30%, rgba(216, 172, 85, 0.18), transparent 28%),
    rgba(255, 252, 246, 0.55);
}

.empty-state svg {
  color: var(--academy-gold);
}

.history-panel {
  background:
    linear-gradient(180deg, rgba(255, 252, 244, 0.88), rgba(236, 247, 226, 0.7)),
    rgba(255, 248, 239, 0.72);
}

.history-list button {
  min-height: 48px;
}

@keyframes academyFloat {
  from {
    transform: translate3d(0, 0, 0);
  }

  to {
    transform: translate3d(18px, -14px, 0);
  }
}

@media (max-width: 1100px) {
  body {
    background-attachment: scroll;
  }

  .workspace {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "prompt attack"
      "result result"
      "history history";
  }

  .prompt-panel,
  .attack-panel {
    min-height: 0;
  }
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    overflow-x: hidden;
  }

  body {
    padding: 0;
  }

  .app-shell {
    width: calc(100% - 64px) !important;
    max-width: 680px !important;
    margin: 0 auto !important;
    padding: 12px 0 28px !important;
  }

  .topbar {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    padding: 18px;
  }

  .brand-lockup {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: flex-start;
    width: 100%;
    min-width: 0;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
  }

  h1 {
    font-size: clamp(2rem, 13vw, 3.2rem);
  }

  .workspace {
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
    grid-template-areas:
      "prompt"
      "attack"
      "result"
      "history";
    min-width: 0;
  }

  .tool-panel,
  .history-panel {
    width: 100%;
    max-width: 100%;
    padding: 16px;
    min-width: 0;
  }

  .rule-row {
    grid-template-columns: 22px minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
  }

  .rules-header span,
  .rule-row .icon-button {
    display: none;
  }

  .add-rule {
    grid-template-columns: 1fr;
  }

  .add-rule .icon-button.add {
    width: 100%;
  }

  .rule-row span,
  textarea,
  input {
    overflow-wrap: anywhere;
  }

  .template-tabs button,
  .mode-toggle button {
    flex: 1 1 auto;
  }

  .template-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .template-tabs button {
    width: 100%;
    min-width: 0;
  }

  .score-grid {
    grid-template-columns: 1fr;
  }

  .run-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .run-button,
  .ghost-button {
    width: 100%;
  }
}
