/* GrilleApp — style.css — calm, focused, slightly playful */

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

:root {
  --bg:         #f8f6f2;
  --surface:    #ffffff;
  --border:     #e5e1d8;
  --text:       #2d2d2d;
  --muted:      #7a7368;
  --primary:    #3b6b8a;
  --primary-lt: #eaf2f8;
  --green:      rgba(34, 197, 94, 0.45);
  --green-str:  rgba(22, 163, 74, 0.85);
  --red:        rgba(239, 68, 68, 0.35);
  --red-str:    rgba(220, 38, 38, 0.85);
  --orange:     rgba(249, 115, 22, 0.35);
  --orange-str: rgba(234, 88, 12, 0.85);
  --radius:     12px;
  --shadow:     0 2px 12px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Screen 1: Character creation ────────────────────────────────────────── */
#screen-create {
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.create-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}

.create-card h1 { font-size: 1.7rem; color: var(--primary); margin-bottom: 6px; }
.create-card p.subtitle { color: var(--muted); margin-bottom: 32px; font-size: 0.95rem; }

.create-card label {
  display: block;
  text-align: left;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.create-card input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 24px;
  transition: border-color 0.2s;
  background: var(--bg);
}
.create-card input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 32px;
}
.avatar-btn {
  font-size: 1.6rem;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  background: var(--bg);
  transition: all 0.15s;
  line-height: 1;
}
.avatar-btn:hover { background: var(--primary-lt); transform: scale(1.1); }
.avatar-btn.selected {
  border-color: var(--primary);
  background: var(--primary-lt);
  transform: scale(1.1);
}

.btn-primary {
  display: inline-block;
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 36px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Screen 2: Hub ────────────────────────────────────────────────────────── */
#screen-hub {
  padding: 40px 24px;
  align-items: center;
}

.hub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.hub-header .ta-avatar { font-size: 2rem; }
.hub-header h2 { font-size: 1.4rem; }
.hub-header p  { color: var(--muted); font-size: 0.9rem; }

.hub-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 760px;
  width: 100%;
  margin-bottom: 32px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 20px;
}

/* Progress circle */
.progress-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.progress-ring-container {
  position: relative;
  width: 130px;
  height: 130px;
}
.progress-ring-container svg { transform: rotate(-90deg); }
.progress-ring-bg   { stroke: var(--border); fill: none; }
.progress-ring-fill { stroke: var(--primary); fill: none; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.progress-text .count  { font-size: 1.8rem; font-weight: 700; color: var(--primary); line-height: 1; }
.progress-text .label  { font-size: 0.72rem; color: var(--muted); }
.progress-text .quota  { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

/* Leaderboard */
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.lb-row:last-child { border-bottom: none; }
.lb-avatar { font-size: 1.4rem; }
.lb-name   { flex: 1; font-weight: 500; }
.lb-count  { font-size: 1rem; font-weight: 700; color: var(--primary); }

.btn-start {
  background: var(--primary);
  color: white;
  border: none;
  padding: 16px 48px;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-start:hover { opacity: 0.88; transform: translateY(-1px); }

/* ── Screen 3: Grading ────────────────────────────────────────────────────── */
#screen-grade {
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.grade-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.grade-header .ta-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-lt);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
}
.grade-header .student-info { flex: 1; min-width: 0; }
.grade-header .student-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grade-header .student-meta { font-size: 0.8rem; color: var(--muted); }

.grade-header .header-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.mini-bar {
  width: 80px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.mini-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* Page tabs */
.page-tabs {
  display: flex;
  gap: 2px;
  background: var(--border);
  border-radius: 8px;
  padding: 2px;
}
.page-tab {
  padding: 5px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.page-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Scan area */
.scan-area {
  flex: 1;
  overflow: auto;
  background: #e8e4dc;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

.scan-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  border-radius: 4px;
  overflow: hidden;
}

.scan-img {
  display: block;
  max-width: min(780px, 100%);
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.scan-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* needs_align overlay */
.align-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(249,115,22,0.9);
  color: white;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* Drag handles for manual alignment */
.align-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  background: #f97316;
  border: 2.5px solid white;
  border-radius: 50%;
  cursor: grab;
  transform: translate(-50%, -50%);
  z-index: 10;
  touch-action: none;
}
.align-handle:active { cursor: grabbing; }

/* Footer */
.grade-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.legend {
  display: flex;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--muted);
  align-items: center;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid transparent;
  flex-shrink: 0;
}
.legend-dot.selected  { background: rgba(34,197,94,0.45); border-color: rgba(22,163,74,0.85); }
.legend-dot.cancelled { background: rgba(239,68,68,0.35); border-color: rgba(220,38,38,0.85); }
.legend-dot.illisible { background: rgba(249,115,22,0.35); border-color: rgba(234,88,12,0.85); }

.btn-done {
  background: #16a34a;
  color: white;
  border: none;
  padding: 11px 28px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-done:hover { opacity: 0.88; }

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--muted);
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* Saving indicator */
.save-indicator {
  font-size: 0.78rem;
  color: var(--muted);
  transition: opacity 0.3s;
}
.save-indicator.saving { color: #f97316; }
.save-indicator.saved  { color: #16a34a; }

/* ── Confetti ─────────────────────────────────────────────────────────────── */
.confetti-piece {
  position: fixed;
  width: 8px; height: 10px;
  pointer-events: none;
  z-index: 9999;
  animation: confetti-fall 2.4s ease-in forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-60px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh)  rotate(720deg); opacity: 0; }
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s;
  z-index: 1000;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .hub-content { grid-template-columns: 1fr; }
  .create-card { padding: 32px 20px; }
  .avatar-grid { grid-template-columns: repeat(4, 1fr); }
}
