:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --primary: #2563eb;
    --secondary: #64748b;
    --danger: #ef4444;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --orange: #f97316;
}

* { box-sizing: border-box; }

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

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

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

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

.brand {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    background: linear-gradient(to right, #1e293b, #2563eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 24px;
    text-align: center;
}

.tabs {
    display: flex;
    gap: 0;
    background: var(--border);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 24px;
    width: 100%;
    max-width: 440px;
}

.tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
}

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

.panel {
    width: 100%;
    max-width: 440px;
}

.teacher-panel {
    max-width: 860px;
}

.teacher-cols {
    display: flex;
    gap: 0;
    align-items: flex-start;
    width: 100%;
}

.teacher-col {
    flex: 1;
}

.rejoin-col {
    max-width: 280px;
    flex: 0 0 280px;
}

.col-divider {
    width: 1px;
    background: var(--border);
    align-self: stretch;
    margin: 0 28px;
    flex-shrink: 0;
}

.col-heading {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 10px;
    padding-left: 2px;
}

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

.rejoin-btn {
    background: var(--secondary);
    color: white;
    width: 100%;
    margin-top: 8px;
}

.rejoin-btn:hover { opacity: 0.9; transform: translateY(-1px); }

@media (max-width: 700px) {
    .teacher-cols { flex-direction: column; }
    .col-divider { width: 100%; height: 1px; margin: 20px 0; }
    .rejoin-col { max-width: 100%; flex: 1; }
}

.card {
    background: var(--card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.07);
}

.field-group {
    margin-bottom: 14px;
}

.field-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field-group input,
.field-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: white;
}

.field-group input:focus,
.field-group select:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.var-count-group {
    display: flex;
    gap: 8px;
}

.var-count-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border);
    background: white;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
}

.var-count-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

.var-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 10px;
    background: #f8fafc;
}

.var-block-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    margin-bottom: 10px;
}

.mini-row {
    display: flex;
    gap: 10px;
}

.mini-row .field-group {
    flex: 1;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.btn.primary {
    background: var(--primary);
    color: white;
    width: 100%;
    margin-top: 8px;
}

.btn.primary:hover { opacity: 0.9; transform: translateY(-1px); }

.hidden { display: none !important; }

/* ==========================================
   TEACHER VIEW
   ========================================== */

#view-teacher {
    height: 100vh;
    overflow: hidden;
}

.teacher-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
}

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

.brand-sm {
    font-weight: 800;
    font-size: 1.1rem;
    background: linear-gradient(to right, #1e293b, #2563eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.room-tag {
    font-weight: 700;
    color: var(--primary);
    font-size: 1rem;
}

.count-tag {
    font-size: 0.85rem;
    color: var(--muted);
    background: var(--bg);
    padding: 3px 10px;
    border-radius: 20px;
}

.bar-right {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-ctrl {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
    transition: all 0.15s;
}

.btn-ctrl:hover { background: var(--bg); }
.btn-ctrl.active { background: var(--primary); color: white; border-color: var(--primary); }
.btn-ctrl.danger { color: var(--danger); border-color: #fecaca; }
.btn-ctrl.danger:hover { background: #fef2f2; }

.teacher-content {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#chart {
    display: block;
    width: 100%;
    height: 100%;
}

.tip {
    position: absolute;
    background: rgba(15, 23, 42, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    line-height: 1.5;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
}

/* QR side panel */
.qr-panel {
    width: 38%;
    max-width: 480px;
    min-width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 30px 24px;
    background: white;
    border-left: 2px solid var(--border);
}

.qr-panel #qr-url-text {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    text-align: center;
    word-break: break-all;
    margin: 0;
}

/* ==========================================
   STUDENT VIEW
   ========================================== */

#view-student {
    justify-content: flex-start;
    align-items: center;
    padding: 40px 20px 60px;
}

.student-inner {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.room-label {
    font-weight: 700;
    color: var(--primary);
    font-size: 1rem;
    margin-bottom: 24px;
}

.error-msg {
    background: #fef2f2;
    color: var(--danger);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
    width: 100%;
    text-align: center;
}

#s-form {
    width: 100%;
}

.slider-group {
    background: white;
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
}

.slider-label {
    font-weight: 600;
    font-size: 1rem;
}

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

input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    height: 6px;
    cursor: pointer;
}

.slider-minmax {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
}

#s-name-wrap {
    background: white;
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

#s-name-wrap label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

#s-name-wrap input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

#btn-submit {
    margin-top: 8px;
}

.done {
    text-align: center;
    padding: 40px;
}

.done-check {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #dcfce7;
    color: #16a34a;
    font-size: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.done p {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--muted);
}

@media (max-width: 500px) {
    .teacher-bar { padding: 8px; }
    .brand-sm { display: none; }
}

/* ==========================================
   CHOOSE MODE — LANDING SETUP
   ========================================== */

/* Mode selector (Plot / Choose) */
.mode-group {
    display: flex;
    gap: 8px;
}

.mode-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border);
    background: white;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
    font-family: inherit;
}

.mode-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

/* Teacher option input rows */
.option-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.option-text-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
}

.option-text-input:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.btn-remove-opt {
    background: #fef2f2;
    color: var(--danger);
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1.1rem;
    flex-shrink: 0;
    font-family: inherit;
}

.btn-remove-opt:hover { background: #fee2e2; }

.btn-add-opt {
    background: none;
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
    font-family: inherit;
    width: 100%;
    margin-top: 4px;
    transition: all 0.15s;
}

.btn-add-opt:hover { border-color: var(--primary); color: var(--primary); }

/* Max votes selector */
.vote-count-group {
    display: flex;
    gap: 8px;
}

.vote-count-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border);
    background: white;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
    font-family: inherit;
}

.vote-count-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text);
    cursor: pointer;
    margin-top: 10px;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

/* ==========================================
   CHOOSE MODE — TEACHER VIEW (BLOBS)
   ========================================== */

#plot-content, #choose-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#blob-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #f8fafc;
}

/* Blob wrapper — draggable, positioned absolutely inside blob-canvas */
.blob-wrap {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.blob-wrap:active { cursor: grabbing; }

/* The circle */
.blob {
    border-radius: 50%;
    background: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width 0.4s ease, height 0.4s ease;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.35);
}

.blob.student-added {
    background: #8b5cf6;
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.35);
}

.blob-count {
    font-size: 2.4rem;
    font-weight: 800;
    color: white;
    line-height: 1;
    pointer-events: none;
}

.blob-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 10px;
    text-align: center;
    max-width: 180px;
    word-break: break-word;
    pointer-events: none;
}

/* Delete button on student-added blobs */
.blob-delete {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: 2px solid white;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.blob-delete:hover { background: #dc2626; }

/* ==========================================
   CHOOSE MODE — STUDENT VIEW
   ========================================== */

.option-btn {
    width: 100%;
    padding: 18px 22px;
    margin-bottom: 10px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: white;
    font-size: 1.15rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    transition: all 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.option-btn:hover { border-color: var(--primary); background: #eff6ff; }

.option-btn.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

/* Student add-option row */
.add-opt-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.add-opt-row input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
}

.add-opt-row input:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.btn-secondary {
    padding: 10px 18px;
    border: 1px solid var(--primary);
    background: white;
    color: var(--primary);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: all 0.15s;
}

.btn-secondary:hover { background: #eff6ff; }

.vote-hint {
    font-size: 1rem;
    color: var(--muted);
    margin: 4px 0 14px;
    text-align: center;
    font-weight: 500;
}

.done-inline {
    text-align: center;
    padding: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #16a34a;
}
