:root {
  --bg: #f7f9fc;
  --paper: #ffffff;
  --paper-2: #f2f6ff;
  --ink: #071229;
  --muted: #5c6880;
  --line: #dbe3ef;
  --blue: #0a63f6;
  --blue-2: #004fc9;
  --green: #14a05d;
  --yellow: #ffc400;
  --orange: #f47c20;
  --red: #df3d42;
  --shadow: 0 18px 45px rgba(7, 18, 41, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(10, 99, 246, 0.06), rgba(20, 160, 93, 0) 460px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 92px;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(260px, 420px) auto;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(20px, 1.8vw, 28px);
  line-height: 1.08;
  letter-spacing: 0;
}

.brand p,
.micro {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.micro {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.icon-button,
.icon-close {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
}

.icon-button span {
  display: block;
  width: 21px;
  height: 2px;
  margin: 3px 0;
  background: currentColor;
}

.icon-close {
  font-size: 30px;
  line-height: 1;
}

.top-progress {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.top-progress span {
  font-weight: 800;
  color: #26344f;
  white-space: nowrap;
}

.progress-track {
  height: 10px;
  background: #e8eef7;
  border-radius: 999px;
  overflow: hidden;
}

.progress-track div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), #18a7ff);
  border-radius: inherit;
  transition: width 240ms ease;
}

.top-actions,
.card-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  gap: 24px;
  padding: 24px;
}

.topic-rail,
.score-panel {
  position: sticky;
  top: 106px;
  align-self: start;
}

.topic-rail {
  min-height: calc(100vh - 130px);
  padding: 18px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.rail-heading {
  margin: 8px 4px 14px;
  color: #43506a;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topic-item {
  width: 100%;
  min-height: 70px;
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.topic-item:hover,
.topic-item.is-active {
  border-color: #cfe0ff;
  background: linear-gradient(90deg, rgba(10, 99, 246, 0.12), rgba(10, 99, 246, 0.03));
}

.topic-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(145deg, var(--blue), #0b2d72);
  border-radius: var(--radius);
  font-weight: 900;
  box-shadow: 0 12px 22px rgba(10, 99, 246, 0.24);
}

.topic-item strong {
  display: block;
  font-size: 15px;
}

.topic-item em {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
}

.mode-panel {
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.mode-button {
  width: 100%;
  margin-bottom: 9px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: #22304a;
  font-weight: 850;
  text-align: left;
}

.mode-button.is-selected {
  border-color: var(--blue);
  background: #eef5ff;
  color: var(--blue);
}

.quiz-column {
  min-width: 0;
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(330px, 1fr);
  align-items: center;
  gap: 22px;
  margin-bottom: 18px;
  padding: 22px 26px;
  border: 1px solid #d7e1f0;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero-card h2 {
  margin: 4px 0 8px;
  font-size: clamp(25px, 3.5vw, 44px);
  line-height: 1.02;
  letter-spacing: 0;
}

.hero-card p:not(.micro) {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
  font-weight: 650;
}

.hero-card img {
  width: 100%;
  aspect-ratio: 12 / 7;
  object-fit: cover;
  object-position: 58% center;
  border-radius: var(--radius);
}

.question-card,
.score-card,
.tip-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.question-card {
  padding: 26px;
}

.question-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.pill,
.difficulty,
.topic-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 900;
}

.pill {
  color: var(--blue);
  background: #eef5ff;
  border: 1px solid #a8c6ff;
}

.difficulty {
  margin-left: 8px;
  color: #9b5500;
  background: #fff2cf;
}

.difficulty.is-hard {
  color: #982227;
  background: #ffe4e4;
}

.difficulty.is-easy {
  color: #087447;
  background: #dcf8ea;
}

.topic-chip {
  color: #26344f;
  background: #f0f4fa;
}

.question-card h2 {
  margin: 0 0 10px;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.14;
  letter-spacing: 0;
}

.instruction {
  margin: 0 0 18px;
  color: var(--muted);
  font-weight: 700;
}

.sentence-box {
  display: none;
  margin: 18px 0 20px;
  padding: 18px 20px;
  border: 1px solid #cfe0ff;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfdff, #f3f7ff);
  font-size: clamp(18px, 2.3vw, 25px);
  line-height: 1.5;
}

.sentence-box:not(:empty) {
  display: block;
}

.sentence-box u {
  text-decoration-thickness: 3px;
  text-decoration-style: wavy;
  text-decoration-color: var(--blue);
  text-underline-offset: 5px;
}

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

.option-button {
  min-height: 58px;
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid #cfd9e9;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  font-size: 17px;
  font-weight: 760;
}

.option-button:hover,
.option-button.is-selected {
  border-color: var(--blue);
  background: #f1f6ff;
}

.option-button.is-correct {
  border-color: var(--green);
  background: #e9f9f0;
}

.option-button.is-wrong {
  border-color: var(--red);
  background: #fff0f0;
}

.option-letter {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--blue);
  background: #eaf2ff;
  font-weight: 950;
}

.confidence-panel {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fbfdff;
}

.confidence-panel > span {
  display: block;
  padding: 12px 14px 6px;
  color: #34435f;
  font-size: 14px;
  font-weight: 850;
}

.confidence-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.confidence-options button {
  min-height: 48px;
  border: 0;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--paper);
  color: #40506b;
  font-weight: 850;
}

.confidence-options button:last-child {
  border-right: 0;
}

.confidence-options button.is-selected {
  color: #087447;
  background: #e9f9f0;
}

.feedback {
  min-height: 78px;
  margin-top: 20px;
  padding: 16px 18px;
  display: grid;
  gap: 4px;
  border: 1px dashed #c5d4e8;
  border-radius: var(--radius);
  background: #fbfdff;
  color: #26344f;
  line-height: 1.45;
}

.feedback.is-good {
  border-style: solid;
  border-color: #97dfb5;
  background: #edf9f2;
}

.feedback.is-bad {
  border-style: solid;
  border-color: #ffb7b7;
  background: #fff1f1;
}

.card-actions {
  justify-content: space-between;
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.ghost-button,
.primary-button,
.primary-small,
.check-button,
.outline-button {
  min-height: 48px;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  font-weight: 900;
  border: 1px solid var(--line);
  background: var(--paper);
  color: #21304a;
}

.primary-button,
.primary-small {
  color: white;
  border-color: var(--blue);
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
}

.primary-small {
  min-height: 42px;
}

.check-button {
  min-width: min(340px, 48%);
  color: #1e2a00;
  border-color: #e6b000;
  background: linear-gradient(135deg, var(--yellow), #ffdf45);
}

.outline-button {
  width: 100%;
  color: var(--blue);
  border-color: #9cc0ff;
  background: #f7fbff;
}

.score-panel {
  display: grid;
  gap: 16px;
}

.score-card,
.tip-card {
  padding: 20px;
}

.score-card h3,
.tip-card h3,
.result-dialog h3 {
  margin: 0 0 14px;
  font-size: 16px;
  letter-spacing: 0;
}

.score-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.score-row:last-child {
  border-bottom: 0;
}

.score-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-weight: 950;
}

.gold { background: var(--yellow); }
.blue { background: var(--blue); }
.green { background: var(--green); }
.red { background: var(--orange); }

.score-row small {
  display: block;
  color: var(--muted);
  font-weight: 750;
}

.score-row strong {
  display: block;
  margin-top: 2px;
  font-size: 26px;
  line-height: 1;
}

.weak-list {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.weak-item {
  display: grid;
  gap: 6px;
}

.weak-item span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #34435f;
  font-size: 13px;
  font-weight: 850;
}

.weak-bar {
  height: 8px;
  background: #e8edf5;
  border-radius: 999px;
  overflow: hidden;
}

.weak-bar div {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--yellow), var(--green));
}

.tip-card {
  border-color: #f6d981;
  background: linear-gradient(180deg, #fff9e8, #ffffff);
}

.tip-card p {
  margin: 0;
  color: #43506a;
  line-height: 1.55;
  font-weight: 680;
}

.result-dialog {
  width: min(1040px, calc(100vw - 28px));
  max-height: min(860px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 30px 90px rgba(7, 18, 41, 0.24);
  color: var(--ink);
}

.result-dialog::backdrop {
  background: rgba(7, 18, 41, 0.52);
}

.result-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 22px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.result-header h2 {
  margin: 4px 0 0;
  font-size: clamp(24px, 3vw, 36px);
}

.result-dialog > section,
.result-grid,
.dialog-actions {
  margin: 0 24px 22px;
}

.result-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  padding-top: 22px;
}

.result-score {
  padding: 22px;
  border: 1px solid #cfe0ff;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #eef5ff, #ffffff);
}

.result-score strong {
  display: block;
  font-size: 64px;
  line-height: 1;
}

.result-score span {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-weight: 950;
}

.result-score p {
  margin: 14px 0 0;
  color: #34435f;
  line-height: 1.5;
  font-weight: 720;
}

.result-list,
.mistake-list {
  display: grid;
  gap: 10px;
}

.result-topic,
.mistake {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
}

.result-topic strong,
.mistake strong {
  display: block;
  margin-bottom: 4px;
}

.result-topic span,
.mistake span {
  color: var(--muted);
  font-weight: 680;
  line-height: 1.45;
}

.mistake code {
  display: block;
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #f0f4fa;
  color: #1e2c44;
  white-space: normal;
  font-family: inherit;
  font-weight: 780;
}

.dialog-actions {
  position: sticky;
  bottom: 0;
  justify-content: flex-end;
  padding: 18px 0 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.84), #ffffff 34%);
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    height: auto;
    min-height: 82px;
  }

  .top-progress {
    grid-column: 1 / -1;
    padding-bottom: 14px;
  }

  .workspace {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .score-panel {
    grid-column: 1 / -1;
    position: static;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 860px) {
  .topbar {
    padding: 14px;
    gap: 12px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .workspace {
    display: block;
    padding: 14px;
  }

  .topic-rail {
    display: none;
    position: static;
    min-height: 0;
    margin-bottom: 14px;
  }

  .topic-rail.is-open {
    display: block;
  }

  .hero-card {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .hero-card img {
    max-height: 180px;
  }

  .question-card {
    padding: 18px;
  }

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

  .confidence-options {
    grid-template-columns: 1fr;
  }

  .confidence-options button {
    border-right: 0;
  }

  .card-actions,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .check-button {
    min-width: 0;
  }

  .score-panel {
    grid-template-columns: 1fr;
    margin-top: 14px;
  }

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

@media print {
  .topbar,
  .topic-rail,
  .hero-card,
  .question-card,
  .score-panel,
  .dialog-actions,
  .icon-close {
    display: none !important;
  }

  body {
    background: white;
  }

  .result-dialog {
    position: static;
    width: auto;
    max-height: none;
    border: 0;
    box-shadow: none;
  }
}
