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

/* 1. Global Box Sizing Fix - Prevents spilling */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100%;
    /* 2. Increased Width for better spacing */
    max-width: 1000px;
    height: 100vh;
    position: relative;
    overflow: hidden;
    background: var(--bg-color);
}

/* VIEW HANDLING */
.view {
    display: none;
    height: 100%;
    flex-direction: column;
    padding: 20px;
    width: 100%;
}

.view.active {
    display: flex;
}

/* LANDING */
#view-landing {
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* 3. Card Styling Updates */
.card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    width: 100%;
    /* Removed global max-width to allow dashboard stretch */
}

/* Only Landing Card is restricted */
.landing-card {
    max-width: 400px;
    margin: 0 auto;
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

input, select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 1rem;
    font-family: inherit;
}

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

.hint-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: -8px;
    margin-bottom: 12px;
    text-align: left;
}

/* BUTTONS */
.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.2s;
}

.primary { background-color: var(--primary); color: white; }
.secondary { background-color: var(--secondary); color: white; }
.action { background-color: var(--text-main); color: white; width: 100%; margin-top: 10px; }
.primary:hover, .secondary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-small { padding: 6px 12px; background: #fee2e2; color: #991b1b; border: none; border-radius: 4px; cursor: pointer; }
.btn-xs { padding: 6px 12px; background: var(--secondary); color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.8rem;}
.text-btn { background: none; color: var(--text-muted); text-decoration: underline; margin-top: 10px; }

.hidden { display: none !important; }

/* TEACHER DASHBOARD */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 5px;
}

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

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    height: 100%;
    overflow-y: auto;
    /* Ensure grid content stretches */
    align-items: start; 
}

@media (max-width: 700px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

.control-row { margin-bottom: 15px; }
.control-row label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.flex-row {
    display: flex;
    gap: 8px;
}
.flex-row input { margin-bottom: 0; }

.status-indicator {
    margin-top: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0fdf4;
    padding: 8px;
    border-radius: 6px;
    color: #166534;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: #ccc; }
.dot.live { background: #10b981; box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2); }

/* HISTORY LIST */
#history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 40vh; /* Dynamic height */
    overflow-y: auto;
}

#history-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    animation: fadeIn 0.3s ease-in;
}

#history-list li span.time { color: var(--text-muted); font-size: 0.8rem; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* STUDENT VIEW */
.center-stage {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 90%;
}

.big-red-button {
    width: clamp(200px, 40vw, 300px); /* Responsive Size */
    height: clamp(200px, 40vw, 300px);
    border-radius: 50%;
    background: var(--danger);
    border: none;
    color: white;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.5);
    transition: transform 0.1s, background 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1.3;
    padding: 20px;
    word-wrap: break-word;
}

.big-red-button:active { transform: scale(0.95); }
.big-red-button:disabled {
    background: #cbd5e1;
    box-shadow: none;
    cursor: not-allowed;
    color: #94a3b8;
}

#cooldown-msg {
    margin-top: 25px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Keep all previous CSS. Add/Update the following: */

/* HISTORY CARD HEADER */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.history-header h3 {
    margin: 0;
}

/* LOG TYPES */
#history-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    animation: fadeIn 0.3s ease-in;
    align-items: center;
}

/* Standard Signal */
.log-signal { color: var(--text-main); }

/* Sound Activated Log */
.log-alert { 
    color: var(--danger); 
    font-weight: 700; 
    background: #fef2f2;
    padding: 8px;
    border-radius: 4px;
}

/* System Messages (Reset/Start) */
.log-system { 
    color: var(--primary); 
    font-style: italic; 
    font-size: 0.85rem; 
    background: #eff6ff;
    padding: 6px;
    border-radius: 4px;
    justify-content: center !important; /* Center text */
}

/* Hide time for system logs if desired, or keep it */
.log-system span.time { display: none; }
