:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #697386;
  --line: #dfe5ee;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-soft: #eef2ff;
  --success: #14805e;
  --success-soft: #e8f8f1;
  --warning: #b46700;
  --warning-soft: #fff6df;
  --danger: #c33d4a;
  --danger-soft: #fff0f2;
  --shadow: 0 20px 55px rgba(32, 44, 72, 0.11);
  --shadow-soft: 0 10px 30px rgba(32, 44, 72, 0.08);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --max-width: 1240px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(79, 70, 229, 0.08), transparent 28rem),
    radial-gradient(circle at 90% 30%, rgba(20, 128, 94, 0.07), transparent 30rem),
    var(--bg);
}

button,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.28);
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

.page-glow {
  position: fixed;
  border-radius: 999px;
  filter: blur(80px);
  pointer-events: none;
  opacity: 0.45;
  z-index: -1;
}

.page-glow-one {
  width: 22rem;
  height: 22rem;
  left: -8rem;
  top: 8rem;
  background: rgba(99, 102, 241, 0.18);
}

.page-glow-two {
  width: 26rem;
  height: 26rem;
  right: -10rem;
  top: 30rem;
  background: rgba(16, 185, 129, 0.14);
}

.topbar {
  width: min(var(--max-width), calc(100% - 32px));
  margin: 18px auto 0;
  min-height: 72px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(223, 229, 238, 0.9);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 12px;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: white;
  font-weight: 900;
  letter-spacing: -0.05em;
  background: linear-gradient(145deg, #5b52f0, #3730a3);
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.25);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
}

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

.mode-pill,
.stat-chip {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  border-radius: 14px;
}

.mode-pill {
  padding: 0 13px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.mode-pill.ai-mode {
  color: var(--success);
  border-color: #b8e7d7;
  background: var(--success-soft);
}

.mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9ca3af;
}

.mode-pill.ai-mode .mode-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(20, 128, 94, 0.1);
}

.stat-chip {
  padding: 6px 11px;
}

.stat-chip span:last-child {
  display: grid;
  line-height: 1.05;
}

.stat-chip small {
  color: var(--muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-chip strong {
  margin-top: 3px;
  font-size: 0.95rem;
}

.stat-icon {
  font-size: 1.05rem;
}

.app-shell {
  width: min(var(--max-width), calc(100% - 32px));
  margin: 28px auto 50px;
}

.hero-panel {
  min-height: 230px;
  padding: 42px 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
  color: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background:
    linear-gradient(110deg, rgba(28, 31, 73, 0.98), rgba(55, 48, 163, 0.95)),
    #29245d;
  box-shadow: var(--shadow);
  position: relative;
}

.hero-panel::after {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  right: -70px;
  top: -80px;
  border: 48px solid rgba(255, 255, 255, 0.05);
  border-radius: 50%;
}

.eyebrow,
.kicker {
  margin: 0 0 7px;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.eyebrow {
  color: #c7d2fe;
}

.kicker {
  color: var(--primary);
}

.hero-panel h1 {
  max-width: 700px;
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.55rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.hero-copy {
  max-width: 750px;
  margin: 18px 0 0;
  color: #dfe4ff;
  font-size: 1.02rem;
  line-height: 1.7;
}

.hero-badge {
  width: 132px;
  min-width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  color: #eef2ff;
  background: rgba(255, 255, 255, 0.08);
  text-align: center;
  font-weight: 900;
  letter-spacing: 0.14em;
  line-height: 1.15;
  transform: rotate(5deg);
}

.magnifier {
  display: block;
  margin-bottom: 4px;
  font-size: 2rem;
}

.workspace {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
  gap: 22px;
}

.control-card,
.game-card,
.feedback-card,
.progress-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.control-card {
  padding: 24px;
  position: sticky;
  top: 104px;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-heading.compact {
  align-items: flex-start;
}

.section-heading h2,
.section-heading h3,
.source-heading h3,
.progress-card h2 {
  margin: 0;
  letter-spacing: -0.025em;
}

.section-heading h2,
.progress-card h2 {
  font-size: 1.25rem;
}

.section-heading h3,
.source-heading h3 {
  font-size: 1rem;
}

.step-number {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--primary);
  font-weight: 900;
  background: var(--primary-soft);
  border: 1px solid #d9ddff;
  border-radius: 12px;
}

.setup-form {
  margin-top: 24px;
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field > span,
.difficulty-field legend {
  color: #414b5f;
  font-size: 0.82rem;
  font-weight: 800;
}

select {
  width: 100%;
  height: 46px;
  padding: 0 38px 0 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

select:hover {
  border-color: #b8c0cf;
}

.difficulty-field {
  margin: 0;
  padding: 0;
  border: 0;
}

.difficulty-field legend {
  margin-bottom: 7px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 4px;
  background: #eef1f5;
  border-radius: 12px;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  transition: 160ms ease;
}

.segmented-control input:checked + span {
  color: var(--primary-dark);
  background: white;
  box-shadow: 0 3px 10px rgba(31, 41, 55, 0.08);
}

.button {
  min-height: 46px;
  padding: 0 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 12px;
  font-weight: 850;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.button-primary {
  color: white;
  background: linear-gradient(135deg, #5a50ed, #4338ca);
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.22);
}

.button-primary:hover {
  box-shadow: 0 13px 28px rgba(79, 70, 229, 0.28);
}

.button-secondary {
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid #d9ddff;
}

.button-ghost {
  color: #4d576a;
  background: #f2f4f8;
}

.button-wide {
  width: 100%;
  justify-content: space-between;
  padding-left: 18px;
  padding-right: 18px;
}

.mini-note {
  margin-top: 20px;
  padding: 13px 14px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed #cfd6e2;
  border-radius: 12px;
  font-size: 0.75rem;
  line-height: 1.55;
}

.mini-note strong {
  color: #414b5f;
}

.game-column {
  display: grid;
  gap: 22px;
}

.game-card {
  min-height: 630px;
  overflow: hidden;
}

.empty-state {
  min-height: 630px;
  padding: 50px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-icon {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  color: var(--primary);
  font-size: 2.2rem;
  background: var(--primary-soft);
  border-radius: 24px;
}

.empty-state h2 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: -0.035em;
}

.empty-state p {
  max-width: 480px;
  margin: 10px 0 22px;
  color: var(--muted);
  line-height: 1.6;
}

.case-header {
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}

.case-header h2 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.035em;
}

.case-tags {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
}

.case-tags span {
  padding: 7px 9px;
  color: #535d70;
  background: #f3f5f8;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.topic-strip {
  margin: 24px 28px 0;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #dce2ec;
  border-radius: 14px;
  background: var(--surface-soft);
}

.topic-strip small,
.topic-strip strong {
  display: block;
}

.topic-strip small {
  color: var(--muted);
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.topic-strip strong {
  margin-top: 2px;
  font-size: 0.9rem;
}

.topic-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 10px;
  font-weight: 900;
}

.instruction-block,
.answer-block {
  padding: 28px;
}

.instruction-block {
  padding-bottom: 0;
}

.passage {
  margin-top: 18px;
  padding: 24px 25px;
  color: #222b3d;
  background:
    linear-gradient(#fffef7, #fffef7) padding-box,
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 33px,
      #e6e0c9 34px
    );
  border: 1px solid #e8e0bf;
  border-left: 5px solid #e7b94c;
  border-radius: 15px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.08rem, 2vw, 1.25rem);
  line-height: 1.8;
  white-space: pre-wrap;
}

.answer-heading {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 9px;
}

.answer-heading label {
  display: grid;
  gap: 2px;
}

.answer-heading strong {
  font-size: 0.95rem;
}

.answer-heading span,
.word-count {
  color: var(--muted);
  font-size: 0.75rem;
}

textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  padding: 18px;
  color: var(--ink);
  border: 1px solid #ccd4e0;
  border-radius: 14px;
  background: #fff;
  line-height: 1.7;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

textarea:focus {
  border-color: #8f8af5;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.08);
  outline: 0;
}

.answer-actions {
  margin-top: 13px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.hint-panel {
  margin-top: 14px;
  padding: 14px 16px;
  color: #6f4c00;
  background: var(--warning-soft);
  border: 1px solid #f3d68f;
  border-radius: 13px;
}

.hint-panel strong {
  font-size: 0.79rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hint-panel p {
  margin: 6px 0 0;
  font-size: 0.85rem;
  line-height: 1.55;
}

.source-panel {
  margin: 0 28px 28px;
  border: 1px solid var(--line);
  border-radius: 15px;
  overflow: hidden;
}

.source-heading {
  padding: 15px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  background: var(--surface-soft);
}

.text-button {
  padding: 5px;
  color: var(--primary);
  border: 0;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 850;
}

.danger-text {
  color: var(--danger);
}

.source-content {
  padding: 16px;
}

.source-content > p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

.search-suggestions:empty {
  display: none;
}

.sources-list {
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 7px;
  list-style: none;
}

.sources-list a {
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.feedback-card {
  padding: 28px;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 24px;
  border-color: #cfe7dc;
}

.score-ring {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  align-content: center;
  border: 9px solid #c9eee0;
  border-radius: 50%;
  background: var(--success-soft);
}

.score-ring span {
  color: var(--success);
  font-size: 2rem;
  line-height: 1;
  font-weight: 950;
  letter-spacing: -0.06em;
}

.score-ring small {
  margin-top: 2px;
  color: #5e6a78;
  font-size: 0.7rem;
}

.score-ring.medium {
  border-color: #f4dca3;
  background: var(--warning-soft);
}

.score-ring.medium span {
  color: var(--warning);
}

.score-ring.low {
  border-color: #f0c1c6;
  background: var(--danger-soft);
}

.score-ring.low span {
  color: var(--danger);
}

.feedback-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 15px;
}

.feedback-title-row h2 {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.04em;
}

.result-badge {
  padding: 7px 10px;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid #c2e7d8;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.feedback-summary {
  margin: 12px 0 20px;
  color: var(--muted);
  line-height: 1.65;
}

.feedback-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.feedback-box,
.reference-answer {
  padding: 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.feedback-box h3,
.corrections-wrap h3 {
  margin: 0 0 7px;
  font-size: 0.87rem;
}

.feedback-box p,
.reference-answer p {
  margin: 0;
  color: #525d70;
  font-size: 0.84rem;
  line-height: 1.6;
}

.corrections-wrap {
  margin-top: 19px;
}

.corrections-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
}

.corrections-list li {
  padding: 10px 12px;
  color: #475164;
  background: #f7f9fc;
  border-left: 3px solid #9aa6ba;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.5;
}

.corrections-list li.good {
  border-left-color: var(--success);
}

.corrections-list li.fix {
  border-left-color: var(--warning);
}

.reference-answer {
  margin-top: 17px;
  background: #f8fbff;
}

.reference-answer .kicker {
  margin-bottom: 8px;
}

.reference-answer p:last-child {
  color: #263248;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.98rem;
}

.feedback-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.progress-card {
  margin-top: 22px;
  padding: 22px 25px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}

.progress-stats {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

.progress-stats > div {
  min-width: 90px;
  padding: 10px 14px;
  display: grid;
  gap: 2px;
  text-align: center;
  background: var(--surface-soft);
  border-radius: 12px;
}

.progress-stats small {
  color: var(--muted);
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.progress-stats strong {
  font-size: 1.05rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 27, 44, 0.52);
  backdrop-filter: blur(6px);
}

.loading-card {
  width: min(440px, 100%);
  padding: 30px;
  text-align: center;
  background: white;
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.loading-card strong {
  display: block;
  margin-top: 17px;
  font-size: 1.15rem;
}

.loading-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 5px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 120;
  max-width: min(420px, calc(100% - 44px));
  padding: 13px 16px;
  color: white;
  background: #252c3d;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  line-height: 1.5;
}

footer {
  padding: 0 20px 28px;
  color: #8a94a7;
  text-align: center;
  font-size: 0.75rem;
}

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

  .control-card {
    position: static;
  }

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

  .setup-form .button-wide,
  .mini-note {
    grid-column: 1 / -1;
  }

  .difficulty-field {
    align-self: end;
  }
}

@media (max-width: 740px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .mode-pill {
    margin-right: auto;
  }

  .hero-panel {
    min-height: 0;
    padding: 32px 25px;
  }

  .hero-badge {
    display: none;
  }

  .hero-panel h1 {
    font-size: 2.4rem;
  }

  .case-header {
    flex-direction: column;
  }

  .case-tags {
    justify-content: flex-start;
  }

  .feedback-card {
    grid-template-columns: 1fr;
  }

  .score-ring {
    width: 96px;
    height: 96px;
  }

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

  .progress-card {
    align-items: stretch;
    flex-direction: column;
  }

  .progress-stats {
    width: 100%;
    margin-left: 0;
  }

  .progress-stats > div {
    min-width: 0;
    flex: 1;
  }
}

@media (max-width: 560px) {
  .topbar,
  .app-shell {
    width: min(100% - 20px, var(--max-width));
  }

  .brand small,
  .mode-pill {
    display: none;
  }

  .stat-chip {
    margin-left: auto;
  }

  .stat-chip + .stat-chip {
    margin-left: 0;
  }

  .hero-panel {
    border-radius: 20px;
  }

  .setup-form {
    grid-template-columns: 1fr;
  }

  .setup-form .button-wide,
  .mini-note {
    grid-column: auto;
  }

  .control-card {
    padding: 20px;
    border-radius: 20px;
  }

  .game-card,
  .feedback-card,
  .progress-card {
    border-radius: 20px;
  }

  .empty-state {
    min-height: 460px;
    padding: 30px 22px;
  }

  .case-header,
  .instruction-block,
  .answer-block {
    padding-left: 20px;
    padding-right: 20px;
  }

  .topic-strip,
  .source-panel {
    margin-left: 20px;
    margin-right: 20px;
  }

  .passage {
    padding: 19px;
  }

  .answer-heading {
    flex-direction: column;
  }

  .answer-actions,
  .feedback-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .answer-actions .button,
  .feedback-actions .button {
    width: 100%;
  }

  .feedback-card {
    padding: 21px;
  }

  .feedback-title-row {
    flex-direction: column;
  }

  .progress-stats {
    gap: 6px;
  }

  .progress-stats > div {
    padding-left: 7px;
    padding-right: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
