@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Fira+Code:wght@400;500&display=swap');

:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface2: #17171f;
  --border: #1e1e2e;
  --border-light: #2a2a3e;
  --accent: #f59e0b;
  --accent2: #fcd34d;
  --accent-glow: rgba(245,158,11,0.2);
  --green: #34d399;
  --red: #f87171;
  --blue: #60a5fa;
  --text: #f0f0f8;
  --text-muted: #6b6b8a;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(245,158,11,0.08) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(252,211,77,0.05) 0%, transparent 55%);
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }
@keyframes scaleIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Header ──────────────────────────────────────── */
.site-header {
  background: rgba(17,17,24,0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.75rem;
  position: sticky; top: 0; z-index: 100;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; max-width: 1100px; margin: 0 auto; }
.logo { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; font-size: 1.1rem; letter-spacing: -0.02em; text-decoration: none; color: var(--text); }
.logo-icon { font-size: 1.3rem; }
.logo-text span { color: var(--accent); }
.header-nav { display: flex; align-items: center; gap: 1rem; }
.nav-link { color: var(--text-muted); text-decoration: none; font-size: 0.875rem; font-weight: 500; transition: color 0.2s; }
.nav-link:hover { color: var(--accent); }
.site-footer { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 0.8rem; border-top: 1px solid var(--border); }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.7rem 1.6rem; border-radius: var(--radius-sm); border: none;
  font-size: 0.9rem; font-weight: 600; font-family: 'Inter', sans-serif;
  cursor: pointer; transition: all 0.2s; text-decoration: none; letter-spacing: -0.01em;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #0a0a0f; font-weight: 700; box-shadow: 0 4px 16px var(--accent-glow); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); box-shadow: 0 6px 24px var(--accent-glow); }
.btn-outline { background: transparent; border: 1px solid var(--border-light); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.btn-danger { background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.3); color: #f87171; }
.btn-danger:hover { background: rgba(248,113,113,0.2); }
.btn-lg { padding: 0.9rem 2.2rem; font-size: 1rem; }
.btn-sm { padding: 0.4rem 1rem; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* ── Layout ──────────────────────────────────────── */
.page-main { max-width: 900px; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; animation: fadeUp 0.4s ease; }
.page-title { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 0.4rem; }
.page-subtitle { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 2rem; }

/* ── Form elements ────────────────────────────────── */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; margin-bottom: 1.5rem; }
.form-section { margin-bottom: 2rem; }
.form-section-title { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.form-group { margin-bottom: 1.25rem; }
.form-row { display: flex; gap: 1rem; }
.form-row.two-col > * { flex: 1; }
.form-row.four-col { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; }
.form-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); justify-content: flex-end; }
label { display: block; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); padding: 0.7rem 1rem; font-size: 0.95rem; font-family: 'Inter', sans-serif; transition: border-color 0.2s, box-shadow 0.2s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
select option { background: var(--surface); }
textarea { resize: vertical; }

/* ── Alerts ───────────────────────────────────────── */
.alert { padding: 0.8rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.875rem; font-weight: 500; }
.alert-error { background: rgba(248,113,113,0.08); border: 1px solid rgba(248,113,113,0.25); color: #fca5a5; }
.alert-success { background: rgba(52,211,153,0.08); border: 1px solid rgba(52,211,153,0.25); color: #6ee7b7; }

/* ── Spinner ──────────────────────────────────────── */
.spinner-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70vh; gap: 1rem; text-align: center; padding: 2rem; }
.spinner-ring { width: 48px; height: 48px; border: 3px solid var(--border); border-top-color: var(--accent); border-right-color: var(--accent2); border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-inline { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); font-size: 0.875rem; }
.spinner-inline .spinner-ring { width: 20px; height: 20px; border-width: 2px; }
.spinner-title { font-size: 1.1rem; font-weight: 600; }
.spinner-subtitle { color: var(--text-muted); font-size: 0.9rem; }

/* ── Home page ────────────────────────────────────── */
.home-main { max-width: 800px; margin: 0 auto; padding: 0 1.5rem 4rem; animation: fadeUp 0.4s ease; }
.hero { text-align: center; padding: 5rem 2rem 3rem; }
.hero-badge { display: inline-block; background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.3); color: var(--accent); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; padding: 0.3rem 0.9rem; border-radius: 20px; margin-bottom: 1.5rem; animation: pulse 2s ease infinite; }
.hero-title { font-size: 3rem; font-weight: 900; letter-spacing: -0.04em; line-height: 1.1; margin-bottom: 1rem; }
.hero-title span { background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.hero-subtitle { color: var(--text-muted); font-size: 1.05rem; margin-bottom: 3rem; max-width: 420px; margin-left: auto; margin-right: auto; }
.hero-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

.home-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-top: 3rem; }
.home-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; text-decoration: none; color: var(--text); transition: all 0.2s; position: relative; overflow: hidden; }
.home-card::before { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, var(--accent-glow), transparent); opacity: 0; transition: opacity 0.3s; }
.home-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 8px 32px var(--accent-glow); }
.home-card:hover::before { opacity: 1; }
.home-card-icon { font-size: 2.25rem; margin-bottom: 0.9rem; display: block; }
.home-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.4rem; }
.home-card p { color: var(--text-muted); font-size: 0.875rem; line-height: 1.5; }

/* Join card on home */
.join-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.join-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.4rem; }
.join-card p { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.5rem; }
.join-input-row { display: flex; gap: 0.75rem; }
.code-input { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.2em; text-align: center; font-family: 'Fira Code', monospace; max-width: 180px; }

/* ── Login ────────────────────────────────────────── */
.login-main { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 120px); padding: 2rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 420px; }
.login-icon { font-size: 2.5rem; text-align: center; margin-bottom: 1rem; }
.login-title { font-size: 1.5rem; font-weight: 800; text-align: center; margin-bottom: 0.4rem; }
.login-subtitle { color: var(--text-muted); font-size: 0.875rem; text-align: center; margin-bottom: 1.75rem; }

/* ── Create session ───────────────────────────────── */
.tabs { display: flex; gap: 0; margin-bottom: 0; border-bottom: 1px solid var(--border); }
.tab-btn { padding: 0.75rem 1.5rem; background: none; border: none; color: var(--text-muted); font-size: 0.875rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.2s; font-family: 'Inter', sans-serif; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; padding-top: 1.5rem; }
.tab-panel.active { display: block; }

/* Manual question builder */
.question-builder { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.question-item { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem; position: relative; }
.question-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.question-item-num { font-size: 0.75rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.remove-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.1rem; padding: 0; line-height: 1; transition: color 0.2s; }
.remove-btn:hover { color: var(--red); }
.options-builder { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.option-input-row { display: flex; gap: 0.5rem; align-items: center; }
.option-input-row input { flex: 1; }
.add-option-btn { font-size: 0.8rem; color: var(--accent); background: none; border: none; cursor: pointer; padding: 0.25rem 0; font-family: 'Inter', sans-serif; }

/* ── Present / Teacher view ───────────────────────── */
.present-main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; display: grid; grid-template-columns: 1fr 320px; gap: 1.5rem; min-height: calc(100vh - 80px); }
.present-stage { display: flex; flex-direction: column; gap: 1rem; }
.present-sidebar { display: flex; flex-direction: column; gap: 1rem; }

.room-code-banner { background: linear-gradient(135deg, rgba(245,158,11,0.15), rgba(252,211,77,0.08)); border: 1px solid rgba(245,158,11,0.3); border-radius: var(--radius); padding: 1.25rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }
.room-code-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 0.25rem; }
.room-code-value { font-size: 2.5rem; font-weight: 900; letter-spacing: 0.15em; font-family: 'Fira Code', monospace; color: var(--accent2); }
.student-count { text-align: right; }
.student-count-num { font-size: 2rem; font-weight: 900; color: var(--text); }
.student-count-label { font-size: 0.75rem; color: var(--text-muted); }

.question-stage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; flex: 1; }
.stage-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 300px; color: var(--text-muted); gap: 1rem; }
.stage-placeholder-icon { font-size: 3rem; opacity: 0.4; }
.q-index { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 0.75rem; }
.q-text { font-size: 1.5rem; font-weight: 700; line-height: 1.4; margin-bottom: 1.5rem; }
.q-type-badge { display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.2rem 0.65rem; border-radius: 20px; background: rgba(245,158,11,0.1); color: var(--accent); margin-bottom: 1rem; }

/* Results display */
.bar-chart { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.bar-row { display: flex; align-items: center; gap: 0.75rem; }
.bar-label { font-size: 0.875rem; min-width: 120px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; background: var(--border); border-radius: 4px; height: 28px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 4px; transition: width 0.8s cubic-bezier(0.4,0,0.2,1); display: flex; align-items: center; padding-left: 0.5rem; min-width: 2px; }
.bar-count { font-size: 0.8rem; font-weight: 700; color: #0a0a0f; white-space: nowrap; }
.bar-pct { font-size: 0.8rem; color: var(--text-muted); min-width: 40px; text-align: right; }

.word-cloud { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 1rem 0; justify-content: center; }
.word-item { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 0.3rem 0.85rem; color: var(--accent2); font-weight: 600; transition: all 0.3s; }

.open-text-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 300px; overflow-y: auto; }
.open-text-item { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.65rem 1rem; font-size: 0.875rem; animation: fadeUp 0.3s ease; }
.open-text-name { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.2rem; font-weight: 600; }

.response-counter { background: var(--surface2); border-radius: var(--radius-sm); padding: 0.75rem 1rem; display: flex; justify-content: space-between; align-items: center; font-size: 0.875rem; }
.response-counter strong { color: var(--accent2); font-size: 1.1rem; }

/* Controls */
.controls-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.controls-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.25rem; }
.progress-indicator { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; color: var(--text-muted); }
.progress-dots { display: flex; gap: 4px; }
.progress-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: background 0.3s; }
.progress-dot.done { background: var(--accent); }
.progress-dot.current { background: var(--accent2); }

.student-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; flex: 1; overflow: hidden; }
.student-list-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.75rem; }
.student-names { display: flex; flex-direction: column; gap: 0.4rem; max-height: 200px; overflow-y: auto; }
.student-name-item { font-size: 0.85rem; padding: 0.3rem 0.5rem; border-radius: var(--radius-sm); background: var(--bg); animation: scaleIn 0.3s ease; }

/* ── Student join page ─────────────────────────────── */
.join-main { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 80px); padding: 2rem; }
.join-card-big { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 3rem 2.5rem; width: 100%; max-width: 480px; text-align: center; }
.join-icon { font-size: 3rem; margin-bottom: 1rem; }
.join-title { font-size: 2rem; font-weight: 900; margin-bottom: 0.5rem; letter-spacing: -0.03em; }
.join-subtitle { color: var(--text-muted); margin-bottom: 2rem; }
.join-form { text-align: left; }

/* ── Student answer page ─────────────────────────── */
.answer-main { max-width: 640px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.waiting-room { text-align: center; padding: 5rem 2rem; }
.waiting-icon { font-size: 4rem; margin-bottom: 1.5rem; animation: pulse 2s ease infinite; }
.waiting-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.waiting-subtitle { color: var(--text-muted); }
.session-title-pill { display: inline-block; background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); color: var(--accent); font-size: 0.8rem; font-weight: 600; padding: 0.3rem 0.9rem; border-radius: 20px; margin-top: 1rem; }

.question-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; animation: scaleIn 0.3s ease; }
.q-progress { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.q-card-text { font-size: 1.3rem; font-weight: 700; line-height: 1.4; margin-bottom: 1.5rem; }
.options-list { display: flex; flex-direction: column; gap: 0.65rem; }
.option-btn { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.25rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-size: 0.95rem; font-family: 'Inter', sans-serif; color: var(--text); transition: all 0.2s; text-align: left; width: 100%; }
.option-btn:hover { border-color: var(--accent); background: rgba(245,158,11,0.06); }
.option-btn.selected { border-color: var(--accent); background: rgba(245,158,11,0.12); color: var(--accent2); }
.option-btn.correct { border-color: var(--green); background: rgba(52,211,153,0.12); color: var(--green); }
.option-letter { width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid currentColor; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; opacity: 0.7; }

.answer-textarea { font-size: 1rem; min-height: 100px; margin-bottom: 1rem; }
.answer-submit-bar { display: flex; justify-content: center; margin-top: 1.25rem; }
.answered-banner { background: rgba(52,211,153,0.1); border: 1px solid rgba(52,211,153,0.3); border-radius: var(--radius); padding: 1.5rem; text-align: center; margin-top: 1rem; }
.answered-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.answered-text { font-weight: 700; color: var(--green); margin-bottom: 0.25rem; }
.answered-sub { font-size: 0.875rem; color: var(--text-muted); }
.ended-banner { text-align: center; padding: 3rem 2rem; }

/* ── Dashboard ────────────────────────────────────── */
.sessions-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 700; }
td { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(245,158,11,0.02); }
.status-badge { display: inline-block; font-size: 0.72rem; padding: 0.2rem 0.65rem; border-radius: 20px; font-weight: 600; }
.status-waiting { background: rgba(107,107,138,0.15); color: var(--text-muted); }
.status-active { background: rgba(52,211,153,0.12); color: var(--green); animation: pulse 2s ease infinite; }
.status-ended { background: rgba(248,113,113,0.1); color: #f87171; }
.action-link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 0.85rem; }
.action-link:hover { text-decoration: underline; }
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 900px) {
  .present-main { grid-template-columns: 1fr; }
  .present-sidebar { flex-direction: row; flex-wrap: wrap; }
  .present-sidebar > * { flex: 1; min-width: 250px; }
}
@media (max-width: 600px) {
  .home-cards { grid-template-columns: 1fr; }
  .hero-title { font-size: 2rem; }
  .form-row.four-col { grid-template-columns: 1fr 1fr; }
  .join-input-row { flex-direction: column; }
}
