:root {
    --bg-dark: #09090b;
    --bg-panel: #18181b;
    --bg-input: #27272a;
    --border: #3f3f46;
    --border-focus: #14b8a6;
    --text: #f4f4f5;
    --text-muted: #a1a1aa;

    --hex-color: #f43f5e;
    --dec-color: #3b82f6;
    --oct-color: #eab308;
    --bin-color: #10b981;

    --ieee-sign: #f43f5e;
    --ieee-exp: #eab308;
    --ieee-mantissa: #3b82f6;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem;
}

.mono {
    font-family: 'Fira Code', monospace;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

header h1 {
    font-family: 'Fira Code', monospace;
    font-weight: 700;
    font-size: 2rem;
    color: var(--border-focus);
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.word-size-toggle,
.sign-toggle {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.word-size-toggle label,
.sign-toggle label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.word-size-toggle input,
.sign-toggle input {
    accent-color: var(--border-focus);
}

main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}

.panel-header {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 600;
}

/* BIT TOGGLES */
.bit-container {
    display: flex;
    flex-direction: row-reverse;
    /* LSB on right */
    flex-wrap: wrap;
    gap: 4px;
    justify-content: flex-end;
}

.bit-group {
    display: flex;
    flex-direction: row-reverse;
    gap: 4px;
    margin-left: 8px;
}

.bit-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.bit-index {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
}

.bit-btn {
    width: 24px;
    height: 28px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.1s;
}

.bit-btn.active {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--bin-color);
    color: var(--bin-color);
    font-weight: 600;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.2);
}

/* MAIN INPUTS */
.core-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: 600;
    font-size: 0.9rem;
}

.hex-group label {
    color: var(--hex-color);
}

.dec-group label {
    color: var(--dec-color);
}

.oct-group label {
    color: var(--oct-color);
}

.bin-group label {
    color: var(--bin-color);
}

.mono-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: 'Fira Code', monospace;
    font-size: 1.5rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    transition: all 0.2s;
    outline: none;
}

.mono-input.invalid {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
}

.mono-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.2);
}

.bin-group {
    grid-column: span 2;
}

.bin-group textarea {
    font-size: 1.25rem;
    resize: vertical;
}

/* BOTTOM GRID */
.bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1.5fr;
    gap: 1.5rem;
}

.ops-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: 'Fira Code', monospace;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    background: #2f2f36;
    border-color: var(--text-muted);
}

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

.bitwise-calc {
    display: flex;
    gap: 0.5rem;
}

.mono-input.sm {
    font-size: 1rem;
    padding: 0.5rem;
    flex: 1;
}

.interp-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}

.interp-row .label {
    color: var(--text-muted);
    font-size: 0.9rem;
    min-width: 90px;
}

.interp-row .value {
    color: var(--border-focus);
    word-break: break-all;
}

.mono-input.tiny {
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
    width: 60px;
}

.block-value {
    display: block;
    margin-top: 0.25rem;
    background: var(--bg-input);
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #27272a;
    min-height: 2.2rem;
    flex: 1;
}

.ieee-visual {
    display: flex;
    margin-top: 1rem;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    font-family: 'Fira Code', monospace;
    font-size: 0.7rem;
    text-align: center;
    line-height: 24px;
    color: #fff;
}

.ieee-part.sign {
    background: var(--ieee-sign);
    flex: 0 0 10%;
}

.ieee-part.exp {
    background: var(--ieee-exp);
    flex: 0 0 30%;
}

.ieee-part.mantissa {
    background: var(--ieee-mantissa);
    flex: 1;
}

@media (max-width: 900px) {
    .core-inputs {
        grid-template-columns: 1fr;
    }

    .bin-group {
        grid-column: span 1;
    }

    .bottom-grid {
        grid-template-columns: 1fr;
    }

    .bit-group {
        margin-left: 4px;
    }

    .bit-btn {
        width: 20px;
        height: 24px;
        font-size: 0.75rem;
    }
}