/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1a1a2e;
  background: #f0f0f5;
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== App Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: #1a1a2e;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.app-nav { display: flex; gap: .5rem; }

.nav-btn {
  background: transparent;
  color: #aab;
  border: 1px solid transparent;
  padding: .4rem 1rem;
  border-radius: 6px;
  font-size: .875rem;
  cursor: pointer;
  transition: all .2s;
}
.nav-btn:hover { color: #fff; border-color: #555; }
.nav-btn.active { color: #fff; background: #2d2d4a; border-color: #444; }
.nav-link { text-decoration: none; display: inline-block; }

/* ===== Sections ===== */
.section { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.hidden { display: none !important; }

/* ===== Welcome / Completion Screen ===== */
.welcome-card {
  max-width: 560px;
  margin: 4rem auto;
  text-align: center;
  background: #fff;
  padding: 2.5rem 2rem;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.welcome-card h2 { font-size: 1.5rem; margin-bottom: .75rem; }
.welcome-card p { margin-bottom: 1rem; color: #444; }
.welcome-alt { margin-top: .5rem; font-size: .85rem; }
.welcome-alt a { color: #555; text-decoration: none; border-bottom: 1px solid #ccc; transition: border-color .2s; }
.welcome-alt a:hover { border-bottom-color: #555; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: .6rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: #4361ee; color: #fff; }
.btn-primary:hover { background: #3a56d4; }

.btn-secondary { background: #e0e0e8; color: #1a1a2e; }
.btn-secondary:hover { background: #d0d0db; }

.btn-sm { padding: .35rem .9rem; font-size: .8rem; }

/* ===== Round Header ===== */
.round-header {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.round-category {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  background: #4361ee;
  color: #fff;
  padding: .2rem .6rem;
  border-radius: 4px;
  font-weight: 600;
}

.round-title { font-size: 1.25rem; flex: 1; }
.round-progress { font-size: .85rem; color: #888; }

/* ===== Round Body: Preview + Checklist ===== */
.round-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 768px) {
  .round-body { grid-template-columns: 1fr; }
}

.round-body.wide-preview {
  grid-template-columns: 1fr;
}
.round-body.wide-preview .iframe-wrapper {
  aspect-ratio: 16 / 7;
}

/* ===== Preview Pane ===== */
.preview-pane { position: relative; }

.iframe-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #ddd;
  background: #fff;
}

.iframe-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.preview-label {
  display: inline-block;
  margin-top: .5rem;
  font-size: .8rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 4px;
}
.preview-label.is-bad { background: #fee2e2; color: #b91c1c; }
.preview-label.is-good { background: #dcfce7; color: #15803d; }

/* ===== Preview Toggle ===== */
.preview-toggle {
  margin-top: .5rem;
  display: flex;
  justify-content: center;
}

/* ===== Checklist Pane ===== */
.checklist-pane h3 { font-size: 1.05rem; margin-bottom: .25rem; }
.checklist-hint { font-size: .85rem; color: #666; margin-bottom: .75rem; }

.checklist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: 1rem;
}

.checklist-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: .25rem .5rem;
  padding: .6rem .75rem;
  background: #fff;
  border: 2px solid #e0e0e8;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.checklist-item:hover { border-color: #b0b0c0; }

.checklist-item input[type="checkbox"] {
  margin-top: .25rem;
  accent-color: #4361ee;
  flex-shrink: 0;
}

.checklist-item label {
  cursor: pointer;
  font-size: .9rem;
  flex: 1;
  min-width: 0;
}

.item-explanation {
  width: 100%;
  font-size: .8rem;
  color: #555;
  margin-top: .2rem;
  padding-top: .35rem;
  border-top: 1px solid #e8e8e8;
}

.item-code-btn {
  background: none;
  border: none;
  color: #4361ee;
  font-size: .78rem;
  cursor: pointer;
  padding: 0;
  margin-top: .15rem;
  text-decoration: underline;
}
.item-code-btn:hover { color: #2d46b9; }

/* Reveal states */
.checklist-item.correct-picked {
  border-color: #22c55e;
  background: #f0fdf4;
}
.checklist-item.correct-missed {
  border-color: #f59e0b;
  background: #fffbeb;
}
.checklist-item.incorrect-picked {
  border-color: #ef4444;
  background: #fef2f2;
}
.checklist-item.distractor-ok {
  border-color: #e0e0e8;
  background: #fafafa;
  opacity: .7;
}

/* ===== Reference Wall ===== */
.wall-heading { font-size: 1.5rem; margin-bottom: .25rem; }
.wall-intro { color: #666; font-size: .9rem; margin-bottom: 1.5rem; }

.wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.wall-card {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border: 1px solid #e0e0e8;
}

.wall-card-header {
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
}

.wall-card-title { font-size: .95rem; font-weight: 600; }

.wall-card-iframe {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: none;
  display: block;
}

.wall-card-footer {
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #eee;
}

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: #666;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  appearance: none;
  -webkit-appearance: none;
  background: #ef4444;
  border-radius: 11px;
  cursor: pointer;
  outline: none;
  transition: background .3s;
  border: none;
}
.toggle:checked { background: #22c55e; }

.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .3s;
}
.toggle:checked::after { transform: translateX(18px); }

/* ===== Code Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid #eee;
}
.modal-header h3 { font-size: 1rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #888;
  line-height: 1;
}
.modal-close:hover { color: #333; }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-body pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 1rem;
  border-radius: 8px;
  font-size: .82rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ===== Transitions ===== */
.fade-out { animation: fadeOut .3s forwards; }
.fade-in  { animation: fadeIn .3s forwards; }

@keyframes fadeOut { to { opacity: 0; } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
