:root {
  --bg-color: #f8fafc;
  --brand-color: #4f46e5;
  --brand-color-dark: #4338ca;
  --text-main: #0f172a;
  --text-body: #475569;
  --text-muted: #94a3b8;
  --border: rgba(226, 232, 240, 0.8);
  --border-strong: rgba(203, 213, 225, 0.9);
  --glass: rgba(255, 255, 255, 0.85);
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px -2px rgba(0, 0, 0, 0.01);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -4px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12);
  --radius: 28px;
  --radius-sm: 16px;
  --success: #10b981;
  --danger: #f43f5e;
  --font-body: "Inter", "Noto Sans KR", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(640px 380px at 0% 0%, rgba(79, 70, 229, 0.08), transparent 60%),
    radial-gradient(520px 420px at 100% 20%, rgba(15, 23, 42, 0.06), transparent 60%),
    linear-gradient(120deg, #f8fafc 0%, #f9fbff 45%, #f8fafc 100%);
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 160px;
  display: grid;
  gap: 28px;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.bento-card {
  background: white;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bento-card:hover {
  border-color: rgba(79, 70, 229, 0.2);
  box-shadow: var(--shadow-md);
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid rgba(226, 232, 240, 0.4);
}

.nav__inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: #0f172a;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.2);
}

.brand-icon::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--brand-color);
}

.brand-text {
  display: grid;
  gap: 2px;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.nav__right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(226, 232, 240, 0.7);
  padding: 6px 10px;
  border-radius: 999px;
}

.auth-user {
  display: grid;
  gap: 2px;
  text-align: right;
}

.user-email {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.auth-hint {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.auth-hint[data-state="error"] {
  color: var(--danger);
}

.auth-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.auth-inline button {
  padding: 8px 12px;
  font-size: 0.7rem;
  border-radius: 10px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  color: var(--brand-color);
  border-color: rgba(79, 70, 229, 0.3);
  background: rgba(79, 70, 229, 0.08);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px 22px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat__label {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-weight: 800;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.stat__value {
  font-size: clamp(26px, 3vw, 38px);
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.stat__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

#sync-stat {
  position: relative;
}

#sync-stat .stat__indicator {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.18);
}

#sync-stat.error .stat__value {
  color: var(--danger);
}

#sync-stat.error .stat__indicator {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(244, 63, 94, 0.2);
}

.controls {
  display: grid;
  gap: 18px;
  padding: 24px;
  border-radius: var(--radius);
}

.control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-body);
}

.control label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-body);
}

.input-shell {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  box-sizing: border-box;
}

.input-icon::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 2px;
  background: #cbd5e1;
  right: -6px;
  bottom: -4px;
  transform: rotate(45deg);
  border-radius: 999px;
}

.control input,
.control select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-body);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.control--search input {
  padding-left: 44px;
}

.control input:focus,
.control select:focus {
  outline: none;
  border-color: rgba(79, 70, 229, 0.5);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
  transform: translateY(-1px);
}

.toggles {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding-top: 6px;
  border-top: 1px solid rgba(226, 232, 240, 0.7);
}

.toggles > span {
  font-weight: 600;
  color: var(--text-main);
  margin-right: auto;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-body);
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand-color);
}

button {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--brand-color);
  color: white;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  font-family: inherit;
}

button:hover {
  background: var(--brand-color-dark);
  box-shadow: 0 10px 24px rgba(79, 70, 229, 0.25);
  transform: translateY(-1px);
}

button:active {
  transform: scale(0.98);
}

button.secondary {
  background: white;
  color: var(--text-body);
  border-color: var(--border);
  box-shadow: none;
}

button.secondary:hover {
  background: #f8fafc;
  border-color: var(--border-strong);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

#grade-btn {
  padding: 11px 22px;
  font-size: 0.85rem;
  box-shadow: 0 12px 26px rgba(79, 70, 229, 0.3);
}

#reset-btn {
  color: var(--danger);
  border-color: rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.08);
}

#reset-btn:hover {
  background: rgba(244, 63, 94, 0.14);
  border-color: rgba(244, 63, 94, 0.5);
  box-shadow: 0 8px 18px rgba(244, 63, 94, 0.2);
}

button.icon-btn {
  padding: 0;
  background: white;
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: none;
}

button.icon-btn:hover {
  background: rgba(79, 70, 229, 0.08);
  border-color: rgba(79, 70, 229, 0.3);
  box-shadow: none;
}

button:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid rgba(79, 70, 229, 0.35);
  outline-offset: 2px;
}

.question-list {
  display: grid;
  gap: 24px;
}

.question-card {
  border-radius: calc(var(--radius) + 8px);
  padding: 28px;
  display: grid;
  gap: 16px;
  animation: fade-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: var(--delay, 0ms);
}

.question-card.correct {
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.12);
}

.question-card.incorrect {
  border-color: rgba(244, 63, 94, 0.4);
  box-shadow: 0 12px 30px rgba(244, 63, 94, 0.12);
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.question-header__left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.question-header__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.question-badge {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: #0f172a;
  color: white;
  font-weight: 800;
  font-size: 0.75rem;
  display: grid;
  place-items: center;
}

.question-kicker {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.question-status {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.question-status.correct {
  color: var(--success);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.question-status.incorrect {
  color: var(--danger);
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.2);
}

.question-points {
  background: rgba(79, 70, 229, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.6rem;
  color: var(--brand-color);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.meta span {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(248, 250, 252, 0.9);
  color: var(--text-muted);
  border: 1px solid rgba(226, 232, 240, 0.8);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.question-text {
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text-main);
  font-weight: 700;
}

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

.choice {
  position: relative;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(248, 250, 252, 0.7);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

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

.choice__badge {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  background: white;
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-muted);
  flex-shrink: 0;
}

.choice__text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-body);
}

.choice:hover {
  border-color: rgba(79, 70, 229, 0.3);
  background: rgba(79, 70, 229, 0.06);
  transform: translateY(-1px);
}

.choice:active {
  transform: scale(0.98);
}

.choice.selected {
  border-color: rgba(79, 70, 229, 0.6);
  background: rgba(79, 70, 229, 0.1);
  box-shadow: 0 10px 20px rgba(79, 70, 229, 0.15);
}

.choice.selected .choice__badge {
  border-color: rgba(79, 70, 229, 0.6);
  background: rgba(79, 70, 229, 0.14);
  color: var(--brand-color);
}

.choice.selected .choice__text {
  color: #3730a3;
}

.choice.correct {
  border-color: rgba(16, 185, 129, 0.7);
  background: rgba(16, 185, 129, 0.9);
}

.choice.correct .choice__badge,
.choice.correct .choice__text {
  color: white;
}

.choice.correct .choice__badge {
  background: rgba(255, 255, 255, 0.2);
  border-color: transparent;
}

.choice.incorrect {
  border-color: rgba(244, 63, 94, 0.7);
  background: rgba(244, 63, 94, 0.9);
}

.choice.incorrect .choice__badge,
.choice.incorrect .choice__text {
  color: white;
}

.choice.incorrect .choice__badge {
  background: rgba(255, 255, 255, 0.2);
  border-color: transparent;
}

.choice input:focus-visible + .choice__badge {
  border-color: rgba(79, 70, 229, 0.6);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

.choice input:focus-visible + .choice__badge + .choice__text {
  color: #3730a3;
}

.choice--pulse {
  animation: choice-pop 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.answer-block {
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(79, 70, 229, 0.08);
  border: 1px solid rgba(79, 70, 229, 0.2);
  font-size: 0.9rem;
}

.explanation {
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text-body);
  font-style: italic;
}

.short-answer {
  display: grid;
  gap: 12px;
}

.short-answer textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-body);
  background: white;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.short-answer textarea:focus {
  outline: none;
  border-color: rgba(79, 70, 229, 0.5);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
  transform: translateY(-1px);
}

.self-grade {
  display: flex;
  gap: 10px;
}

.self-grade button {
  flex: 1;
  background: white;
  color: var(--text-body);
  border: 1px solid var(--border);
  box-shadow: none;
}

.self-grade button:hover {
  transform: none;
  box-shadow: none;
}

.self-grade button.active.correct {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.16);
}

.self-grade button.active.incorrect {
  border-color: rgba(244, 63, 94, 0.5);
  background: rgba(244, 63, 94, 0.16);
}

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

.images img {
  max-width: 100%;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: white;
  box-shadow: var(--shadow-sm);
}

.footer {
  margin-top: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes choice-pop {
  0% {
    transform: scale(0.98);
  }
  60% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

.animate-fade-up {
  animation: fade-up 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.stagger-1 {
  animation-delay: 0.1s;
}

.stagger-2 {
  animation-delay: 0.2s;
}

.stagger-3 {
  animation-delay: 0.3s;
}

@media (min-width: 960px) {
  .controls {
    grid-template-columns: 2fr 1fr 1fr 1fr;
  }

  .control--search {
    grid-column: span 2;
  }

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

@media (max-width: 980px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .nav__right {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 24px 16px 140px;
  }

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

  .controls {
    padding: 20px;
  }

  .nav__right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .nav__actions {
    justify-content: flex-start;
  }

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

  .auth-inline {
    width: 100%;
    justify-content: space-between;
  }

  .auth-user {
    text-align: left;
  }

  .question-card {
    padding: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .question-card,
  .stat-card,
  .controls {
    animation: none !important;
  }

  .choice,
  button,
  .bento-card {
    transition: none;
  }

  .choice--pulse {
    animation: none;
  }
}
