:root {
  --ink: #132238;
  --ink-soft: #3a4a5c;
  --paper: #f3f0ea;
  --paper-2: #e7eef4;
  --card: rgba(255, 252, 247, 0.92);
  --line: rgba(19, 34, 56, 0.12);
  --accent: #0b6e4f;
  --accent-2: #c45c26;
  --good: #1b7f4a;
  --good-bg: #e7f6ee;
  --bad: #b42318;
  --bad-bg: #fdeceb;
  --shadow: 0 18px 50px rgba(19, 34, 56, 0.12);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, sans-serif;
}

[data-theme="dark"] {
  --ink: #e8eef5;
  --ink-soft: #9fb0c3;
  --paper: #101823;
  --paper-2: #0c1420;
  --card: rgba(23, 33, 48, 0.92);
  --line: rgba(232, 238, 245, 0.12);
  --accent: #3ecf95;
  --accent-2: #e8935a;
  --good: #3ecf95;
  --good-bg: rgba(62, 207, 149, 0.12);
  --bad: #ff7b6e;
  --bad-bg: rgba(255, 123, 110, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] body {
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #17283d 0%, transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, #2a1e14 0%, transparent 50%),
    linear-gradient(165deg, var(--paper) 0%, var(--paper-2) 100%);
  background-attachment: fixed;
}

[data-theme="dark"] .passage-box,
[data-theme="dark"] .sentence-error {
  background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .choice,
[data-theme="dark"] .back-btn,
[data-theme="dark"] .miss-item {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .score-chip {
  background: rgba(255, 255, 255, 0.07);
}

* {
  box-sizing: border-box;
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  display: none;
}

#theme-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.15rem;
  cursor: pointer;
  transition: transform 0.2s;
}

#theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #d9e8f2 0%, transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, #f0dfd0 0%, transparent 50%),
    linear-gradient(165deg, var(--paper) 0%, var(--paper-2) 100%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.hidden {
  display: none !important;
}

/* ——— Home ——— */
.hero {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  animation: rise 0.7s ease both;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1.25rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), #1a9b6c);
  box-shadow: 0 0 0 4px rgba(11, 110, 79, 0.15);
  animation: pulse 2.4s ease-in-out infinite;
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.hero h1 span {
  color: var(--accent-2);
}

.hero p {
  margin: 1rem auto 0;
  max-width: 34rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.7;
}

.credit {
  display: inline-block;
  margin-top: 1.15rem !important;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(11, 110, 79, 0.1);
  border: 1px solid rgba(11, 110, 79, 0.22);
  color: var(--accent) !important;
  font-size: 0.95rem !important;
  font-weight: 600;
}

.site-footer {
  margin-top: 2.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.section-grid {
  display: grid;
  gap: 1rem;
  margin-top: 2rem;
  animation: rise 0.8s 0.1s ease both;
}

.section-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1.25rem 1.35rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: right;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s;
}

.section-card:hover {
  transform: translateY(-3px);
  border-color: rgba(11, 110, 79, 0.35);
  box-shadow: 0 22px 55px rgba(19, 34, 56, 0.16);
}

.section-card:focus-visible {
  outline: 3px solid rgba(11, 110, 79, 0.4);
  outline-offset: 2px;
}

.sec-num {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  color: #fff;
  background: linear-gradient(145deg, var(--ink) 0%, #243752 100%);
}

.sec-num.alt {
  background: linear-gradient(145deg, var(--accent) 0%, #15936a 100%);
}

.sec-num.warm {
  background: linear-gradient(145deg, var(--accent-2) 0%, #d9783d 100%);
}

.sec-body h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.sec-body p {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.5;
}

.sec-meta {
  color: var(--ink-soft);
  font-size: 0.85rem;
  white-space: nowrap;
}

.best-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(232, 185, 49, 0.18);
  border: 1px solid rgba(232, 185, 49, 0.4);
  color: #9a7b0a;
  font-size: 0.78rem;
  font-weight: 700;
}

[data-theme="dark"] .best-badge {
  color: #e8b931;
}

.full-best {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.85;
}

.shuffle-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.9rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  cursor: pointer;
  user-select: none;
}

.shuffle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.full-btn {
  margin-top: 1rem;
  width: 100%;
  padding: 1rem 1.25rem;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--ink), #1f3550);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(19, 34, 56, 0.25);
  transition: transform 0.2s, filter 0.2s;
  animation: rise 0.85s 0.15s ease both;
}

.full-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.note {
  margin-top: 1.5rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.6;
}

/* ——— Quiz chrome ——— */
.quiz-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  animation: rise 0.45s ease both;
}

.back-btn,
.next-btn,
.restart-btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}

.back-btn {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.back-btn:hover {
  background: #fff;
}

.progress-wrap {
  flex: 1;
  min-width: 160px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.progress-bar {
  height: 8px;
  border-radius: 99px;
  background: rgba(19, 34, 56, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #2aa876);
  transition: width 0.35s ease;
}

.chip-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.score-chip {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
}

.score-chip.streak:empty {
  display: none;
}

.score-chip.streak {
  background: rgba(232, 147, 90, 0.18);
  border-color: rgba(196, 92, 38, 0.4);
  color: var(--accent-2);
  animation: pulse 1.2s ease-in-out infinite;
}

.quiz-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.4rem 1.35rem;
  animation: rise 0.45s ease both;
}

.passage-box {
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: linear-gradient(180deg, #f7fafc, #eef3f7);
  border: 1px solid var(--line);
  max-height: 280px;
  overflow: auto;
}

.passage-box h3 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.passage-box p {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
  direction: ltr;
  text-align: left;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.q-tag {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 8px;
  background: rgba(11, 110, 79, 0.1);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
}

.skill-tag {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 8px;
  background: rgba(196, 92, 38, 0.1);
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 600;
}

.sub-prompt {
  margin: -0.4rem 0 1.15rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.passage-details {
  margin-bottom: 1.25rem;
}

.passage-details summary {
  cursor: pointer;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  background: rgba(11, 110, 79, 0.08);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.92rem;
  user-select: none;
}

.passage-details[open] summary {
  border-radius: 10px 10px 0 0;
}

.question-text {
  margin: 0 0 1.15rem;
  font-size: 1.08rem;
  line-height: 1.7;
  direction: ltr;
  text-align: left;
  font-family: "IBM Plex Sans", var(--font-body);
}

.sentence-error {
  margin: 0 0 1.15rem;
  padding: 1rem;
  border-radius: 12px;
  background: #fbf8f3;
  border: 1px dashed rgba(19, 34, 56, 0.18);
  font-size: 1.05rem;
  line-height: 1.85;
  direction: ltr;
  text-align: left;
  font-family: "IBM Plex Sans", var(--font-body);
}

.sentence-error u,
.sentence-error .ul {
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}

.choices {
  display: grid;
  gap: 0.65rem;
}

.choice {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 0.75rem;
  align-items: start;
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  text-align: left;
  direction: ltr;
  font-family: "IBM Plex Sans", var(--font-body);
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--ink);
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.choice:hover:not(:disabled) {
  border-color: rgba(11, 110, 79, 0.45);
  transform: translateX(3px);
}

.choice:disabled {
  cursor: default;
}

.choice .letter {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(19, 34, 56, 0.06);
  font-weight: 700;
  font-size: 0.9rem;
}

.choice.correct {
  border-color: var(--good);
  background: var(--good-bg);
}

.choice.correct .letter {
  background: var(--good);
  color: #fff;
}

.choice.wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}

.choice.wrong .letter {
  background: var(--bad);
  color: #fff;
}

.choice.missed {
  border-color: var(--good);
  background: var(--good-bg);
  box-shadow: inset 0 0 0 1px rgba(27, 127, 74, 0.25);
}

.feedback {
  margin-top: 1.15rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  animation: slideUp 0.35s ease both;
}

.feedback.ok {
  background: var(--good-bg);
  border: 1px solid rgba(27, 127, 74, 0.25);
}

.feedback.no {
  background: var(--bad-bg);
  border: 1px solid rgba(180, 35, 24, 0.2);
}

.feedback-title {
  margin: 0 0 0.45rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.feedback.ok .feedback-title {
  color: var(--good);
}

.feedback.no .feedback-title {
  color: var(--bad);
}

.feedback p {
  margin: 0;
  line-height: 1.7;
  color: var(--ink);
  font-size: 0.95rem;
}

.feedback .correct-line {
  margin-top: 0.55rem;
  font-weight: 600;
  direction: ltr;
  text-align: left;
  font-family: "IBM Plex Sans", var(--font-body);
}

.feedback .correct-line.good {
  color: var(--good);
}

.rule-box {
  margin-top: 0.9rem;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  background: rgba(42, 127, 184, 0.08);
  border: 1px solid rgba(42, 127, 184, 0.25);
}

[data-theme="dark"] .rule-box {
  background: rgba(90, 160, 220, 0.1);
}

.rule-head {
  font-weight: 700;
  margin-bottom: 0.45rem;
  color: #1c6396;
}

[data-theme="dark"] .rule-head {
  color: #7cbdea;
}

.rule-en {
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.75;
  direction: ltr;
  display: inline-block;
}

.rule-box p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.75;
}

.rule-tip {
  margin-top: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  background: rgba(232, 185, 49, 0.14);
  font-size: 0.88rem;
  line-height: 1.6;
  font-weight: 600;
}

.kbd-hint {
  align-self: center;
  margin-inline-start: 0.6rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
}

.kbd-help {
  margin: 0.9rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  opacity: 0.8;
}

.actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 1.15rem;
}

.next-btn {
  padding: 0.8rem 1.35rem;
  border: none;
  background: linear-gradient(135deg, var(--accent), #15936a);
  color: #fff;
  box-shadow: 0 10px 24px rgba(11, 110, 79, 0.28);
}

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

/* ——— Results ——— */
.results {
  text-align: center;
  padding: 2rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}

.results h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2rem;
}

.big-score {
  margin: 1.25rem 0 0.5rem;
  font-family: var(--font-display);
  font-size: clamp(3rem, 8vw, 4.5rem);
  font-weight: 650;
  color: var(--accent);
  line-height: 1;
}

.results .sub {
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.restart-btn {
  padding: 0.85rem 1.4rem;
  border: none;
  background: var(--ink);
  color: #fff;
}

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

.new-best {
  display: inline-block;
  margin-top: 0.9rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  background: rgba(232, 185, 49, 0.18);
  border: 1px solid rgba(232, 185, 49, 0.45);
  color: #9a7b0a;
  font-weight: 700;
  animation: pulse 1.4s ease-in-out infinite;
}

[data-theme="dark"] .new-best {
  color: #e8b931;
}

.result-actions {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}

.skills-panel {
  margin-top: 1.75rem;
  padding: 1.1rem 1.2rem;
  border-radius: 14px;
  background: rgba(42, 127, 184, 0.06);
  border: 1px solid rgba(42, 127, 184, 0.18);
  text-align: right;
}

.skills-panel h3 {
  margin: 0 0 0.9rem;
  font-family: var(--font-display);
}

.skill-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 2fr 44px;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.skill-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.skill-name span {
  color: var(--ink-soft);
  font-weight: 400;
}

.skill-bar {
  height: 10px;
  border-radius: 99px;
  background: rgba(19, 34, 56, 0.1);
  overflow: hidden;
}

[data-theme="dark"] .skill-bar {
  background: rgba(255, 255, 255, 0.1);
}

.skill-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 0.6s ease;
}

.skill-fill.hi {
  background: linear-gradient(90deg, var(--good), #2aa876);
}

.skill-fill.mid {
  background: linear-gradient(90deg, #e8b931, #d9a520);
}

.skill-fill.lo {
  background: linear-gradient(90deg, var(--bad), #d9534a);
}

.skill-pct {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: left;
}

.skill-advice {
  margin: 0.9rem 0 0;
  font-size: 0.9rem;
  line-height: 1.6;
}

.missed-list {
  margin-top: 1.75rem;
  text-align: right;
}

.missed-list h3 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
}

.miss-item {
  padding: 0.85rem 1rem;
  margin-bottom: 0.55rem;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.9rem;
  line-height: 1.55;
}

.miss-item strong {
  color: var(--bad);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 4px rgba(11, 110, 79, 0.15);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 0 7px rgba(11, 110, 79, 0.08);
  }
}

@media (max-width: 640px) {
  .section-card {
    grid-template-columns: auto 1fr;
  }

  .sec-meta {
    display: none;
  }

  .quiz-card {
    padding: 1.15rem 1rem;
  }

  .passage-box {
    max-height: 220px;
  }
}
