:root {
    --bg-gradient: linear-gradient(135deg, #eef6ff 0%, #fef6e4 100%);
    --card-bg: #ffffff;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --info: #0284c7;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --light-sq: #f3e5ab;
    --dark-sq: #769656;
    --border-radius: 16px;
    --shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
}

/* Landing Page */
.landing-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.landing-header {
    text-align: center;
    margin-bottom: 32px;
}

.landing-header .logo-badge {
    display: inline-block;
    background: #fef08a;
    color: #854d0e;
    font-weight: 800;
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 0.9rem;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.landing-header h1 {
    font-size: 2.3rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 8px;
}

.landing-header p {
    font-size: 1.05rem;
    color: var(--text-muted);
    max-width: 540px;
    margin: 0 auto;
}

.landing-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 24px;
    width: 100%;
    max-width: 760px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 28px;
    box-shadow: var(--shadow);
    border: 2px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.card-icon {
    font-size: 2.6rem;
    margin-bottom: 12px;
}

.card h2 {
    font-size: 1.35rem;
    margin-bottom: 8px;
}

.card p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

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

.btn-success {
    background: var(--success);
    color: #fff;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.btn-success:hover {
    background: #15803d;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.input-text {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #cbd5e1;
    border-radius: 12px;
    font-size: 1.05rem;
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: border-color 0.15s;
}

.input-text:focus {
    border-color: var(--primary);
}

.error-msg {
    color: var(--danger);
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 8px;
    min-height: 20px;
    text-align: center;
}

/* Classroom / Board Page */
body.board-page {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.classroom-topbar {
    background: #ffffff;
    border-bottom: 2px solid #e2e8f0;
    padding: 7px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    flex-shrink: 0;
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.brand-mini {
    font-weight: 800;
    font-size: 1.15rem;
    color: #0f172a;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 700;
}

.pill-room {
    background: #e0e7ff;
    color: #3730a3;
}

.pill-teacher {
    background: #fef3c7;
    color: #92400e;
}

.pill-student {
    background: #dcfce7;
    color: #166534;
}

.pill-locked {
    background: #fee2e2;
    color: #991b1b;
}

.pill-unlocked {
    background: #dcfce7;
    color: #166534;
}

.btn-sm {
    padding: 7px 13px;
    font-size: 0.88rem;
    border-radius: 10px;
}

.btn-outline {
    background: #f8fafc;
    color: #334155;
    border: 2px solid #cbd5e1;
}

.btn-outline:hover {
    background: #e2e8f0;
}

/* Main Workspace */
.classroom-main {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 18px;
    padding: 10px 16px;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    --board-size: min(92vw, calc(100dvh - 125px), 660px);
}

.status-banner {
    width: var(--board-size);
    max-width: 100%;
    padding: 7px 12px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

.status-banner.unlocked {
    background: #dcfce7;
    color: #166534;
    border: 2px solid #86efac;
}

.status-banner.locked {
    background: #fee2e2;
    color: #991b1b;
    border: 2px solid #fca5a5;
}

.board-wrapper {
    position: relative;
    width: var(--board-size);
    height: var(--board-size);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.2);
    border: 5px solid #473321;
    user-select: none;
    touch-action: none;
    background: #473321;
    flex-shrink: 0;
}

.chess-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
}

.square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.square.light {
    background-color: var(--light-sq);
}

.square.dark {
    background-color: var(--dark-sq);
}

.square.last-move {
    box-shadow: inset 0 0 0 4px rgba(250, 204, 21, 0.85);
}

.square.selected {
    background-color: rgba(250, 204, 21, 0.7) !important;
}

.square.remote-selected {
    box-shadow: inset 0 0 0 4px #ec4899;
    animation: remotePulse 1.2s ease-in-out infinite;
}

@keyframes remotePulse {
    0%, 100% { box-shadow: inset 0 0 0 4px rgba(236, 72, 153, 0.95); }
    50% { box-shadow: inset 0 0 0 6px rgba(236, 72, 153, 0.45); }
}

/* Square Highlights */
.square .highlight-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.highlight-red { background: rgba(239, 68, 68, 0.58); box-shadow: inset 0 0 0 3px #dc2626; }
.highlight-green { background: rgba(34, 197, 94, 0.55); box-shadow: inset 0 0 0 3px #16a34a; }
.highlight-yellow { background: rgba(250, 204, 21, 0.62); box-shadow: inset 0 0 0 3px #ca8a04; }
.highlight-blue { background: rgba(59, 130, 246, 0.55); box-shadow: inset 0 0 0 3px #2563eb; }

/* Coordinates */
.coord-rank {
    position: absolute;
    top: 3px;
    left: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    pointer-events: none;
    z-index: 2;
    opacity: 0.75;
}

.coord-file {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    pointer-events: none;
    z-index: 2;
    opacity: 0.75;
}

.square.light .coord-rank, .square.light .coord-file { color: #5c7640; }
.square.dark .coord-rank, .square.dark .coord-file { color: #f3e5ab; }

/* Legal move dot */
.legal-dot {
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.85);
    border: 2px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.25);
    z-index: 3;
    pointer-events: none;
    animation: popIn 0.15s ease-out;
}

.legal-capture-ring {
    position: absolute;
    inset: 6%;
    border-radius: 50%;
    border: 5px solid rgba(239, 68, 68, 0.85);
    z-index: 3;
    pointer-events: none;
}

@keyframes popIn {
    from { transform: scale(0.4); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Piece SVG */
.piece-wrap {
    width: 86%;
    height: 86%;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: transform 0.1s ease;
}

.piece-wrap:hover {
    transform: scale(1.06);
}

.piece-wrap svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.28));
}

/* Arrow SVG Layer */
.arrow-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Teacher Sidebar */
.teacher-panel {
    background: #ffffff;
    border-radius: var(--border-radius);
    padding: 14px;
    box-shadow: var(--shadow);
    border: 2px solid #e2e8f0;
    width: 100%;
    max-width: 340px;
    max-height: calc(100dvh - 74px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 11px;
    flex-shrink: 0;
}

.teacher-panel .btn {
    padding: 8px 12px;
    font-size: 0.86rem;
    border-radius: 10px;
}

@media (max-width: 899px) {
    body.board-page {
        height: auto;
        min-height: 100dvh;
        overflow-y: auto;
    }
    .classroom-main {
        flex-wrap: wrap;
        overflow: visible;
    }
    .teacher-panel {
        max-width: 560px;
        max-height: none;
    }
}

.panel-section h3 {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tool-btn {
    padding: 10px 10px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    background: #f8fafc;
    color: #1e293b;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.12s;
}

.tool-btn:hover {
    background: #f1f5f9;
}

.tool-btn.active {
    background: #e0e7ff;
    border-color: var(--primary);
    color: #3730a3;
}

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

.color-swatch {
    flex: 1;
    height: 36px;
    border-radius: 10px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.12s;
}

.color-swatch:hover { transform: scale(1.05); }
.color-swatch.active { border-color: #0f172a; box-shadow: 0 0 0 2px #fff inset; }

.swatch-red { background: #ef4444; }
.swatch-green { background: #22c55e; }
.swatch-yellow { background: #eab308; }
.swatch-blue { background: #3b82f6; }

.setup-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    background: #f8fafc;
    padding: 10px;
    border-radius: 12px;
    border: 2px dashed #cbd5e1;
}

.palette-btn {
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    background: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
}

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

.action-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-celebrate {
    background: linear-gradient(135deg, #f59e0b, #ec4899);
    color: #fff;
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3);
}

.btn-lock-on {
    background: #dc2626;
    color: #fff;
}

.btn-lock-off {
    background: #16a34a;
    color: #fff;
}

/* Confetti Overlay */
#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #0f172a;
    color: #fff;
    padding: 10px 20px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.92rem;
    z-index: 10000;
    opacity: 0;
    transition: all 0.25s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Teacher Dashboard (panel.php) */
.panel-wrap {
    max-width: 920px;
    margin: 24px auto;
    padding: 0 18px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-card {
    background: #ffffff;
    border-radius: var(--border-radius);
    padding: 22px;
    box-shadow: var(--shadow);
    border: 2px solid #e2e8f0;
}

.panel-card h2 {
    font-size: 1.25rem;
    margin-bottom: 6px;
}

.panel-sub {
    color: var(--text-muted);
    font-size: 0.94rem;
    margin-bottom: 14px;
}

.panel-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

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

.create-row .input-text {
    flex: 1 1 260px;
}

.pass-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.rooms-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.room-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
}

.room-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.room-meta {
    font-size: 0.84rem;
    color: var(--text-muted);
}

.room-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

