:root {
    --bg-color: #121212;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-color: #ffffff;
    --primary-color: #00d4ff;
    /* Neon Cyan */
    --secondary-color: #ff007a;
    /* Neon Pink */
    --btn-bg: rgba(255, 255, 255, 0.05);
    --btn-hover: rgba(255, 255, 255, 0.15);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    background: radial-gradient(circle at top left, #1a0b2e, #000000);
    overflow-x: hidden;
    overflow-y: auto;
    padding: 24px 12px 40px;
}

/* Background decorative elements */
body::before,
body::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
}

body::before {
    background: var(--primary-color);
    top: -50px;
    left: -50px;
    opacity: 0.4;
}

body::after {
    background: var(--secondary-color);
    bottom: -50px;
    right: -50px;
    opacity: 0.4;
}

/* Layout Wrapper */
.app-layout {
    display: flex;
    gap: 20px;
    max-width: 95vw;
    align-items: flex-start;
    position: relative;
    /* For absolute positioning of chat if needed */
}

.main-container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 20px;
    box-shadow: var(--shadow);
    width: 420px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 10;
}

/* AI Chat Container */
.ai-chat-container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 20px;
    box-shadow: var(--shadow);
    width: 350px;
    height: 600px;
    display: flex;
    flex-direction: column;
    /* Transition for toggle */
    transition: all 0.3s ease;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 15px;
}

.chat-header h3 {
    color: var(--primary-color);
    font-weight: 600;
}

.status-dot {
    width: 10px;
    height: 10px;
    background-color: #00ff88;
    border-radius: 50%;
    box-shadow: 0 0 10px #00ff88;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 5px;
    margin-bottom: 15px;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
}

.message {
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    max-width: 85%;
}

.message.bot {
    background: rgba(255, 255, 255, 0.1);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.message.user {
    background: var(--primary-color);
    color: #000;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
    font-weight: 500;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 12px;
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    resize: none;
    font-size: 0.95rem;
    max-height: 100px;
}

.chat-actions {
    display: flex;
    gap: 5px;
}

.icon-btn,
.send-btn {
    background: transparent;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
    transition: 0.2s;
}

.send-btn {
    color: var(--secondary-color);
    font-size: 1.2rem;
}

.icon-btn:hover,
.send-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Existing Styles */
.tabs {
    display: flex;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 5px;
    overflow-x: auto;
    /* Allow scrolling if too many tabs */
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn.active {
    background: var(--primary-color);
    color: #000;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calculator {
    width: 100%;
}

.display {
    margin-bottom: 15px;
    text-align: right;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.history {
    height: 20px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    margin-bottom: 5px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.screen {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-color);
    font-size: 2.5rem;
    text-align: right;
    font-weight: 300;
}

.screen::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.btn {
    padding: 12px 0;
    border: none;
    outline: none;
    border-radius: 12px;
    background: var(--btn-bg);
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn:hover {
    background: var(--btn-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn:active {
    transform: translateY(0);
}

.num {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
}

.op {
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1.2rem;
}

.func {
    color: var(--secondary-color);
    font-size: 0.85rem;
}

.clear {
    color: #ff4444;
    font-weight: 600;
}

.equal {
    background: var(--primary-color);
    color: #000;
    font-weight: 600;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
}

.equal:hover {
    background: #33ddff;
    box-shadow: 0 0 25px rgba(0, 212, 255, 0.6);
}

/* Graphing & Analysis Styles */
.graph-controls,
.analysis-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#graph-input,
#analysis-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px;
    color: #fff;
    font-size: 1rem;
    outline: none;
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.btn-primary:hover {
    background: #33ddff;
}

#plot-container {
    width: 100%;
    height: 300px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

.result-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.result-card h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.result-card p {
    margin-bottom: 5px;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.8);
}

/* Converter Box Styles */
.converter-box {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.converter-box h3 {
    color: var(--primary-color);
    font-weight: 600;
}

.converter-box input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    font-size: 1.1rem;
    outline: none;
}

.select-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.select-group select {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px;
    color: #fff;
    outline: none;
    cursor: pointer;
}

.select-group select option {
    background: #1a0b2e;
    color: #fff;
}

.select-group span {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
}

.result-display {
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid var(--primary-color);
    border-radius: 12px;
    padding: 15px;
    color: #fff;
    font-size: 1.2rem;
    text-align: center;
    font-weight: 600;
}

.op {
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1.2rem;
}

.func {
    color: var(--secondary-color);
    font-size: 0.85rem;
}

.clear {
    color: #ff4444;
    font-weight: 600;
}

.equal {
    background: var(--primary-color);
    color: #000;
    font-weight: 600;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
}

.equal:hover {
    background: #33ddff;
    box-shadow: 0 0 25px rgba(0, 212, 255, 0.6);
}

/* Graphing & Analysis Styles */
.graph-controls,
.analysis-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#graph-input,
#analysis-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px;
    color: #fff;
    font-size: 1rem;
    outline: none;
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.btn-primary:hover {
    background: #33ddff;
}

#plot-container {
    width: 100%;
    height: 300px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

.result-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.result-card h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.result-card p {
    margin-bottom: 5px;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.8);
}

/* Converter Box Styles */
.converter-box {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.converter-box h3 {
    color: var(--primary-color);
    font-weight: 600;
}

.converter-box input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    font-size: 1.1rem;
    outline: none;
}

.select-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* Responsive adjustments */
@media (max-width: 800px) {
    .app-layout {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .main-container,
    .ai-chat-container {
        width: 100%;
        max-width: 450px;
    }

    .ai-chat-container {
        height: 400px;
    }
}

@media (max-width: 450px) {
    .main-container {
        border-radius: 0;
        padding: 15px;
    }

    .screen {
        font-size: 3rem;
    }

    #plot-container {
        height: 50vh;
    }
}

/* History Tab Styles */
.history-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 300px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-list::-webkit-scrollbar {
    width: 5px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
}

.btn-small-danger {
    background: rgba(255, 68, 68, 0.2);
    color: #ff4444;
    border: 1px solid #ff4444;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: 0.2s;
}

.btn-small-danger:hover {
    background: #ff4444;
    color: #fff;
}


/* Handwriting Styles */
#handwriting-canvas {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    cursor: crosshair;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
}

.handwriting-controls {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 20;
    display: flex;
    gap: 5px;
}

.handwriting-controls .icon-btn {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    color: #fff;
}

#graph-input,
#analysis-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px;
    color: #fff;
    font-size: 1rem;
    outline: none;
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.btn-primary:hover {
    background: #33ddff;
}

#plot-container {
    width: 100%;
    height: 300px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

.result-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.result-card h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.result-card p {
    margin-bottom: 5px;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.8);
}

/* Converter Box Styles */
.converter-box {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.converter-box h3 {
    color: var(--primary-color);
    font-weight: 600;
}

.converter-box input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 12px;
    color: #fff;
    font-size: 1.1rem;
    outline: none;
}

.select-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* Responsive adjustments */
@media (max-width: 800px) {
    .app-layout {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .main-container,
    .ai-chat-container {
        width: 100%;
        max-width: 450px;
    }

    .ai-chat-container {
        height: 400px;
    }
}

@media (max-width: 450px) {
    .main-container {
        border-radius: 0;
        padding: 15px;
    }

    .screen {
        font-size: 3rem;
    }

    #plot-container {
        height: 50vh;
    }
}

/* History Tab Styles */
.history-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 300px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-list::-webkit-scrollbar {
    width: 5px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
}

.btn-small-danger {
    background: rgba(255, 68, 68, 0.2);
    color: #ff4444;
    border: 1px solid #ff4444;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: 0.2s;
}

.btn-small-danger:hover {
    background: #ff4444;
    color: #fff;
}


/* Handwriting Styles */
#handwriting-canvas {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    cursor: crosshair;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
}

.handwriting-controls {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 20;
    display: flex;
    gap: 5px;
}

.handwriting-controls .icon-btn {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    color: #fff;
}

.handwriting-controls .icon-btn:hover {
    background: var(--primary-color);
    color: #000;
}

.hidden {
    display: none !important;
}

/* Electronics Toolkit & Logic Simulator Styles */
.electronics-toolkit,
.logic-simulator {
    display: flex;
    flex-direction: column;
    gap: 15px;
    animation: fadeIn 0.3s ease;
}

.tool-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    transition: transform 0.2s;
}

.tool-card:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.08);
}

.tool-card h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1rem;
}

.input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.input-row input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 8px;
    color: #fff;
    outline: none;
}

.gate-visualizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: inset 0 0 20px rgba(0, 212, 255, 0.05);
}

#logic-canvas {
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
}

.gate-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.gate-inputs {
    display: flex;
    gap: 20px;
    width: 100%;
    justify-content: center;
}

.gate-inputs button {
    min-width: 80px;
    background: rgba(255, 255, 255, 0.1);
}

.gate-inputs button:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Logic Studio Styles */
.logic-shell {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.logic-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.logic-title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #c7f6ff;
}

.logic-subtitle {
    margin-top: 4px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

.logic-badge {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(0, 212, 255, 0.4);
    background: rgba(0, 212, 255, 0.12);
    color: #9eefff;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.logic-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logic-palette,
.logic-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.logic-btn {
    padding: 8px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.22), rgba(0, 0, 0, 0.2));
    color: #e6fbff;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.logic-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(0, 212, 255, 0.6);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.logic-btn:active {
    transform: translateY(0);
}

.logic-btn.ghost {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-transform: none;
}

.logic-btn.danger {
    background: rgba(255, 68, 68, 0.18);
    border-color: rgba(255, 68, 68, 0.45);
    color: #ffb0b0;
    text-transform: none;
}

.logic-workspace {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.logic-panels {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.logic-card {
    padding: 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.25);
    box-shadow: inset 0 0 18px rgba(0, 212, 255, 0.04);
}

.logic-quick {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logic-card-title {
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 8px;
}

.logic-tip {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.82);
    margin-bottom: 6px;
}

.logic-tip:last-child {
    margin-bottom: 0;
}

.quick-gate-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-gate-btn {
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.06);
    color: #d5f7ff;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 62px;
}

.quick-gate-btn:hover {
    border-color: rgba(0, 212, 255, 0.5);
}

.quick-gate-btn.active {
    background: rgba(0, 212, 255, 0.22);
    border-color: rgba(0, 212, 255, 0.6);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
}

.quick-io {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.logic-bit {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.35);
    min-height: 44px;
}

.bit-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.bit-switch {
    display: flex;
    gap: 6px;
}

.bit-btn {
    width: 40px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.bit-btn.active {
    background: rgba(0, 255, 136, 0.3);
    border-color: rgba(0, 255, 136, 0.6);
    color: #00140a;
}

.bit-btn.disabled {
    opacity: 0.35;
    pointer-events: none;
}

.quick-out {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.35);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.logic-output {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #15171c;
    color: #8a8a8a;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.7);
}

.logic-output.on {
    background: #00ff88;
    color: #002212;
    border-color: rgba(0, 255, 136, 0.6);
    box-shadow: 0 0 14px rgba(0, 255, 136, 0.6), inset 0 0 8px rgba(0, 0, 0, 0.25);
}

.logic-output.off {
    background: #1c1313;
    color: #ffb0b0;
    border-color: rgba(255, 120, 120, 0.45);
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.6);
}

.quick-build {
    width: 100%;
    text-transform: none;
}

.logic-guide .guide-line {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 6px;
}

.logic-guide .guide-line:last-child {
    margin-bottom: 0;
}

.logic-templates .template-note,
.logic-save .template-note {
    margin-top: 8px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
}

.logic-truth .truth-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.truth-mode {
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

.truth-mode.active {
    background: rgba(0, 212, 255, 0.25);
    border-color: rgba(0, 212, 255, 0.6);
    color: #fff;
}

.truth-table {
    max-height: 180px;
    overflow: auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.35);
    padding: 8px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
}

.truth-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.truth-table th,
.truth-table td {
    padding: 6px 4px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.truth-table th {
    color: #c7f6ff;
    font-weight: 600;
}

.logic-tutor .tutor-step {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 10px;
}

.tutor-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.tutor-progress {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
}

.logic-save textarea {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    padding: 10px;
    font-size: 0.78rem;
    outline: none;
    resize: vertical;
}

.save-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

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

.stat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.75);
}

.stat-item strong {
    font-size: 0.9rem;
    color: #9eefff;
}

.logic-signals {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow: auto;
    padding-right: 4px;
}

.signal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
    transition: all 0.2s ease;
}

.signal-row:hover {
    border-color: rgba(0, 212, 255, 0.4);
    background: rgba(0, 212, 255, 0.08);
}

.signal-row.active {
    border-color: rgba(0, 255, 136, 0.6);
    background: rgba(0, 255, 136, 0.12);
}

.signal-name {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.75);
}

.signal-value {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
}

.signal-value.high {
    background: rgba(0, 255, 136, 0.25);
    color: #00ff88;
    border: 1px solid rgba(0, 255, 136, 0.5);
}

.signal-value.low {
    background: rgba(255, 107, 107, 0.2);
    color: #ff8b8b;
    border: 1px solid rgba(255, 107, 107, 0.4);
}

.signal-empty {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
    padding: 6px 4px;
}

.logic-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.legend-chip {
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid;
}

.legend-chip.high {
    color: #00ff88;
    border-color: rgba(0, 255, 136, 0.5);
    background: rgba(0, 255, 136, 0.12);
}

.legend-chip.low {
    color: #ff9e9e;
    border-color: rgba(255, 120, 120, 0.4);
    background: rgba(255, 120, 120, 0.12);
}

.logic-canvas-card {
    position: relative;
    min-height: 320px;
    height: 360px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    overflow: hidden;
    background:
        radial-gradient(circle at 20% 20%, rgba(0, 212, 255, 0.18), transparent 45%),
        radial-gradient(circle at 80% 70%, rgba(255, 0, 122, 0.16), transparent 45%),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 24px),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 24px),
        rgba(0, 0, 0, 0.35);
    box-shadow: inset 0 0 28px rgba(0, 212, 255, 0.1), 0 12px 30px rgba(0, 0, 0, 0.35);
}

.logic-canvas-card::after {
    content: '';
    position: absolute;
    inset: -40%;
    background: radial-gradient(circle, rgba(0, 212, 255, 0.2), transparent 60%);
    opacity: 0.6;
    animation: logicGlow 10s ease-in-out infinite;
    pointer-events: none;
}

@keyframes logicGlow {
    0% {
        transform: translate(-6%, -4%) scale(1);
    }

    50% {
        transform: translate(4%, 6%) scale(1.05);
    }

    100% {
        transform: translate(-6%, -4%) scale(1);
    }
}

#logic-canvas {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    display: block;
}

.logic-hud {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 3;
    display: flex;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.45);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}

.logic-hud-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hud-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2f2f2f;
    box-shadow: none;
}

.hud-dot.high.active {
    background: #00ff88;
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.6);
}

.hud-dot.low.active {
    background: #ff6b6b;
    box-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

.hud-monitor {
    padding-left: 4px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

@media (max-width: 520px) {
    .logic-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .logic-badge {
        align-self: flex-start;
    }

    .logic-canvas-card {
        height: 300px;
    }
}

@media (min-width: 520px) {
    .logic-panels {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
