:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --danger: #ef4444;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --track: #e2e8f0;
    --avg-color: #1e293b;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
}

.hidden { display: none !important; }

.view { display: none; }
.view.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ==========================================
   LANDING
   ========================================== */

#view-landing {
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
    gap: 0;
}

.brand {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    background: linear-gradient(90deg, #ef4444, #f97316, #eab308, #22c55e, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    text-align: center;
}

.brand-sub {
    color: var(--muted);
    font-size: 1rem;
    margin: 0 0 40px 0;
    text-align: center;
}

.landing-btns {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    max-width: 360px;
}

.landing-btn {
    padding: 18px 32px;
    font-size: 1.15rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    background: var(--primary);
    color: white;
    transition: background 0.15s, transform 0.1s;
    font-family: 'Inter', sans-serif;
}

.landing-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.landing-btn:active { transform: translateY(0); }

.landing-btn.secondary {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
}

.landing-btn.secondary:hover { background: #f1f5f9; }

.student-room-entry {
    margin-top: 28px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==========================================
   TEACHER SETUP
   ========================================== */

#view-teacher-setup {
    align-items: stretch;
    padding: 0;
}

.setup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.brand-sm {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(90deg, #ef4444, #f97316, #eab308, #22c55e, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.btn-back {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 14px;
    cursor: pointer;
    color: var(--muted);
    font-size: 0.9rem;
    font-family: 'Inter', sans-serif;
    transition: background 0.15s;
}

.btn-back:hover { background: var(--bg); }

.setup-cols {
    display: flex;
    gap: 0;
    flex: 1;
    padding: 32px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    align-items: flex-start;
}

.setup-col {
    flex: 1;
    min-width: 0;
}

.rejoin-col {
    max-width: 320px;
}

.col-divider {
    width: 1px;
    background: var(--border);
    margin: 0 32px;
    align-self: stretch;
    min-height: 200px;
}

.col-heading {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text);
}

.new-heading { color: var(--primary); }
.rejoin-heading { color: var(--secondary); }

/* ==========================================
   COMMON COMPONENTS
   ========================================== */

.card {
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.card.narrow {
    max-width: 360px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.field-group input[type=text],
.field-group input[type=password],
.field-group input[type=number],
.field-group textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    color: var(--text);
    background: white;
    transition: border-color 0.15s;
    outline: none;
}

.field-group input:focus,
.field-group textarea:focus {
    border-color: var(--primary);
}

.field-group textarea {
    resize: vertical;
    line-height: 1.5;
}

.field-group.half { flex: 1; }

.field-row {
    display: flex;
    gap: 12px;
}

.scale-grid {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 8px 12px;
}

.opt {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--muted);
    font-size: 0.8rem;
}

.format-hint {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.4;
}

.format-example {
    font-size: 0.82rem;
    color: var(--muted);
    background: var(--bg);
    padding: 6px 10px;
    border-radius: 6px;
    border-left: 3px solid var(--primary);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    user-select: none;
}

.toggle-label input[type=checkbox] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: translateY(1px); }

.btn.primary {
    background: var(--primary);
    color: white;
}

.btn.primary:hover { background: var(--primary-dark); }

.btn.large {
    padding: 14px 32px;
    font-size: 1.05rem;
}

.rejoin-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: background 0.15s;
}

.rejoin-btn:hover { background: #e9eef4; }

.error-msg {
    font-size: 0.875rem;
    color: var(--danger);
    background: #fee2e2;
    padding: 8px 12px;
    border-radius: 6px;
}

/* ==========================================
   TEACHER DASHBOARD
   ========================================== */

#view-teacher-dashboard {
    min-height: 100vh;
}

.teacher-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    flex-wrap: wrap;
    gap: 8px;
}

.bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-tag {
    font-weight: 700;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 20px;
    color: var(--text);
    font-family: monospace;
    font-size: 0.95rem;
}

.count-tag {
    font-size: 0.85rem;
    color: var(--muted);
}

.mode-btns {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.btn-mode {
    padding: 5px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    background: none;
    color: var(--muted);
    transition: all 0.15s;
}

.btn-mode.active {
    background: var(--card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-ctrl {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: background 0.15s;
}

.btn-ctrl:hover { background: var(--bg); }

.context-box {
    background: #fffbeb;
    border-bottom: 2px solid #f59e0b;
    padding: 12px 24px;
    font-size: 0.93rem;
    color: #78350f;
    line-height: 1.5;
}

.dashboard-content {
    display: flex;
    flex: 1;
    height: calc(100vh - 57px);
    overflow: hidden;
}

.results-panel {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 60px 20px;
    font-size: 0.95rem;
}

/* ==========================================
   QR MODAL
   ========================================== */

.qr-modal {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
}

.qr-modal-inner {
    position: relative;
    background: white;
    border-radius: 16px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 520px;
    width: calc(100vw - 40px);
}

.qr-modal-code {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    line-height: 0;
}

.qr-modal-link {
    font-family: monospace;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--primary);
    text-align: center;
    word-break: break-all;
    background: #eff6ff;
    padding: 10px 16px;
    border-radius: 8px;
    width: 100%;
}

/* Help modal */
.help-modal-inner {
    max-width: 640px;
    max-height: 80vh;
    overflow-y: auto;
    align-items: flex-start;
    gap: 0;
    padding: 28px 32px 24px;
}

.help-title {
    font-size: 1.2rem;
    font-weight: 800;
    margin: 0 0 18px 0;
    color: var(--text);
}

.help-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    margin-bottom: 20px;
}

.help-section h3 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    margin: 0 0 6px 0;
}

.help-section p {
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.55;
    margin: 0 0 6px 0;
}

.help-section ul {
    margin: 0;
    padding-left: 18px;
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.6;
}

.help-section pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.82rem;
    line-height: 1.6;
    margin: 6px 0 0;
    white-space: pre-wrap;
}

/* font-size slider in bar */
.font-size-ctrl {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: default;
}

.font-size-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
    user-select: none;
}

.font-size-ctrl input[type=range] {
    width: 80px;
    height: 4px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Context button highlight when room has context */
#btn-toggle-context.has-context {
    border-color: #f59e0b;
    color: #92400e;
    background: #fffbeb;
}

/* ==========================================
   STATEMENT CARDS (Teacher Dashboard)
   ========================================== */

.statement-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.statement-text {
    font-size: var(--q-font-size, 15px);
    color: var(--text);
    line-height: 1.5;
    font-weight: 500;
}

.cat-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.cat-pill {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: white;
    padding: 2px 7px;
    border-radius: 20px;
    opacity: 0.85;
}

/* ==========================================
   CATEGORY AVERAGE CARD
   ========================================== */

.cat-avg-card {
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.cat-avg-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 7px;
}

.cat-avg-val {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text);
    margin-left: 4px;
}

.cat-avg-dot {
    opacity: 0.5;
    pointer-events: none;
}

.cat-title-avg {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    margin-left: 4px;
}

.cat-title-name {
    font-weight: 700;
}

.statement-category {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: white;
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    width: fit-content;
}

.spectrum-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.spectrum-bar-inner {
    position: relative;
    height: 32px;
    width: 100%;
    cursor: default;
}

.spectrum-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 5px;
    background: var(--track);
    transform: translateY(-50%);
    border-radius: 3px;
}

.spectrum-dot {
    position: absolute;
    top: 50%;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.8;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
    user-select: none;
}

.spectrum-dot:hover {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.3);
    z-index: 10;
}

.spectrum-dot.marked-delete {
    background: var(--danger) !important;
    opacity: 1;
    font-size: 9px;
    font-weight: 900;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    transform: translate(-50%, -50%);
    border-radius: 3px;
    z-index: 20;
    cursor: pointer;
}

.spectrum-dot.marked-delete:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

.spectrum-avg {
    position: absolute;
    top: 12%;
    bottom: 12%;
    width: 3px;
    background: var(--avg-color);
    transform: translateX(-50%);
    border-radius: 2px;
    pointer-events: none;
}

.spectrum-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.3;
}

.spectrum-labels small {
    font-size: 0.7rem;
    opacity: 0.75;
}

.response-meta {
    font-size: 0.78rem;
    color: var(--muted);
}

/* ==========================================
   CATEGORY GROUP LABELS (Organise + Reveal)
   ========================================== */

.category-group-label {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
}

.category-group-label:first-child { margin-top: 0; }

.category-group-label.reveal-title {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.category-group-label.reveal-title:hover {
    background: #e9eef4;
}

.cat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.expand-icon {
    margin-left: auto;
    font-size: 0.9rem;
    color: var(--muted);
}

/* ==========================================
   TABLE VIEW
   ========================================== */

.table-scroll {
    overflow-x: auto;
    width: 100%;
}

.response-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    background: var(--card);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.response-table th {
    background: var(--bg);
    font-weight: 600;
    padding: 10px 12px;
    border: 1px solid var(--border);
    text-align: center;
    font-size: 0.78rem;
    color: var(--muted);
    position: sticky;
    top: 0;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.response-table th:first-child {
    text-align: left;
    min-width: 100px;
    position: sticky;
    left: 0;
    z-index: 2;
}

.response-table td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: center;
    color: var(--text);
}

.response-table td.student-cell {
    text-align: left;
    font-weight: 600;
    font-size: 0.82rem;
    min-width: 100px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: sticky;
    left: 0;
    background: var(--card);
    z-index: 1;
}

.response-table td.score-cell {
    font-family: monospace;
    font-size: 0.88rem;
    color: var(--primary);
    font-weight: 600;
}

.response-table td.score-cell.empty {
    color: var(--muted);
    font-weight: 400;
}

.response-table tbody tr {
    transition: background 0.1s;
    cursor: pointer;
}

.response-table tbody tr:hover {
    background: #f8fafc;
}

.response-table tbody tr:hover .student-cell {
    background: #f8fafc;
}

.response-table tbody tr.row-pending-delete {
    background: #fee2e2;
}

.response-table tbody tr.row-pending-delete .student-cell {
    background: #fee2e2;
    color: var(--danger);
}

.response-table tbody tr.row-pending-delete .score-cell {
    color: var(--danger);
}

.anon-id {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 400;
}

.delete-x {
    font-weight: 900;
    color: var(--danger);
}

/* ==========================================
   DOT TOOLTIP
   ========================================== */

.dot-tooltip {
    position: fixed;
    background: #1e293b;
    color: white;
    padding: 5px 11px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}

.dot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 12px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #1e293b;
}

/* ==========================================
   STUDENT SLIDERS
   ========================================== */

#view-student-sliders {
    align-items: stretch;
}

.student-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px 60px;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
}

.student-inner.wide {
    max-width: 700px;
}

.room-label {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: monospace;
    color: var(--muted);
    margin-bottom: 24px;
    text-align: center;
}

.brand-sm-center {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(90deg, #ef4444, #f97316, #eab308, #22c55e, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
    text-align: center;
}

#sliders-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.slider-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.slider-statement-text {
    font-size: 0.98rem;
    color: var(--text);
    line-height: 1.5;
    font-weight: 500;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-min, .slider-max {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
    min-width: 40px;
    line-height: 1.3;
    text-align: center;
}

.slider-max { text-align: center; }

.slider-min small, .slider-max small {
    display: block;
    font-size: 0.7rem;
    opacity: 0.75;
    font-weight: 400;
}

input[type=range].spectrum-slider {
    flex: 1;
    height: 6px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--track);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    accent-color: var(--primary);
}

input[type=range].spectrum-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(37,99,235,0.4);
    transition: transform 0.1s;
}

input[type=range].spectrum-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type=range].spectrum-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.slider-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    text-align: right;
    min-width: 40px;
}

.name-input-wrap {
    width: 100%;
    margin-top: 8px;
}

.submit-bar {
    margin-top: 24px;
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 20px;
}

.done-message {
    text-align: center;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.done-icon {
    font-size: 3rem;
    color: #22c55e;
    line-height: 1;
}

.done-message p {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
    margin: 8px 0 4px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: underline;
    font-family: 'Inter', sans-serif;
    padding: 0;
}

.btn-link:hover { color: var(--primary-dark); }

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .setup-cols {
        flex-direction: column;
        padding: 20px 16px;
    }

    .col-divider {
        width: 100%;
        height: 1px;
        margin: 20px 0;
        min-height: 0;
    }

    .rejoin-col {
        max-width: 100%;
    }

    .dashboard-content {
        height: auto;
        overflow: visible;
    }

    .results-panel {
        overflow-y: visible;
    }

    .teacher-bar {
        padding: 10px 14px;
    }

    .btn-mode {
        padding: 5px 9px;
        font-size: 0.78rem;
    }
}
