/* =====================================================
   RoboCil - Premium Kid-Friendly UI/UX v2
   Fully Responsive • Proportional • Colorful • Polished
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
    --bg: #e0f7fa;
    --bg2: #b2ebf2;
    --primary: #00bcd4;
    --primary-dark: #0097a7;
    --primary-darker: #006064;
    --secondary: #ff9800;
    --secondary-dark: #f57c00;
    --success: #4caf50;
    --success-dark: #388e3c;
    --danger: #f44336;
    --danger-dark: #c62828;
    --warning: #ffeb3b;
    --purple: #9c27b0;
    --purple-dark: #7b1fa2;
    --pink: #e91e63;
    --text: #1a237e;
    --text-muted: #546e7a;
    --white: #ffffff;
    --card-border: #80deea;
    --radius: 20px;
    --radius-sm: 14px;
    --font: 'Nunito', 'Comic Sans MS', cursive, sans-serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: linear-gradient(160deg, #e0f7fa 0%, #b2ebf2 40%, #80deea 100%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ========== TYPOGRAPHY ========== */
h1, h2, h3, h4 {
    font-weight: 800;
    color: var(--primary-darker);
    line-height: 1.25;
}

h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
h2 { font-size: clamp(1.3rem, 3vw, 1.7rem); }
h3 { font-size: clamp(1.1rem, 2.5vw, 1.35rem); }

p { color: var(--text-muted); }

a {
    color: var(--primary-dark);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover { color: var(--secondary); }

/* ========== LAYOUT ========== */
.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 18px 40px;
}

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0,96,100,0.12), 0 4px 0 var(--card-border);
    padding: clamp(18px, 4vw, 28px);
    margin-bottom: 22px;
    border: 3px solid #b2ebf2;
    position: relative;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-size: clamp(1.2rem, 3vw, 1.5rem);
}

/* ========== NAVBAR ========== */
.navbar {
    background: linear-gradient(90deg, #00acc1, #26c6da, #4dd0e1);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 4px solid #00838f;
    flex-wrap: wrap;
}

.navbar-brand {
    font-size: clamp(1.4rem, 3.5vw, 1.85rem);
    font-weight: 900;
    color: white !important;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 2px 2px 0 #006064;
    white-space: nowrap;
}

.navbar-nav {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-link {
    color: white !important;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.18);
    transition: all 0.2s;
    white-space: nowrap;
}
.nav-link:hover {
    background: rgba(255,255,255,0.35);
    transform: translateY(-1px);
}

.user-badge {
    background: #ffeb3b;
    color: #333;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 3px 0 #f9a825;
    white-space: nowrap;
}

/* ========== BUTTONS 3D ========== */
.btn-robocil {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 12px 22px;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 800;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    color: white;
    background: var(--primary);
    box-shadow: 0 6px 0 var(--primary-dark);
    transition: all 0.12s ease;
    text-decoration: none;
    user-select: none;
    line-height: 1.2;
    white-space: nowrap;
}

.btn-robocil:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--primary-dark);
    filter: brightness(1.05);
}

.btn-robocil:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--primary-dark);
}

.btn-robocil.secondary {
    background: var(--secondary);
    box-shadow: 0 6px 0 var(--secondary-dark);
}
.btn-robocil.secondary:hover { box-shadow: 0 8px 0 var(--secondary-dark); }
.btn-robocil.secondary:active { box-shadow: 0 2px 0 var(--secondary-dark); }

.btn-robocil.success {
    background: var(--success);
    box-shadow: 0 6px 0 var(--success-dark);
}
.btn-robocil.success:hover { box-shadow: 0 8px 0 var(--success-dark); }
.btn-robocil.success:active { box-shadow: 0 2px 0 var(--success-dark); }

.btn-robocil.danger {
    background: var(--danger);
    box-shadow: 0 6px 0 var(--danger-dark);
}
.btn-robocil.danger:hover { box-shadow: 0 8px 0 var(--danger-dark); }
.btn-robocil.danger:active { box-shadow: 0 2px 0 var(--danger-dark); }

.btn-robocil.purple {
    background: var(--purple);
    box-shadow: 0 6px 0 var(--purple-dark);
}
.btn-robocil.purple:hover { box-shadow: 0 8px 0 var(--purple-dark); }
.btn-robocil.purple:active { box-shadow: 0 2px 0 var(--purple-dark); }

.btn-robocil.pink {
    background: var(--pink);
    box-shadow: 0 6px 0 #ad1457;
}

.btn-robocil.warning {
    background: var(--warning);
    color: #333;
    box-shadow: 0 6px 0 #fbc02d;
}

.btn-robocil:disabled,
.btn-robocil.disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: 0 4px 0 #999 !important;
    filter: grayscale(0.4);
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.9rem;
    border-radius: 11px;
    box-shadow: 0 4px 0 var(--primary-dark);
}
.btn-sm:active { box-shadow: 0 1px 0 var(--primary-dark); }

.btn-block { width: 100%; }

/* ========== FORMS ========== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 800;
    margin-bottom: 6px;
    color: var(--primary-darker);
    font-size: 0.98rem;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    font-family: var(--font);
    font-size: 1.05rem;
    font-weight: 600;
    border: 3px solid #b2ebf2;
    border-radius: 12px;
    background: #f5fdff;
    transition: 0.2s;
    outline: none;
    color: var(--text);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0,188,212,0.22);
    background: #fff;
}

select.form-control { cursor: pointer; }

/* ========== ALERTS ========== */
.alert {
    padding: 13px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 3px solid transparent;
    font-size: 0.98rem;
}

.alert-success { background: #e8f5e9; border-color: #4caf50; color: #1b5e20; }
.alert-danger  { background: #ffebee; border-color: #f44336; color: #b71c1c; }
.alert-warning { background: #fffde7; border-color: #ffc107; color: #e65100; }
.alert-info    { background: #e0f7fa; border-color: #00bcd4; color: #006064; }

/* ========== HERO / LANDING ========== */
.hero {
    text-align: center;
    padding: clamp(24px, 5vw, 48px) 12px;
}

.hero h1 {
    font-size: clamp(2rem, 7vw, 3.2rem);
    margin-bottom: 10px;
    text-shadow: 3px 3px 0 #80deea;
}

.hero .tagline {
    font-size: clamp(1rem, 2.8vw, 1.35rem);
    color: var(--primary-darker);
    margin-bottom: 28px;
    font-weight: 700;
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
}

.hero-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin: 36px 0 20px;
}

.feature-card {
    background: white;
    border-radius: var(--radius);
    padding: 22px 16px;
    text-align: center;
    border: 3px solid #b2ebf2;
    box-shadow: 0 7px 0 #80deea;
    transition: 0.2s;
}
.feature-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 13px 0 #80deea;
}
.feature-card .emoji {
    font-size: 2.8rem;
    margin-bottom: 10px;
    display: block;
}
.feature-card h3 {
    margin-bottom: 8px;
    font-size: 1.15rem;
}
.feature-card p {
    font-size: 0.92rem;
    line-height: 1.45;
}

/* ========== LEVEL MAP ========== */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.level-card {
    aspect-ratio: 1 / 1;
    background: white;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 4px solid #b2ebf2;
    cursor: pointer;
    transition: 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    box-shadow: 0 5px 0 #80deea;
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    min-height: 0;
}

.level-card:hover:not(.locked) {
    transform: translateY(-5px) scale(1.06);
    box-shadow: 0 10px 0 #80deea;
    border-color: var(--primary);
    z-index: 2;
}

.level-card.locked {
    background: #eceff1;
    border-color: #b0bec5;
    box-shadow: 0 5px 0 #90a4ae;
    cursor: not-allowed;
    opacity: 0.88;
}

.level-card.completed {
    border-color: #4caf50;
    box-shadow: 0 5px 0 #388e3c;
    background: linear-gradient(145deg, #e8f5e9, #c8e6c9);
}

.level-card .level-num {
    font-size: clamp(1.3rem, 4vw, 1.7rem);
    font-weight: 900;
    color: var(--primary-darker);
    line-height: 1;
}

.level-card.locked .level-num { color: #78909c; }

.level-card .stars {
    font-size: clamp(0.85rem, 2.5vw, 1.05rem);
    margin-top: 4px;
    letter-spacing: -1px;
}

.level-card .lock-icon {
    font-size: 1.4rem;
    position: absolute;
    top: 6px;
    right: 6px;
}

.level-card .premium-badge {
    position: absolute;
    bottom: 5px;
    font-size: 0.65rem;
    background: linear-gradient(90deg, #ff9800, #ff5722);
    color: white;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 800;
}

/* ========== GAME BOARD ========== */
.game-area {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 12px;
    align-items: flex-start;
}

.game-board-wrapper {
    flex: 0 1 380px;
    width: 100%;
    max-width: 400px;
}

.game-board,
.studio-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    aspect-ratio: 1 / 1;
    gap: 3px;
    background: #00695c;
    border: 6px solid #004d40;
    border-radius: 18px;
    padding: 5px;
    box-shadow: 0 10px 0 #00251a, 0 0 40px rgba(0,0,0,0.18);
    width: 100%;
}

.cell {
    background: #e0f7fa;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.1rem, 3.5vw, 1.55rem);
    position: relative;
    transition: background 0.12s;
    user-select: none;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
}

.cell.wall {
    background: linear-gradient(145deg, #607d8b, #455a64);
    box-shadow: inset 0 0 0 2px #37474f;
}

.cell.target {
    background: linear-gradient(145deg, #fff9c4, #ffeb3b);
}

.cell.star { background: #fff8e1; }
.cell.trap { background: #ffcdd2; }

.cell.robot {
    background: #b2dfdb;
    z-index: 5;
}

.cell.robot .robot-emoji {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
    transition: transform 0.18s;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
    display: block;
    line-height: 1;
}

.robot-dir-right { transform: rotate(0deg); }
.robot-dir-down  { transform: rotate(90deg); }
.robot-dir-left  { transform: rotate(180deg); }
.robot-dir-up    { transform: rotate(270deg); }

/* ========== BLOCKLY ========== */
#blockly-div {
    height: 420px !important;
    width: 100%;
    min-height: 320px;
    border: 4px solid #00bcd4;
    border-radius: 14px;
    overflow: hidden;
    background: #f5f5f5;
    box-shadow: inset 0 0 0 1px #b2ebf2;
}

.blockly-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 12px 0 4px;
    align-items: center;
}

/* ========== STUDIO ========== */
.studio-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
    align-items: center;
}

.tool-btn {
    width: 48px;
    height: 48px;
    font-size: 1.45rem;
    border-radius: 12px;
    border: 3px solid #b2ebf2;
    background: white;
    cursor: pointer;
    transition: 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 0 #80deea;
}
.tool-btn:hover, .tool-btn.active {
    background: #00bcd4;
    border-color: #00838f;
    transform: scale(1.08);
    box-shadow: 0 4px 0 #006064;
    color: white;
}

.studio-grid .cell { cursor: pointer; }
.studio-grid .cell:hover {
    outline: 3px solid #ff9800;
    outline-offset: -2px;
}

/* ========== STORE ========== */
.skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 14px;
}

.skin-card {
    background: white;
    border-radius: 16px;
    padding: 16px 10px;
    text-align: center;
    border: 3px solid #b2ebf2;
    box-shadow: 0 5px 0 #80deea;
    transition: 0.15s;
}
.skin-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 9px 0 #80deea;
}
.skin-card .emoji {
    font-size: 3.2rem;
    margin-bottom: 6px;
    line-height: 1;
}
.skin-card h4 {
    font-size: 0.95rem;
    margin-bottom: 6px;
}
.skin-card.owned { border-color: #4caf50; }
.skin-card.equipped {
    border-color: #ff9800;
    background: #fff8e1;
}

/* ========== STATS ========== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    border-radius: 16px;
    padding: 16px 12px;
    text-align: center;
    border: 3px solid #b2ebf2;
    box-shadow: 0 5px 0 #80deea;
}
.stat-card .value {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 900;
    color: var(--primary-darker);
    line-height: 1.15;
}
.stat-card .label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 700;
    margin-top: 4px;
}

/* ========== TABLE ========== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}

table.robocil-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    min-width: 500px;
}

table.robocil-table th,
table.robocil-table td {
    padding: 10px 12px;
    border: 2px solid #b2ebf2;
    text-align: left;
}

table.robocil-table th {
    background: linear-gradient(90deg, #00acc1, #26c6da);
    color: white;
    font-weight: 800;
    white-space: nowrap;
}

table.robocil-table tr:nth-child(even) { background: #e0f7fa; }
table.robocil-table tr:hover { background: #b2ebf2; }

/* ========== MODAL ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,30,40,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.modal {
    background: white;
    border-radius: 24px;
    padding: 28px 22px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    border: 5px solid #00bcd4;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal h2 { margin-bottom: 10px; }

.modal .stars-display {
    font-size: 2.4rem;
    margin: 14px 0;
    letter-spacing: 2px;
}

.celebration {
    font-size: 3.5rem;
    animation: bounce 0.55s ease infinite alternate;
}
@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

/* ========== FOOTER ========== */
.footer {
    text-align: center;
    padding: 28px 16px;
    color: var(--primary-darker);
    font-size: 0.88rem;
    font-weight: 600;
    margin-top: 20px;
}

/* ========== UTILITY ========== */
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
}
.badge-premium { background: linear-gradient(90deg,#ff9800,#ff5722); color: white; }
.badge-free { background: #4caf50; color: white; }

.spinner {
    width: 40px;
    height: 40px;
    border: 5px solid #b2ebf2;
    border-top-color: #00bcd4;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
    .game-area {
        flex-direction: column;
        align-items: stretch;
    }
    
    .game-board-wrapper {
        max-width: 100%;
        flex: none;
        margin: 0 auto;
    }
    
    #blockly-div {
        height: 360px !important;
    }
}

@media (max-width: 640px) {
    .navbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 12px;
    }
    
    .navbar-nav {
        justify-content: center;
        gap: 6px;
    }
    
    .nav-link {
        font-size: 0.82rem;
        padding: 6px 10px;
    }
    
    .user-badge {
        font-size: 0.8rem;
        padding: 5px 10px;
    }
    
    .hero h1 { font-size: 1.9rem; }
    
    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
        gap: 9px;
    }
    
    .level-card .level-num { font-size: 1.25rem; }
    
    .btn-robocil {
        padding: 11px 16px;
        font-size: 0.95rem;
    }
    
    .card {
        padding: 16px 14px;
        border-radius: 16px;
    }
    
    #blockly-div {
        height: 300px !important;
        border-width: 3px;
    }
    
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .skin-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }
    
    .modal {
        padding: 22px 16px;
        border-radius: 18px;
    }
}

@media (max-width: 400px) {
    .level-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .cell {
        font-size: 1rem;
    }
    
    .cell.robot .robot-emoji {
        font-size: 1.15rem;
    }
    
    .btn-robocil {
        padding: 10px 12px;
        font-size: 0.88rem;
        gap: 4px;
    }
    
    .blockly-controls {
        gap: 6px;
    }
}

/* Blockly toolbox / workspace polish */
.blocklyToolboxDiv {
    background: #e0f7fa !important;
    border-right: 3px solid #00bcd4 !important;
}

.blocklyMainBackground {
    stroke: none !important;
}

.blocklyFlyoutBackground {
    fill: #f0fdff !important;
}
