@font-face {
  font-family: "UnifrakturMaguntia";
  src: url("assets/fonts/UnifrakturMaguntia-Book.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  font-family: "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  --accent: #1457d1;
  --accent-soft: rgba(20, 87, 209, 0.1);
  --surface: #ffffff;
  --surface-dark: #1f1f1f;
  --border: #d0d7de;
  --border-dark: #2d2d2d;
  --danger: #d1202f;
  --danger-soft: rgba(209, 32, 47, 0.12);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

body {
  margin: 0;
  background: linear-gradient(180deg, #f5f7fb 0%, #f7f9fc 100%);
  color: #111926;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  caret-color: transparent;
}

body.dark {
  background: linear-gradient(180deg, #121212 0%, #1a1a1a 100%);
  color: #f5f5f5;
}

.app-header,
.app-footer {
  padding: 1rem clamp(1rem, 2vw, 2rem);
  background-color: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

body.dark .app-header,
body.dark .app-footer {
  background-color: rgba(31, 31, 31, 0.85);
  border-bottom: 1px solid var(--border-dark);
}

.app-header h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-family: "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.04em;
}

.app-header h1 .brand-name {
  font-family: 'UnifrakturMaguntia', 'Old English Text MT', Georgia, serif;
}

.app-header h2.app-subtitle {
  margin: 0 0 0.5rem;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 400;
  color: var(--accent);
  opacity: 0.9;
}

body.dark .app-header h2.app-subtitle {
  color: #64a3ff;
}

.app-header p {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  opacity: 0.8;
}

.intro-content {
  margin-top: 1.5rem;
}

.intro-content p {
  margin: 0 0 1rem;
  font-size: 1rem;
  line-height: 1.6;
  opacity: 0.9;
  text-align: justify;
}

.intro-content p:last-child {
  margin-bottom: 0;
}

.intro-content-section {
  margin: 2rem auto;
  padding: 2rem;
  background-color: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

body.dark .intro-content-section {
  background-color: rgba(31, 31, 31, 0.85);
  border-color: var(--border-dark);
}

.intro-content-section h2 {
  margin: 0 0 1.5rem;
  font-size: 1.5rem;
  color: var(--accent);
}

body.dark .intro-content-section h2 {
  color: #64a3ff;
}

.intro-content-section h3 {
  margin: 2rem 0 1rem;
  font-size: 1.25rem;
  color: var(--accent);
  font-weight: 600;
}

body.dark .intro-content-section h3 {
  color: #64a3ff;
}

.app-main {
  flex: 1;
  width: min(960px, 90vw);
  margin: 1rem auto 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (max-width: 768px) {
  .app-main {
    margin: 0.5rem auto 1rem;
    gap: 0.75rem;
  }
}

.control-panel {
  background-color: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.control-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease;
}

.control-panel-header:hover {
  background-color: rgba(20, 87, 209, 0.05);
}

.control-panel-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.chevron {
  font-size: 1rem;
  transition: opacity 0.2s ease;
}

.toggle-button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--accent);
  padding: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  line-height: 1;
  user-select: none;
}

.toggle-button:hover {
  transform: scale(1.2);
}

.toggle-button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.control-panel-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0.75rem;
  padding: 1rem clamp(1rem, 2vw, 1.25rem);
  transition: max-height 0.3s ease, padding 0.3s ease;
  overflow: hidden;
  max-height: 500px;
}

.control-panel.collapsed .control-panel-content {
  max-height: 0;
  padding: 0 clamp(1rem, 2vw, 1.25rem);
}

.control-panel.collapsed .control-panel-header {
  border-bottom: none;
}

.control-panel.collapsed .toggle-button {
  transform: rotate(180deg);
}

@media (max-width: 768px) {
  .control-panel-content {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    padding: 0.75rem;
    max-height: 400px;
  }
  
  .control-panel.collapsed .control-panel-content {
    padding: 0 0.75rem;
    max-height: 0;
  }
}

body.dark .control-panel {
  background-color: var(--surface-dark);
  border: 1px solid var(--border-dark);
}

body.dark .control-panel-header {
  border-bottom: 1px solid var(--border-dark);
}

body.dark .control-panel.collapsed .control-panel-header {
  border-bottom: none;
}

body.dark .control-panel select,
body.dark .control-panel input,
body.dark .control-panel button {
  background-color: #111;
  color: #f3f4f6;
  border: 1px solid var(--border-dark);
}

.control-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .control-group {
    gap: 0.4rem;
    font-size: 0.85rem;
  }
}

.control-group label {
  font-weight: 600;
  min-width: 140px;
}

.control-panel select,
.control-panel input,
.control-panel button {
  font: inherit;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  background-color: #fff;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  font-size: 0.9rem;
}

input,
textarea,
select {
  caret-color: auto;
}

.control-panel select:focus,
.control-panel input:focus,
.control-panel button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.control-panel input {
  width: 120px;
  cursor: text;
}

.control-panel button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(20, 87, 209, 0.15);
}

.control-panel button.danger {
  border-color: var(--danger);
  color: var(--danger);
  background-color: var(--danger-soft);
}

.control-panel button.danger:hover {
  box-shadow: 0 8px 16px rgba(209, 32, 47, 0.15);
}

#status {
  min-height: 1rem;
  padding: 0 0.25rem;
  color: #475569;
  font-size: 0.9rem;
}

#status[data-state="info"] {
  color: #475569;
}

#status[data-state="error"] {
  color: var(--danger);
  font-weight: 600;
}

body.dark #status {
  color: #d1d5db;
}

.question-card {
  padding: clamp(1.25rem, 2.5vw, 1.5rem);
  border-radius: 16px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (max-width: 768px) {
  .question-card {
    padding: 1rem;
    gap: 0.75rem;
  }
}

body.dark .question-card {
  background-color: var(--surface-dark);
  border: 1px solid var(--border-dark);
}

.question-navigation {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.5rem;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-left {
  justify-content: flex-start;
}

.nav-right {
  justify-content: flex-end;
}

.section-info {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
}

.mark-button {
  background: none;
  border: 2px solid #6b7280;
  color: #6b7280;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mark-button.mark-known {
  border-color: #10b981;
  color: #10b981;
}

.mark-button.mark-known:hover {
  background-color: #10b981;
  color: white;
  transform: scale(1.1);
}

.mark-button.mark-known.active {
  background-color: #10b981;
  color: white;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
}

.mark-button.mark-unknown {
  border-color: #f59e0b;
  color: #f59e0b;
}

.mark-button.mark-unknown:hover {
  background-color: #f59e0b;
  color: white;
  transform: scale(1.1);
}

.mark-button.mark-unknown.active {
  background-color: #f59e0b;
  color: white;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.mark-button:active {
  transform: scale(0.95);
}

.mark-button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.mark-button:disabled:hover {
  background: none;
  transform: none;
}

.nav-arrow[style*="visibility: hidden"] {
  visibility: hidden !important;
}

@media (max-width: 768px) {
  .question-navigation {
    min-height: 2rem;
    gap: 0.4rem;
  }
  
  .nav-group {
    gap: 0.4rem;
  }
  
  .mark-button {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.2rem;
  }
}

.nav-arrow {
  background: none;
  border: 2px solid var(--accent);
  color: var(--accent);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
  .nav-arrow {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.5rem;
  }
  
  .section-info-container {
    gap: 0.4rem;
  }
}

.nav-arrow:hover {
  background-color: var(--accent);
  color: white;
  transform: scale(1.1);
}

.nav-arrow:active {
  transform: scale(0.95);
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.nav-arrow:disabled:hover {
  background: none;
  color: var(--accent);
  transform: none;
}

body.dark .nav-arrow {
  border-color: #60a5fa;
  color: #60a5fa;
}

body.dark .nav-arrow:hover {
  background-color: #60a5fa;
  color: #1a1a1a;
}

body.dark .mark-button.mark-known {
  border-color: #34d399;
  color: #34d399;
}

body.dark .mark-button.mark-known:hover {
  background-color: #34d399;
  color: #1a1a1a;
}

body.dark .mark-button.mark-known.active {
  background-color: #34d399;
  color: #1a1a1a;
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.3);
}

body.dark .mark-button.mark-unknown {
  border-color: #fbbf24;
  color: #fbbf24;
}

body.dark .mark-button.mark-unknown:hover {
  background-color: #fbbf24;
  color: #1a1a1a;
}

body.dark .mark-button.mark-unknown.active {
  background-color: #fbbf24;
  color: #1a1a1a;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3);
}

.question-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: #64748b;
}

body.dark .question-meta {
  color: #cbd5f5;
}

.question-text {
  margin: 0;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  line-height: 1.4;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.answers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.answer-option,
.answer-option * {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.answer-option {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(20, 87, 209, 0.03);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

body.dark .answer-option {
  border: 1px solid var(--border-dark);
  background: rgba(255, 255, 255, 0.04);
}

.answer-option:hover {
  border-color: var(--accent);
  background-color: var(--accent-soft);
}

.answer-option.selected {
  border-color: var(--accent);
  background-color: rgba(20, 87, 209, 0.18);
  color: #0b367f;
}

body.dark .answer-option.selected {
  color: #e0ecff;
}

.answer-option.correct {
  border-color: #15803d;
  background: rgba(21, 128, 61, 0.12);
  color: #14532d;
}

body.dark .answer-option.correct {
  border-color: #22c55e;
  color: #bbf7d0;
}

.answer-option.incorrect {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: #7f1d1d;
}

body.dark .answer-option.incorrect {
  border-color: #f87171;
  color: #fecaca;
}

.answer-key {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  min-width: 1.5ch;
  text-align: center;
}

.images {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.images img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  background-color: #f8fafc;
  cursor: zoom-in;
}

.images img:focus {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}

.image-lightbox[hidden] {
  display: none;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 1000;
}

.lightbox-content {
  position: relative;
  max-width: min(90vw, 960px);
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
}

.lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  border: none;
  background: #ffffff;
  color: #111926;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
}

.lightbox-close:focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

body.dark .lightbox-close {
  background: #1f1f1f;
  color: #f5f5f5;
}

body.lightbox-open {
  overflow: hidden;
}

.splash-screen {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 2000;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

body.dark .splash-screen {
  background: #0f172a;
}

.splash-screen img {
  max-width: min(60vw, 420px);
  width: 100%;
  height: auto;
  filter: drop-shadow(0 20px 45px rgba(15, 23, 42, 0.25));
}

.splash-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.splash-active {
  overflow: hidden;
}

@media (max-width: 768px) {
  .control-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .control-panel button,
  .control-panel select,
  .control-panel input {
    width: 100%;
  }

  .answers {
    gap: 0.5rem;
  }
}

/* Congratulations Modal */
.congratulations-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 3000;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.congratulations-modal[hidden] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.congratulations-content {
  background: #ffffff;
  border-radius: 16px;
  padding: 0;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  animation: congratsSlideIn 0.4s ease-out;
}

body.dark .congratulations-content {
  background: #1e293b;
  color: #f8fafc;
}

@keyframes congratsSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.congratulations-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 20px;
  color: #64748b;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 1;
}

.congratulations-close:hover {
  background: #f1f5f9;
  color: #334155;
}

body.dark .congratulations-close {
  color: #94a3b8;
}

body.dark .congratulations-close:hover {
  background: #334155;
  color: #f8fafc;
}

.congratulations-header {
  text-align: center;
  padding: 2rem 2rem 1rem;
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  border-radius: 16px 16px 0 0;
  color: white;
}

.congratulations-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: congratsBounce 1s ease-in-out;
}

@keyframes congratsBounce {
  0%, 20%, 60%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-20px);
  }
  80% {
    transform: translateY(-10px);
  }
}

.congratulations-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.congratulations-body {
  padding: 2rem;
}

.congratulations-message {
  font-size: 1.1rem;
  line-height: 1.6;
  margin: 0 0 2rem;
  text-align: center;
  color: #475569;
}

body.dark .congratulations-message {
  color: #cbd5e1;
}

.congratulations-stats {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 12px;
  text-align: center;
}

body.dark .congratulations-stats {
  background: #0f172a;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: #059669;
}

body.dark .stat-number {
  color: #10b981;
}

.stat-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

body.dark .stat-label {
  color: #94a3b8;
}

.stat-text {
  font-size: 1rem;
  font-weight: 600;
  color: #1e40af;
  padding: 0.5rem 1rem;
  background: #dbeafe;
  border-radius: 8px;
  display: inline-block;
}

body.dark .stat-text {
  color: #60a5fa;
  background: #1e3a8a;
}

.congratulations-actions {
  display: flex;
  gap: 1rem;
  flex-direction: column;
}

.congratulations-actions button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.btn-primary {
  background: #059669;
  color: white;
}

.btn-primary:hover {
  background: #047857;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.btn-secondary:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

body.dark .btn-secondary {
  background: #334155;
  color: #e2e8f0;
  border-color: #475569;
}

body.dark .btn-secondary:hover {
  background: #475569;
  border-color: #64748b;
}

@media (min-width: 640px) {
  .congratulations-actions {
    flex-direction: row;
  }
  
  .congratulations-stats {
    flex-direction: row;
    justify-content: space-around;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .congratulations-content {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
  }
  
  .congratulations-header {
    padding: 1.5rem 1.5rem 1rem;
  }
  
  .congratulations-icon {
    font-size: 3rem;
  }
  
  .congratulations-title {
    font-size: 1.5rem;
  }
  
  .congratulations-body {
    padding: 1.5rem;
  }
}
