:root {
  --bg: #f5fbfd;
  --panel: #ffffff;
  --ink: #16313f;
  --muted: #667985;
  --line: #d6e5ea;
  --soft: #e8f6f3;
  --accent: #15746b;
  --accent-strong: #0f5b55;
  --blue: #2f7dd1;
  --blue-soft: #e8f2ff;
  --coral: #d95f55;
  --coral-soft: #fff0ee;
  --amber: #b77910;
  --amber-soft: #fff6db;
  --green: #2f7a4f;
  --green-soft: #e9f7ef;
  --warn: #a36613;
  --error: #a43a38;
  --ok: #23724d;
  --shadow: 0 20px 70px rgba(22, 49, 63, 0.11);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(47, 125, 209, 0.1), transparent 260px),
    linear-gradient(90deg, rgba(21, 116, 107, 0.1), transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--blue), var(--coral), var(--amber));
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 12px 30px rgba(21, 116, 107, 0.22);
}

.brand-mark svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.08rem;
  line-height: 1.25;
  font-weight: 760;
}

.brand p,
.preview-header p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.88rem;
}

.topbar-actions,
.preview-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.access-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.access-field input {
  width: 132px;
  min-height: 36px;
}

.workspace {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px 28px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(390px, 0.95fr);
  gap: 22px;
  align-items: start;
}

.input-panel,
.preview-panel {
  background: var(--panel);
  border: 1px solid rgba(122, 153, 163, 0.34);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.input-panel {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;
  overflow: hidden;
}

.input-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--blue), var(--coral), var(--amber));
}

.preview-panel {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 110px);
  overflow: auto;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.section-title h2,
.preview-header h2,
.notes h2 {
  font-size: 0.92rem;
  line-height: 1.3;
  font-weight: 760;
}

.section-title h2 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.section-title h2::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--coral), var(--amber));
}

.section-title span,
#statusPill {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 720;
  text-transform: uppercase;
}

.grid {
  display: grid;
  gap: 12px;
}

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

.grid.compact {
  align-items: start;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

label > span,
legend,
.choice-field > span {
  color: #37534e;
  font-size: 0.82rem;
  font-weight: 690;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid #cadfe5;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

select[multiple] {
  min-height: 132px;
  padding: 8px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(47, 125, 209, 0.72);
  box-shadow: 0 0 0 3px rgba(47, 125, 209, 0.14);
}

.choice-field {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.choice-field legend,
.choice-field > span {
  display: block;
  margin-bottom: 8px;
}

.choice-grid,
.chip-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 8px;
}

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

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

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

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

.choice-card,
.chip {
  display: block;
  min-width: 0;
}

.choice-card input,
.chip input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
}

.choice-card span,
.chip span,
.sentence-presets button {
  min-width: 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border: 1px solid #c9dfe6;
  border-radius: var(--radius);
  color: #33525d;
  background: #fff;
  font-weight: 780;
  overflow-wrap: anywhere;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.choice-card span {
  flex-direction: column;
  align-items: flex-start;
}

.pronoun-card span,
.chip span,
.sentence-presets button {
  flex-direction: row;
  align-items: center;
  text-align: center;
}

.choice-card strong {
  font-size: 0.96rem;
  line-height: 1.05;
}

.choice-card small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 720;
}

.choice-card:hover span,
.chip:hover span,
.sentence-presets button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(22, 49, 63, 0.1);
}

.choice-card input:checked + span {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  box-shadow: 0 12px 30px rgba(47, 125, 209, 0.18);
}

.choice-card input:checked + span small {
  color: rgba(255, 255, 255, 0.86);
}

.period-card input:checked + span {
  background: linear-gradient(135deg, var(--blue), var(--accent));
}

.pronoun-card input:checked + span {
  background: linear-gradient(135deg, var(--coral), var(--amber));
}

.chip span {
  justify-content: flex-start;
}

.chip span::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: currentColor;
  opacity: 0.52;
}

.chip-teal span {
  color: var(--accent);
  background: var(--soft);
}

.chip-blue span {
  color: var(--blue);
  background: var(--blue-soft);
}

.chip-coral span {
  color: var(--coral);
  background: var(--coral-soft);
}

.chip-amber span {
  color: var(--amber);
  background: var(--amber-soft);
}

.chip-green span {
  color: var(--green);
  background: var(--green-soft);
}

.chip input:checked + span {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  box-shadow: 0 12px 28px rgba(21, 116, 107, 0.18);
}

.chip-coral input:checked + span {
  background: linear-gradient(135deg, var(--coral), var(--amber));
}

.chip-amber input:checked + span {
  background: linear-gradient(135deg, var(--amber), var(--coral));
}

.chip-green input:checked + span {
  background: linear-gradient(135deg, var(--green), var(--accent));
}

.sentence-control {
  display: grid;
  gap: 8px;
}

.sentence-presets {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.sentence-presets button {
  min-height: 34px;
  padding: 6px;
  border-color: rgba(47, 125, 209, 0.28);
  color: var(--blue);
  background: var(--blue-soft);
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 760;
}

.primary-button {
  flex: 1;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  padding: 0 18px;
  box-shadow: 0 12px 28px rgba(21, 116, 107, 0.18);
}

.primary-button:hover {
  background: linear-gradient(135deg, var(--accent-strong), #236db4);
  transform: translateY(-1px);
}

.secondary-button,
.icon-button {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: rgba(47, 125, 209, 0.25);
}

.secondary-button {
  padding: 0 16px;
}

.secondary-button:hover,
.icon-button:hover {
  color: var(--accent-strong);
  background: var(--soft);
  transform: translateY(-1px);
}

.danger-button {
  color: var(--error);
  background: var(--coral-soft);
  border-color: rgba(217, 95, 85, 0.28);
}

.danger-button:hover {
  color: #fff;
  background: var(--error);
  border-color: var(--error);
}

.icon-button {
  width: 42px;
  padding: 0;
}

.primary-button svg,
.secondary-button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(47, 125, 209, 0.08), rgba(21, 116, 107, 0.05));
}

.comment-output {
  padding: 24px;
  min-height: 310px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(47, 125, 209, 0.055) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(180deg, rgba(255, 246, 219, 0.36), transparent 180px),
    #fff;
}

.comment-output p {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
  line-height: 1.75;
}

.comment-output pre.prompt-output {
  margin: 0;
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-output .empty-state {
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.96rem;
  line-height: 1.55;
}

.checklist,
.notes {
  padding: 20px;
}

.checklist {
  background: linear-gradient(180deg, #fff, rgba(232, 246, 243, 0.48));
}

.checklist ul,
.notes ul {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 9px;
}

.checklist li,
.notes li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  color: #405b56;
  font-size: 0.92rem;
  line-height: 1.45;
}

.checklist li::before,
.notes li::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 99px;
  background: var(--line);
  flex: 0 0 auto;
}

.checklist li.pass::before {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(35, 114, 77, 0.12);
}

.checklist li.warn::before,
.notes li::before {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(163, 102, 19, 0.12);
}

.checklist li.fail::before {
  background: var(--error);
  box-shadow: 0 0 0 4px rgba(164, 58, 56, 0.12);
}

.notes {
  border-top: 1px solid var(--line);
  background: #fffdf8;
}

.loading {
  display: inline-flex;
  gap: 7px;
  align-items: center;
}

.loading span {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--accent);
  animation: pulse 900ms ease-in-out infinite;
}

.loading span:nth-child(2) {
  animation-delay: 120ms;
}

.loading span:nth-child(3) {
  animation-delay: 240ms;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--accent-strong);
  box-shadow: var(--shadow);
  z-index: 30;
  font-weight: 700;
}

.toast.error {
  background: var(--error);
}

@keyframes pulse {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  50% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .topbar-actions,
  .access-field,
  .form-actions {
    width: 100%;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
    align-items: end;
  }

  .access-field input,
  .primary-button,
  .secondary-button {
    flex: 1;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-actions .primary-button,
  .form-actions .secondary-button {
    width: 100%;
  }

  .workspace {
    padding: 14px;
    gap: 14px;
  }

  .input-panel {
    padding: 16px;
  }

  .grid.two,
  .period-grid,
  .pronoun-grid,
  .profile-grid,
  .atl-grid {
    grid-template-columns: 1fr;
  }

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

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

  .preview-header {
    align-items: flex-start;
  }
}
