/* ==========================================
   C-GOLEM — Soft UI / Neumorphism Design
   ========================================== */

/* --- CSS Custom Properties --- */
:root {
    /* Base Colors */
    --bg: #2d3436;
    --bg-deep: #222628;
    --surface: #353b48;
    --surface-light: #3d4452;
    --surface-dark: #2a2e35;

    /* Accent Colors */
    --primary: #0984e3;
    --primary-hover: #0a6fc2;
    --success: #00b894;
    --success-hover: #00a382;
    --warning: #fdcb6e;
    --danger: #d63031;
    --danger-hover: #c0282a;
    --accent: #6c5ce7;
    --orange: #e17055;

    /* Text */
    --text: #dfe6e9;
    --text-dim: #b2bec3;
    --text-muted: #636e72;
    --text-gold: #ffeaa7;

    /* Neumorphism Shadows */
    --shadow-out: 6px 6px 12px rgba(0,0,0,0.35), -6px -6px 12px rgba(255,255,255,0.04);
    --shadow-out-sm: 3px 3px 6px rgba(0,0,0,0.3), -3px -3px 6px rgba(255,255,255,0.03);
    --shadow-in: inset 3px 3px 6px rgba(0,0,0,0.35), inset -3px -3px 6px rgba(255,255,255,0.04);
    --shadow-in-deep: inset 4px 4px 10px rgba(0,0,0,0.5), inset -4px -4px 10px rgba(255,255,255,0.03);
    --shadow-btn: 4px 4px 8px rgba(0,0,0,0.3), -4px -4px 8px rgba(255,255,255,0.03);
    --shadow-btn-active: inset 2px 2px 5px rgba(0,0,0,0.35), inset -2px -2px 5px rgba(255,255,255,0.03);

    /* Layout */
    --radius: 14px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --gap: 12px;
}

/* --- Base Reset & Body --- */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', 'Inter', system-ui, sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    margin: 0;
    padding: 12px;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

body.in-game {
    background-image: url('images/seamless.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-deep); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* --- LOGIN / AUTH --- */
#auth-container {
    background: var(--surface);
    box-shadow: var(--shadow-out);
    padding: 32px;
    border-radius: var(--radius);
    text-align: center;
    width: 340px;
    margin: auto;
    border: none;
}

#auth-container h2 {
    margin: 0 0 20px 0;
    color: var(--text);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

#auth-container img {
    width: 100%;
    max-width: 340px;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: -32px -32px 16px -32px;
    width: calc(100% + 64px);
    display: block;
}

#auth-container input {
    display: block;
    margin: 10px auto;
    padding: 12px 14px;
    width: 100%;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--surface-dark);
    box-shadow: var(--shadow-in);
    font-size: 14px;
    color: var(--text);
    outline: none;
    transition: box-shadow 0.2s;
}

#auth-container input:focus {
    box-shadow: var(--shadow-in), 0 0 0 2px var(--primary);
}

#auth-container input::placeholder { color: var(--text-muted); }

.auth-link {
    display: block;
    margin-top: 16px;
    color: var(--primary);
    font-size: 13px;
    text-decoration: none;
    font-weight: 600;
}

.auth-link:hover { text-decoration: underline; }

#auth-msg { margin-top: 10px; color: var(--warning); font-size: 13px; }

/* --- GAME CONTAINER --- */
#game-container {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    max-width: 95%;
    width: 95%;
    height: 92vh;
}

#game-logo {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    flex-shrink: 0;
}

/* --- CANVAS --- */
#canvas-wrapper {
    position: relative;
    flex: 1;
    min-width: 300px;
    overflow: hidden;
    height: 100%;
}

canvas#gameCanvas {
    background-color: #1a1a2e;
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-out);
    display: block;
    width: 100%;
    height: 100%;
}

#resize-handle {
    position: absolute;
    right: 0; bottom: 0;
    width: 16px; height: 16px;
    cursor: ew-resize;
    background: linear-gradient(135deg, transparent 50%, var(--text-muted) 50%);
    border-radius: 0 0 var(--radius) 0;
    z-index: 5;
    opacity: 0.5;
}
#resize-handle:hover { opacity: 1; }

/* --- UI PANEL (Right Sidebar) --- */
#ui-wrapper {
    background: var(--surface);
    box-shadow: var(--shadow-out);
    padding: 14px;
    border-radius: var(--radius);
    width: 500px;
    min-width: 340px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    border: none;
    gap: 10px;
}

/* --- UI HEADER --- */
.ui-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0;
    margin-bottom: 0;
    border: none;
}

.ui-header h3 {
    margin: 0;
    color: var(--text);
    font-size: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-right {
    display: flex;
    gap: 4px;
}

/* Golem Select */
#golem-select {
    background: var(--surface-dark);
    color: var(--text-gold);
    border: none;
    box-shadow: var(--shadow-in);
    font-weight: 600;
    padding: 5px 8px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

#tick-indicator { color: var(--success); font-size: 14px; }

/* --- SOFT CARD (reusable container) --- */
.soft-card {
    background: var(--surface);
    box-shadow: var(--shadow-out-sm);
    border-radius: var(--radius-sm);
    padding: 10px;
    border: none;
}

.soft-card-inset {
    background: var(--surface-dark);
    box-shadow: var(--shadow-in);
    border-radius: var(--radius-sm);
    padding: 10px;
    border: none;
}

.soft-card-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: block;
}

/* --- HUD BADGES --- */
.hud-badges {
    display: flex;
    gap: 6px;
    margin: 0;
    align-items: stretch;
}

.badge {
    flex: 1;
    min-width: 0;
    background: var(--surface-dark);
    box-shadow: var(--shadow-in);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 12px;
    font-weight: 700;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    white-space: nowrap;
}

.badge-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.badge-sparkline {
    flex: 1;
    min-width: 25px;
    max-width: 55px;
    height: 16px;
    display: block;
}

.badge-energy { color: var(--success); }
.badge-wood { color: var(--warning); }
.badge-stone { color: var(--text-dim); }

/* --- BUTTONS --- */
button, .soft-btn {
    background: var(--surface);
    color: var(--text);
    border: none;
    font-weight: 600;
    padding: 10px 14px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    width: 100%;
    margin: 0;
    box-shadow: var(--shadow-btn);
    transition: all 0.15s ease;
    font-size: 13px;
    outline: none;
}

button:hover { filter: brightness(1.08); }
button:active { box-shadow: var(--shadow-btn-active); transform: translateY(1px); }

/* Button Variants */
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-warning { background: var(--warning); color: #333; }

.btn-orange { background: var(--orange); color: #fff; }

.btn-muted { background: var(--surface-dark); color: var(--text-dim); }

.btn-ghost {
    background: transparent;
    box-shadow: none;
    color: var(--text-dim);
    padding: 5px 8px;
}
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.btn-ghost:active { box-shadow: none; }

.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-icon { width: auto; padding: 5px 10px; font-size: 14px; }
.btn-admin { background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; letter-spacing: 0.5px; }
.btn-inline { width: auto; margin: 0; }

/* Flex utilities for button groups */
.btn-group { display: flex; gap: 6px; }
.btn-group > * { flex: 1; }
.btn-group-tight { display: flex; gap: 4px; }
.btn-group-tight > * { flex: 1; }

/* --- TABS --- */
.tabs-nav {
    display: flex;
    gap: 3px;
    background: var(--surface-dark);
    padding: 4px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-in);
    border: none;
    margin: 0;
    flex-wrap: wrap;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 7px 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all 0.2s;
    margin: 0;
    width: auto;
    box-shadow: none;
    min-width: 0;
}

.tab-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-out-sm);
}

.tab-btn:hover:not(.active) {
    color: var(--text-dim);
    background: rgba(255,255,255,0.03);
}

.tab-btn:active { transform: none; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* --- EDITOR COMPONENTS --- */
.mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--surface-dark);
    padding: 3px;
    border-radius: var(--radius-xs);
    box-shadow: var(--shadow-in);
}

.mode-toggle button {
    flex: 1;
    padding: 6px;
    font-size: 12px;
    margin: 0;
    border-radius: var(--radius-xs);
    box-shadow: none;
}

.mode-toggle .mode-active {
    background: var(--surface);
    box-shadow: var(--shadow-out-sm);
    color: var(--text);
}

.mode-toggle .mode-inactive {
    background: transparent;
    box-shadow: none;
    color: var(--text-muted);
}

#text-editor-container, #python-editor-container {
    display: flex;
    height: 180px;
    border: none;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-deep);
    box-shadow: var(--shadow-in-deep);
    margin: 0;
}

#line-numbers, #python-line-numbers {
    background: var(--surface-dark);
    color: var(--text-muted);
    text-align: right;
    padding: 6px 4px;
    min-width: 28px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    user-select: none;
    overflow: hidden;
    border-right: 1px solid rgba(255,255,255,0.05);
}

#line-numbers div, #python-line-numbers div {
    height: 20px;
    line-height: 20px;
    padding: 0 4px;
    border-radius: 2px;
}

#script, #python-script {
    flex: 1;
    border: none;
    padding: 6px 8px;
    outline: none;
    resize: none;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 20px;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
    background: transparent;
    color: #74b9ff;
    margin: 0;
}

#script::placeholder, #python-script::placeholder { color: var(--text-muted); }

/* Block Editor */
#block-editor {
    border: none;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-in);
    background: var(--surface-dark);
}

.block-editor-toolbar {
    background: var(--surface);
    padding: 4px 6px;
    display: flex;
    justify-content: flex-end;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* Script management section */
.script-select {
    flex: 1;
    padding: 7px 10px;
    background: var(--bg-deep);
    color: var(--text);
    border: none;
    border-radius: var(--radius-xs);
    font-size: 12px;
    box-shadow: var(--shadow-in);
    outline: none;
}

/* Loop checkbox */
.loop-check {
    font-size: 12px;
    cursor: pointer;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
}

.loop-check input[type="checkbox"] {
    accent-color: var(--primary);
}

/* Script error / status */
#script-error {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    display: none;
}
#script-error:not(:empty) {
    display: block;
}

/* Resume button */
.btn-resume {
    background: var(--success);
    color: #fff;
    display: none;
}

/* --- QUEST & CHALLENGE CARDS --- */
.quest-card {
    background: var(--surface-dark);
    box-shadow: var(--shadow-in);
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
}

.quest-card.completed {
    background: rgba(0, 184, 148, 0.08);
    box-shadow: var(--shadow-in), inset 0 0 0 1px rgba(0, 184, 148, 0.2);
}

.quest-title {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    margin-bottom: 4px;
}

.quest-desc {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.progress-bar-bg {
    background: var(--bg-deep);
    border-radius: 10px;
    height: 6px;
    overflow: hidden;
    border: none;
    box-shadow: var(--shadow-in);
}

.progress-bar-fill {
    background: linear-gradient(to right, var(--primary), var(--success));
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

.challenge-hint {
    font-size: 12px;
    color: var(--text-gold);
    margin-bottom: 8px;
}

/* --- ACTION LOG --- */
#log-container {
    background: var(--bg-deep);
    box-shadow: var(--shadow-in-deep);
    border: none;
    border-radius: var(--radius-sm);
    height: 250px;
    overflow-y: auto;
    padding: 8px;
    font-family: 'Consolas', monospace;
    font-size: 12px;
    color: var(--text-dim);
}

.log-entry {
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.log-time { color: var(--text-muted); margin-right: 6px; }

.log-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }

/* --- HELP --- */
.help-section {
    background: var(--surface-dark);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: none;
    box-shadow: var(--shadow-in);
    font-size: 13px;
    line-height: 1.6;
    max-height: 420px;
    overflow-y: auto;
}

.help-section h4 {
    color: var(--text);
    margin-top: 0;
    font-size: 14px;
}

.help-section h4:not(:first-child) { margin-top: 16px; }

.help-section code {
    background: var(--bg-deep);
    padding: 2px 6px;
    border-radius: 4px;
    color: #74b9ff;
    font-size: 12px;
}

.help-section ul { padding-left: 18px; }
.help-section li { margin-bottom: 3px; }

.help-section a.tutorial-link {
    display: block;
    text-align: center;
    background: var(--primary);
    color: white;
    padding: 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 700;
    margin-top: 16px;
    box-shadow: var(--shadow-btn);
}
.help-section a.tutorial-link:hover { background: var(--primary-hover); }

/* --- RANKING --- */
.ranking-title { margin-top: 0; color: var(--warning); font-size: 15px; }
.ranking-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

/* --- MANUAL CONTROL HINT --- */
.manual-hint {
    background: var(--surface-dark);
    box-shadow: var(--shadow-in);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 11px;
    color: var(--text-dim);
    position: relative;
}

.manual-hint b { color: var(--text); }
.manual-hint i { color: var(--text-muted); font-size: 10px; }

.hint-close {
    position: absolute;
    top: 4px; right: 8px;
    font-size: 15px;
    cursor: pointer;
    color: var(--text-muted);
    user-select: none;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    width: auto;
    font-weight: bold;
}
.hint-close:hover { color: var(--text); }
.hint-close:active { transform: none; box-shadow: none; }

/* --- FOOTER --- */
.ui-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.04);
}

.ui-footer a {
    color: var(--text-muted);
    text-decoration: none;
}
.ui-footer a:hover { color: var(--text-dim); }

/* --- LEGAL PANES --- */
.legal-pane h4 { margin-top: 0; color: var(--text); }
.legal-pane {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-dim);
}
.legal-pane a { color: var(--primary); }
.legal-pane b { color: var(--text); }

/* --- BLOCKLY OVERRIDES --- */
.blocklyToolboxDiv { background-color: var(--surface-dark) !important; }
.blocklyTreeLabel { color: var(--text) !important; font-weight: 600; }
.blocklyTreeRow.blocklyTreeSelected .blocklyTreeLabel,
.blocklyTreeRow:hover .blocklyTreeLabel { color: #fff !important; }
.blocklyTreeRow:hover { background-color: var(--surface-light) !important; }
.blocklyFlyoutBackground { fill: var(--surface) !important; }

/* --- UTILITY CLASSES --- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-xs { gap: 4px; }
.gap-sm { gap: 6px; }
.gap-md { gap: 10px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-xs { margin-bottom: 4px; }
.mb-sm { margin-bottom: 8px; }
.mt-sm { margin-top: 8px; }
.w-auto { width: auto; }
.w-full { width: 100%; }
.hidden { display: none; }
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
