:root {
  color-scheme: light;
  --ink: #171511;
  --ink-soft: #333a39;
  --muted: #65706c;
  --paper: #f2f3ee;
  --paper-strong: #fffdf6;
  --field: #e3ebe6;
  --line: #bbc6c0;
  --line-strong: #7f8c87;
  --accent: #b83a29;
  --accent-dark: #7f2218;
  --teal: #1d6f72;
  --blue: #254f7d;
  --green: #17764b;
  --green-soft: #d8eee4;
  --red: #bd2e25;
  --red-soft: #f3d7d2;
  --gold: #b17622;
  --shadow: 0 24px 70px rgba(23, 21, 17, 0.18);
  --radius: 8px;
  --serif: Georgia, "Times New Roman", "Noto Serif SC", "Songti SC", SimSun, serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(37, 79, 125, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 21, 17, 0.06) 1px, transparent 1px),
    linear-gradient(135deg, #e1ebe7 0%, #f3f2ea 46%, #d9e1ea 100%);
  background-size: 34px 34px, 34px 34px, auto;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  width: 1.08rem;
  height: 1.08rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.icon-sprite {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 10px 0 18px;
}

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

.brand img {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(23, 21, 17, 0.22);
}

.brand-name {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.brand-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-strong);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
  user-select: none;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  border-color: var(--ink);
  outline: none;
  box-shadow: 0 12px 26px rgba(23, 21, 17, 0.14);
}

.button:active {
  transform: translateY(0);
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffdf6;
}

.button.ghost {
  background: rgba(255, 253, 246, 0.58);
}

.button.danger {
  border-color: var(--red);
  background: #fff4f2;
  color: var(--red);
}

.button.favorite {
  border-color: var(--gold);
  color: var(--gold);
}

.button.favorite svg {
  fill: currentColor;
}

.button.full {
  width: 100%;
}

.button:disabled,
.segmented button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.option-button:disabled {
  cursor: not-allowed;
  opacity: 1;
  transform: none;
  box-shadow: none;
}

.workspace {
  min-height: calc(100vh - 118px);
}

.empty-state {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  align-items: stretch;
  gap: 18px;
  min-height: calc(100vh - 132px);
}

.empty-copy,
.drop-zone {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 246, 0.74);
  box-shadow: var(--shadow);
}

.empty-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 42px;
}

.empty-copy h1 {
  max-width: 760px;
  margin: 10px 0 12px;
  font-size: 3.4rem;
  line-height: 1.05;
}

.empty-copy p {
  max-width: 620px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.1rem;
}

.eyebrow,
.panel-label {
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 320px;
  padding: 30px;
  color: var(--blue);
  cursor: pointer;
  text-align: center;
  transition:
    transform 180ms ease,
    background 180ms ease,
    border-color 180ms ease;
}

.drop-zone svg {
  width: 4rem;
  height: 4rem;
  stroke-width: 1.5;
}

.drop-zone:hover,
.drop-zone.drag-over {
  transform: translateY(-2px);
  border-color: var(--blue);
  background: #eef4f1;
}

.quiz-state {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.control-panel {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 246, 0.82);
  box-shadow: 0 18px 54px rgba(23, 21, 17, 0.13);
}

.control-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mobile-controls-toggle {
  display: none;
}

.dataset-panel,
.control-section {
  padding: 14px;
  border: 1px solid rgba(127, 140, 135, 0.55);
  border-radius: var(--radius);
  background: rgba(242, 243, 238, 0.72);
}

.dataset-panel strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 1.15rem;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0 0;
}

.score-grid div {
  min-width: 0;
  padding: 8px;
  border-left: 3px solid var(--line-strong);
  background: rgba(255, 253, 246, 0.72);
}

.score-grid dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.score-grid dd {
  margin: 2px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
}

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

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 38px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.segmented button.active {
  border-color: var(--line-strong);
  background: var(--paper-strong);
  color: var(--accent-dark);
  box-shadow: 0 6px 16px rgba(23, 21, 17, 0.1);
}

.type-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}

.type-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 246, 0.72);
  cursor: pointer;
  text-align: left;
}

.type-button.active {
  border-color: var(--accent);
  background: #fff4e9;
  color: var(--accent-dark);
}

.type-button span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-button span:last-child {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.84rem;
}

.switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0 48px;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.switch-row input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-row i {
  position: relative;
  display: block;
  width: 48px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--field);
  transition: background 160ms ease;
}

.switch-row i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--paper-strong);
  box-shadow: 0 2px 8px rgba(23, 21, 17, 0.22);
  transition: transform 160ms ease;
}

.switch-row input:checked + i {
  border-color: var(--teal);
  background: var(--teal);
}

.switch-row input:checked + i::after {
  transform: translateX(20px);
}

.action-stack {
  display: grid;
  gap: 8px;
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.map-head span:last-child {
  color: var(--muted);
  font-size: 0.84rem;
}

.question-map {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  max-height: 216px;
  margin-top: 10px;
  overflow: auto;
  padding-right: 2px;
}

.map-button {
  position: relative;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 246, 0.7);
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.map-button.current {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffdf6;
}

.map-button.answered:not(.current) {
  border-color: var(--blue);
}

.map-button.correct:not(.current) {
  border-color: var(--green);
  background: var(--green-soft);
}

.map-button.wrong:not(.current) {
  border-color: var(--red);
  background: var(--red-soft);
}

.map-button.favorite::after {
  content: "";
  position: absolute;
  right: 4px;
  top: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
}

.stage {
  min-width: 0;
}

.question-card {
  position: relative;
  min-height: calc(100vh - 132px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent 0, transparent 54px, rgba(184, 58, 41, 0.18) 55px, transparent 56px),
    repeating-linear-gradient(0deg, rgba(37, 79, 125, 0.06) 0 1px, transparent 1px 33px),
    rgba(255, 253, 246, 0.94);
  box-shadow: var(--shadow);
}

.question-card.correct-flash {
  animation: correctPulse 700ms ease;
}

.question-card.wrong-flash {
  animation: wrongPulse 700ms ease;
}

.question-inner {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: inherit;
  padding: 34px 38px 30px 82px;
}

.question-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.question-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 253, 246, 0.8);
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.chip.type {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-strong);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  transform: translateY(-1px);
  border-color: var(--ink);
  outline: none;
}

.icon-button.favorite {
  color: var(--gold);
}

.icon-button.favorite svg {
  fill: currentColor;
}

.question-text {
  max-width: 980px;
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.question-text mark {
  padding: 0 4px;
  border-radius: 4px;
  background: #ffe6ab;
  color: var(--ink);
}

.option-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.option-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
  width: 100%;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 246, 0.78);
  cursor: pointer;
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.option-button:hover:not(:disabled),
.option-button:focus-visible:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--ink);
  outline: none;
  box-shadow: 0 12px 26px rgba(23, 21, 17, 0.11);
}

.option-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--field);
  font-weight: 700;
}

.option-main {
  min-width: 0;
}

.option-word {
  display: block;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 1.16rem;
  font-weight: 700;
}

.option-translation {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.96rem;
  overflow-wrap: anywhere;
}

.option-button.selected {
  border-color: var(--blue);
  background: #eef3f7;
}

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

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

.option-button.correct .option-key {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.option-button.wrong .option-key {
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.verdict {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 1.08rem;
  font-weight: 700;
}

.verdict.show {
  display: flex;
}

.verdict.correct {
  border: 1px solid var(--green);
  background: var(--green-soft);
  color: #0e5536;
}

.verdict.wrong {
  border: 1px solid var(--red);
  background: var(--red-soft);
  color: #812019;
}

.question-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
}

.question-actions .cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-card {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 132px);
  padding: 30px;
  text-align: center;
}

.empty-card p {
  max-width: 420px;
  margin: 8px 0 0;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  max-width: min(520px, calc(100% - 28px));
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fffdf6;
  box-shadow: 0 20px 46px rgba(23, 21, 17, 0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes correctPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(23, 118, 75, 0.46), var(--shadow);
  }
  45% {
    box-shadow: 0 0 0 13px rgba(23, 118, 75, 0), var(--shadow);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

@keyframes wrongPulse {
  0%,
  100% {
    transform: translateX(0);
  }
  18% {
    transform: translateX(-7px);
  }
  36% {
    transform: translateX(7px);
  }
  54% {
    transform: translateX(-5px);
  }
  72% {
    transform: translateX(5px);
  }
}

@media (max-width: 1080px) {
  .quiz-state {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .option-list {
    grid-template-columns: 1fr;
  }

  .question-inner {
    padding: 30px 28px 28px 72px;
  }
}

@media (max-width: 840px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    gap: 10px;
    min-height: 0;
    padding: 4px 0 10px;
  }

  .top-actions {
    width: auto;
    justify-content: flex-end;
    flex: 0 0 auto;
    gap: 6px;
  }

  .top-actions .button,
  .upload-trigger {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 10px;
  }

  .top-actions .button span,
  .upload-trigger span {
    display: none;
  }

  .brand {
    flex: 1 1 auto;
  }

  .brand-name {
    font-size: 1.62rem;
  }

  .brand-subtitle {
    display: none;
  }

  .brand img {
    width: 42px;
    height: 42px;
  }

  .empty-state,
  .quiz-state {
    grid-template-columns: 1fr;
  }

  .empty-state {
    min-height: auto;
  }

  .empty-copy,
  .drop-zone {
    min-height: 260px;
  }

  .empty-copy {
    padding: 28px;
  }

  .empty-copy h1 {
    font-size: 2.35rem;
  }

  .control-panel {
    position: sticky;
    top: 0;
    z-index: 12;
    gap: 8px;
    max-height: none;
    overflow: visible;
    padding: 8px;
    border-color: var(--line-strong);
    background: rgba(255, 253, 246, 0.94);
    box-shadow: 0 12px 36px rgba(23, 21, 17, 0.16);
  }

  .dataset-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
  }

  .dataset-panel strong {
    margin-top: 0;
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .score-grid {
    grid-template-columns: repeat(4, minmax(34px, 1fr));
    gap: 5px;
    min-width: min(48vw, 220px);
    margin: 0;
  }

  .score-grid div {
    padding: 5px 6px;
    border-left-width: 2px;
  }

  .score-grid dt {
    font-size: 0.68rem;
  }

  .score-grid dd {
    font-size: 1rem;
  }

  .mobile-controls-toggle {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--ink);
    color: #fffdf6;
    cursor: pointer;
    text-align: left;
  }

  .mobile-controls-toggle strong {
    min-width: 0;
    overflow: hidden;
    color: #f4d6a0;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-controls-toggle::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 160ms ease;
  }

  .control-panel.mobile-controls-open .mobile-controls-toggle::after {
    transform: rotate(225deg);
  }

  .control-body {
    display: none;
  }

  .control-panel.mobile-controls-open .control-body {
    display: flex;
    max-height: min(62vh, 520px);
    overflow: auto;
    padding-right: 2px;
  }

  .control-section {
    padding: 10px;
  }

  .question-map {
    max-height: 164px;
  }

  .question-card,
  .empty-card {
    min-height: 0;
  }

  .question-inner {
    gap: 16px;
    min-height: 0;
    padding: 18px;
  }

  .question-card {
    background:
      repeating-linear-gradient(0deg, rgba(37, 79, 125, 0.06) 0 1px, transparent 1px 33px),
      rgba(255, 253, 246, 0.96);
  }

  .question-top,
  .question-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .question-actions {
    margin-top: 0;
    padding-top: 0;
  }

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

  .question-actions .cluster .button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 15px;
  }

  .brand-name {
    font-size: 1.38rem;
  }

  .brand img {
    width: 38px;
    height: 38px;
  }

  .score-grid {
    grid-template-columns: repeat(4, minmax(32px, 1fr));
    min-width: 148px;
  }

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

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

  .segmented button {
    min-height: 34px;
    padding: 6px 5px;
  }

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

  .question-text {
    font-size: 1.28rem;
  }

  .option-button {
    grid-template-columns: 36px minmax(0, 1fr);
    min-height: 78px;
  }

  .option-key {
    width: 36px;
    height: 36px;
  }

  .option-word {
    font-size: 1.06rem;
  }
}

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