/* Atomic structure quiz — matches Uni+ Worksheet Generator (equation practice) */
:root {
  --bg-color: #fdfbf7;
  --element-bg: #f5efe6;
  --text-primary: #2c2420;
  --text-secondary: #5d544f;
  --border-color: rgba(0, 0, 0, 0.06);
  --text: var(--text-primary) !important;
  --text-muted: var(--text-secondary) !important;
  --bg: var(--bg-color) !important;
  --surface: var(--element-bg) !important;
  --border: var(--border-color) !important;
  --border-soft: rgba(0, 0, 0, 0.1) !important;
  --primary: var(--text-primary) !important;
  --primary-hover: #1a1512 !important;
  --ok: #047857 !important;
  --bad: #b91c1c !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg-color) !important;
  color: var(--text-primary) !important;
  font-family: system-ui, "Segoe UI", "Microsoft JhengHei", 微軟正黑體, sans-serif;
}

#root {
  max-width: none !important;
  min-height: 0 !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  margin: 0 !important;
  padding: 20px !important;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--bg-color) !important;
}

.app {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Start screen (menu) ── */
.app-main:has(.card) {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.app-main:has(.card) .card {
  background: var(--element-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 1.5rem 1.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  max-width: 420px;
  width: 100%;
}

.app-main:has(.card) .btn--primary {
  width: 100%;
  margin-top: 0.75rem;
}

/* ── Quiz: 2-column worksheet layout (controls | preview) ── */
.app:has(.quiz) {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  gap: 10px 20px;
  height: 100%;
  min-height: 0;
  align-content: stretch;
}

.app:has(.quiz) .app-main,
.app:has(.quiz) .quiz,
.app:has(.quiz) .quiz__layout {
  display: contents;
}

.app:has(.quiz) .app-header {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  background: var(--element-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 12px 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  margin: 0;
  border-bottom: none !important;
}

.app:has(.quiz) .app-header__titles h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary) !important;
  margin: 0 0 4px !important;
}

.app:has(.quiz) .app-header__sub {
  font-size: 0.8rem;
  color: var(--text-secondary) !important;
  line-height: 1.4;
  margin: 0 !important;
}

.app:has(.quiz) .lang-switch {
  margin-top: 10px;
  flex-wrap: wrap;
  gap: 6px;
}

.app:has(.quiz) .lang-switch__label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary) !important;
}

.app:has(.quiz) .quiz__progress {
  grid-column: 1;
  grid-row: 2;
  margin: 0;
  padding: 0 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.app:has(.quiz) .quiz__hint {
  grid-column: 1;
  grid-row: 3;
  margin: 0;
  padding: 8px 12px;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-secondary);
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

.app:has(.quiz) .progress-sidebar {
  grid-column: 1;
  grid-row: 4;
  min-height: 0;
  height: auto;
  align-self: stretch;
}

.app:has(.quiz) .progress-sidebar__card {
  background: var(--element-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 12px 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app:has(.quiz) .progress-sidebar__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem !important;
}

.app:has(.quiz) .progress-sidebar__stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.app:has(.quiz) .progress-sidebar__list {
  gap: 0.35rem !important;
}

.app:has(.quiz) .progress-sidebar__item {
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-color);
}

.app:has(.quiz) .progress-sidebar__item--current {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* Right panel — worksheet-preview */
.app:has(.quiz) .quiz__row {
  grid-column: 2;
  grid-row: 1 / 5;
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 20px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--element-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  padding: 20px 22px;
  overflow: hidden;
  align-self: stretch;
  align-items: center;
}

.app:has(.quiz) .notation-tile {
  width: min(100%, 280px);
  height: min(100%, 280px);
  max-width: 280px;
  max-height: 280px;
  aspect-ratio: 1;
  align-self: center;
  justify-self: center;
  border: 2px solid var(--border-color);
  border-radius: 18px;
  background: var(--bg-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.app:has(.quiz) .notation-tile__mass,
.app:has(.quiz) .notation-tile__z {
  font-size: 1.15rem !important;
}

.app:has(.quiz) .notation-tile__symbol {
  font-size: clamp(2.25rem, 5dvh, 3.25rem) !important;
}

.app:has(.quiz) .bohr-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px 14px !important;
  overflow: hidden;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: none;
}

.app:has(.quiz) .bohr-wrap__title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem !important;
}

.app:has(.quiz) .bohr-controls {
  flex-shrink: 0;
  margin-bottom: 0.5rem !important;
  gap: 6px !important;
}

.app:has(.quiz) .bohr-svg {
  width: 100%;
  max-width: min(100%, 420px);
  height: auto;
  max-height: clamp(200px, 36dvh, 360px);
  min-height: 0;
  flex: 1 1 auto;
  display: block;
  margin: 0 auto;
}

.app:has(.quiz) .bohr-nucleus-q {
  font-size: 22px !important;
  fill: var(--text-primary) !important;
}

.app:has(.quiz) .bohr-electron {
  font-size: 32px !important;
  fill: var(--text-primary) !important;
  font-weight: 800 !important;
}

.app:has(.quiz) .bohr-shell {
  stroke: #475569 !important;
  stroke-width: 2.5px;
  opacity: 0.85;
}

.app:has(.quiz) .shell-boxes {
  flex-shrink: 0;
  gap: 0.4rem !important;
  margin: 0.4rem 0 0 !important;
}

.app:has(.quiz) .shell-box {
  min-height: 44px !important;
  padding: 0.35rem 0.5rem !important;
  border: 1.5px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-color);
}

.app:has(.quiz) .bohr-meta {
  flex-shrink: 0;
  margin: 0.35rem 0 0 !important;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.app:has(.quiz) .quiz__actions {
  grid-column: 2;
  grid-row: 5;
  position: static;
  flex-shrink: 0;
  margin: 0 !important;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: transparent;
  border: none;
  box-shadow: none;
}

.app:has(.quiz) .quiz .feedback {
  grid-column: 2;
  grid-row: 6;
  margin: 0;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
}

/* Buttons — match worksheet option-btn / generate-btn */
.btn {
  padding: 7px 14px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lang-btn,
.btn--secondary,
.btn--ghost,
.bohr-controls .btn {
  border: 1.5px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-secondary);
}

.lang-btn:hover,
.btn--secondary:hover:not(:disabled),
.btn--ghost:hover:not(:disabled),
.bohr-controls .btn:hover:not(:disabled) {
  border-color: var(--text-secondary);
  background: #fff;
  color: var(--text-primary);
}

.lang-btn--active {
  background: var(--text-primary) !important;
  border-color: var(--text-primary) !important;
  color: var(--bg-color) !important;
}

.btn--primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 0.85rem;
}

.btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.lead {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.notation-tile__symbol:placeholder-shown {
  background: var(--bg-color);
  box-shadow: inset 0 0 0 1.5px var(--border-color);
}

.notation-tile__symbol:focus-visible {
  outline: 3px solid rgba(44, 36, 32, 0.15);
}

.progress-sidebar__item--ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.progress-sidebar__item--bad {
  background: #fef2f2;
  border-color: #fecaca;
}

.app:has(.quiz) .shell-box__e {
  color: var(--text-primary) !important;
  border: 2px solid var(--text-primary) !important;
  background: var(--bg-color);
  font-weight: 900;
}

.shell-box__e {
  color: var(--text-primary);
  border: 2px solid var(--text-primary);
  border-radius: 8px;
  background: var(--bg-color);
  font-weight: 900;
}

.feedback--ok {
  color: var(--ok);
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}

.feedback--bad {
  color: var(--bad);
  background: #fef2f2;
  border: 1px solid #fecaca;
}

/* Results screen */
.app-main:has(.results) {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0;
}

.results {
  background: var(--element-bg);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.results h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.results__score {
  color: var(--text-primary);
}

.results__summary {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  border-color: var(--border-color);
  font-size: 0.85rem;
}

.data-table th {
  background: var(--element-bg);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.reason-tag {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.8rem;
}

@media (max-width: 900px) {
  #root {
    padding: 12px !important;
  }

  .app:has(.quiz) {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .app:has(.quiz) .app-header,
  .app:has(.quiz) .quiz__progress,
  .app:has(.quiz) .quiz__hint,
  .app:has(.quiz) .progress-sidebar,
  .app:has(.quiz) .quiz__row,
  .app:has(.quiz) .quiz__actions,
  .app:has(.quiz) .quiz .feedback {
    grid-column: 1;
    grid-row: auto;
  }

  .app:has(.quiz) .quiz__row {
    grid-template-columns: 1fr;
    height: auto;
  }

  .app:has(.quiz) .notation-tile {
    max-width: 240px;
    max-height: 240px;
  }

  .app:has(.quiz) .progress-sidebar__list {
    grid-template-columns: repeat(10, 1fr) !important;
  }
}

@media (max-height: 700px) {
  #root {
    padding: 10px !important;
  }

  .app:has(.quiz) {
    gap: 6px 14px;
  }

  .app:has(.quiz) .app-header__titles h1 {
    font-size: 1.1rem;
  }

  .app:has(.quiz) .bohr-svg {
    max-height: clamp(160px, 28dvh, 260px);
  }
}
