@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,400&family=Crimson+Pro:ital,wght@0,300;0,400;0,600;1,400&display=swap');

:root {
  --bg:       #F5F0E8;
  --surface:  #ffffff;
  --primary:  #1C2E44;
  --accent:   #2E7BC4;
  --correct:  #27ae60;
  --wrong:    #e74c3c;
  --hint-col: #c08020;
  --text:     #1A1610;
  --muted:    #7f8c8d;
  --border:   #D4C9A8;
  --bronze:   #8B6914;
  --gold:     #E8C96A;
  --r:        12px;
  --shadow:   0 2px 12px rgba(26,22,16,0.12);
  --font-d:   'Cormorant Garamond', Georgia, serif;
  --font-b:   'Crimson Pro', Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-b);
  font-size: 18px;
  line-height: 1.65;
  min-height: 100vh;
}

/* ── App shell ─────────────────────────────────────────────────────────── */

#app { min-height: 100vh; }

/* ── Views ─────────────────────────────────────────────────────────────── */

.view {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.view-narrow {
  max-width: 560px;
}

.view-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.25rem;
  padding-top: 4rem;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.header-actions { display: flex; gap: .75rem; flex-wrap: wrap; }

.back-link {
  display: inline-block;
  font-family: var(--font-d);
  font-size: .82rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--bronze);
  cursor: pointer;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.back-link:hover { border-bottom-color: var(--bronze); }

/* ── Typography ────────────────────────────────────────────────────────── */

h1 {
  font-family: var(--font-d);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 400;
  color: var(--primary);
  margin-bottom: .5rem;
}
h2 {
  font-family: var(--font-d);
  font-size: 1.5rem;
  color: var(--primary);
}
p { color: #4A3C28; }
.muted { color: var(--muted); font-style: italic; }
.small { font-size: .88rem; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-family: var(--font-d);
  font-size: .82rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--r);
  border: 2px solid transparent;
  padding: .7rem 1.5rem;
  transition: all .2s;
  min-height: 48px;
  font-weight: 500;
}
.btn-primary  { background: var(--primary); color: #F5F0E8; border-color: var(--primary); }
.btn-primary:hover { background: transparent; color: var(--primary); }
.btn-sm       { background: var(--primary); color: #F5F0E8; padding: .5rem 1rem; min-height: 40px; }
.btn-ghost-sm { background: transparent; color: var(--muted); border-color: var(--border); padding: .5rem 1rem; min-height: 40px; }
.btn-ghost-sm:hover { color: var(--text); border-color: #999; }
.btn-danger-sm { background: transparent; color: var(--wrong); border-color: var(--wrong); padding: .5rem 1rem; min-height: 40px; }
.btn-danger-sm:hover { background: var(--wrong); color: #fff; }
.btn-icon     { background: none; border: none; cursor: pointer; font-size: 1.1rem; padding: .5rem; color: var(--bronze); }
.btn-icon:hover { color: var(--primary); }
.btn-gender   { background: var(--surface); border: 2px solid var(--border); color: var(--text); padding: .9rem 2rem; font-size: 1rem; min-height: 56px; border-radius: var(--r); cursor: pointer; transition: all .2s; }
.btn-gender:hover { border-color: var(--accent); color: var(--accent); }

/* ── Login ─────────────────────────────────────────────────────────────── */

.view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 3rem 2.5rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-icon { font-size: 3rem; }

/* ── Class grid ────────────────────────────────────────────────────────── */

.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}
.class-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--bronze);
  border-radius: var(--r);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.class-card-name { font-family: var(--font-d); font-size: 1.1rem; font-weight: 500; color: var(--primary); }
.class-card-actions { display: flex; gap: .5rem; }

/* ── Stats ─────────────────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: .9rem 1.25rem;
  min-width: 90px;
  text-align: center;
}
.stat-box.stat-warn { border-color: var(--wrong); background: rgba(231,76,60,.06); }
.stat-value { font-family: var(--font-d); font-size: 1.8rem; font-weight: 600; color: var(--primary); line-height: 1; }
.stat-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: .25rem; }

/* ── Student grid ──────────────────────────────────────────────────────── */

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.student-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.student-card--warn { border-color: var(--hint-col); }
.student-card-photo { aspect-ratio: 1; overflow: hidden; background: #eee; }
.student-card-photo img { width: 100%; height: 100%; object-fit: cover; }
.student-card-no-photo { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; color: #ccc; }
.student-card-info { padding: .6rem .75rem; flex: 1; }
.student-card-name { font-family: var(--font-d); font-size: .95rem; font-weight: 500; color: var(--primary); }
.student-card-meta { font-size: .75rem; color: var(--muted); display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.warn-badge { background: rgba(192,128,32,.15); color: var(--hint-col); font-size: .68rem; padding: .1em .4em; border-radius: 4px; }
.student-card .btn-icon { align-self: flex-end; padding: .3rem .6rem; }

/* ── Drop zone ─────────────────────────────────────────────────────────── */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--r);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin: 1.5rem 0;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(46,123,196,.05);
}
.drop-zone-icon { font-size: 2.5rem; margin-bottom: .5rem; }

.file-list {
  list-style: none;
  font-size: .9rem;
  color: var(--muted);
  margin-bottom: 1rem;
  max-height: 180px;
  overflow-y: auto;
}
.file-list li { padding: .2rem 0; border-bottom: 1px solid var(--border); }

/* ── Forms ─────────────────────────────────────────────────────────────── */

.input {
  display: block;
  width: 100%;
  margin-top: .35rem;
  padding: .65rem .9rem;
  font-family: var(--font-b);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 2px solid #b0a080;
  border-radius: 4px;
  outline: none;
  transition: border-color .2s;
}
.input:focus { border-bottom-color: var(--bronze); }
textarea.input { min-height: 90px; resize: vertical; }

.field-label {
  display: flex;
  flex-direction: column;
  font-family: var(--font-d);
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #6B5840;
  margin-bottom: 1rem;
}

.action-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.meta-row { margin: .5rem 0 1rem; }

/* ── Photos (edit) ─────────────────────────────────────────────────────── */

.photo-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.photo-thumb { position: relative; width: 80px; height: 80px; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.photo-delete-btn {
  position: absolute; top: -6px; right: -6px;
  background: var(--wrong); color: #fff;
  border: none; border-radius: 50%;
  width: 22px; height: 22px; font-size: .75rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── Gender tag ────────────────────────────────────────────────────────── */

.tag-photo { width: 180px; height: 180px; object-fit: cover; border-radius: var(--r); box-shadow: var(--shadow); }
.tag-no-photo { width: 180px; height: 180px; display: flex; align-items: center; justify-content: center; font-size: 4rem; background: #eee; border-radius: var(--r); }
.tag-name { font-family: var(--font-d); font-size: 1.6rem; color: var(--primary); }
.gender-btns { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }

/* ── Quiz ──────────────────────────────────────────────────────────────── */

.quiz-view {
  max-width: 600px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.quiz-stimulus { width: 100%; display: flex; justify-content: center; }
.quiz-photo { max-width: 280px; max-height: 280px; object-fit: cover; border-radius: var(--r); box-shadow: var(--shadow); }
.quiz-hint-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--hint-col);
  border-radius: var(--r);
  padding: 1.5rem 2rem;
  font-size: 1.15rem;
  font-style: italic;
  color: var(--text);
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow);
}

.quiz-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  width: 100%;
}
.answer-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r);
  padding: 1rem;
  font-family: var(--font-d);
  font-size: 1rem;
  cursor: pointer;
  transition: all .15s;
  min-height: 56px;
  color: var(--text);
}
.answer-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.answer-btn.correct { background: rgba(39,174,96,.12); border-color: var(--correct); color: var(--correct); font-weight: 600; }
.answer-btn.wrong   { background: rgba(231,76,60,.10);  border-color: var(--wrong);   color: var(--wrong); }

.quiz-input-wrap { display: flex; gap: .75rem; width: 100%; }
.quiz-input { flex: 1; }
.quiz-submit { white-space: nowrap; }

.quiz-feedback {
  font-size: 1rem;
  padding: .75rem 1rem;
  border-radius: 8px;
  width: 100%;
  text-align: center;
}
.quiz-feedback.correct { background: rgba(39,174,96,.12); color: var(--correct); }
.quiz-feedback.wrong   { background: rgba(231,76,60,.10);  color: var(--wrong); }

.hint-btn {
  background: none;
  border: 1px solid var(--hint-col);
  color: var(--hint-col);
  border-radius: 20px;
  padding: .4rem 1.1rem;
  font-size: .85rem;
  cursor: pointer;
  transition: all .2s;
}
.hint-btn:hover { background: rgba(192,128,32,.1); }
.hint-btn.hint-revealed { font-weight: 700; }

/* ── Progress bar ──────────────────────────────────────────────────────── */

.progress-wrap {
  width: 100%;
  position: relative;
  background: var(--border);
  border-radius: 4px;
  height: 6px;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .3s;
}
.progress-label {
  position: absolute;
  right: 0;
  top: 10px;
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .05em;
}

/* ── Spinner ───────────────────────────────────────────────────────────── */

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 4rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 1.5rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: #F5F0E8;
  padding: .7rem 1.5rem;
  border-radius: var(--r);
  font-size: .9rem;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 9999;
  pointer-events: none;
}
.toast-error { background: var(--wrong); }
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Group practice ────────────────────────────────────────────────────── */

.group-list {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  margin-top: 1.5rem;
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--r);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.group-card--locked {
  border-left-color: var(--border);
  opacity: .55;
}

.group-card--done {
  border-left-color: var(--correct);
}

.group-card-info { flex: 1; }

.group-card-top {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .2rem;
}

.group-number {
  font-family: var(--font-d);
  font-size: 1rem;
  font-weight: 500;
  color: var(--primary);
}

.phase-badge {
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .2em .65em;
  border-radius: 20px;
}

.phase-active  { background: rgba(46,123,196,.14); color: var(--accent); }
.phase-locked  { background: var(--border); color: var(--muted); }
.phase-done    { background: rgba(39,174,96,.14); color: var(--correct); }

.group-names {
  font-size: .88rem;
  color: var(--muted);
  font-style: italic;
}

.quiz-quit { margin-top: .25rem; }

/* ── Mix & Match ───────────────────────────────────────────────────────── */

.view-match {
  max-width: 860px;
}

.match-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: .5rem;
}

.match-count {
  font-family: var(--font-d);
  font-size: 1.1rem;
}

.match-banner {
  width: 100%;
  max-width: 860px;
  text-align: center;
  padding: .65rem 1rem;
  border-radius: var(--r);
  background: rgba(46,123,196,.12);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-d);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.match-banner--empty {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted);
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
  margin-bottom: 1.5rem;
}

.match-slot {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  box-shadow: var(--shadow);
}

.match-slot--droppable {
  border-color: var(--accent);
  transform: scale(1.02);
}

.match-slot--droppable:hover {
  background: rgba(46,123,196,.06);
}

.match-slot--correct {
  border-color: var(--correct);
  cursor: default;
}

.match-slot--wrong {
  border-color: var(--wrong);
  cursor: default;
}

.match-photo {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.match-label {
  padding: .4rem .6rem;
  font-family: var(--font-d);
  font-size: .9rem;
  text-align: center;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.match-label--empty {
  color: var(--muted);
  font-style: italic;
}

.match-correct-label {
  padding: .25rem .6rem .4rem;
  font-family: var(--font-d);
  font-size: .8rem;
  text-align: center;
  color: var(--correct);
  font-weight: 600;
  background: rgba(39,174,96,.1);
}

.match-pool {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  justify-content: center;
  padding: .5rem 0 1rem;
}

.match-chip {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: .45rem 1.1rem;
  font-family: var(--font-d);
  font-size: .95rem;
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
}

.match-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.match-chip--selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.match-score {
  font-family: var(--font-d);
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 1.5rem;
}

.match-actions {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: .5rem;
}

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .view { padding: 1.25rem 1rem 3rem; }
  .quiz-answers { grid-template-columns: 1fr; }
  .stats-row { gap: .6rem; }
  .stat-box { min-width: 70px; padding: .7rem .9rem; }
}
