/* ================================================================
   BRUTALCALC — SOVIET CONSTRUCTIVIST STYLESHEET
   Inspired by El Lissitzky, Rodchenko, Russian Constructivism
   NO gradients, NO border-radius, NO soft UI
   ================================================================ */

/* ── VARIABLES ─────────────────────────────────────────────── */
:root {
    --black: #0a0a0a;
    --white: #f0ece4;
    --red: #cc0000;
    --red-dark: #8a0000;
    --red-bright: #ff1111;
    --grey-dark: #1a1a1a;
    --grey-mid: #2d2d2d;
    --grey-light: #444444;
    --grey-border: #555555;
    --grey-text: #888888;
    --white-dim: #cccccc;
    --success: #2a7a2a;
    --success-bright: #44aa44;
    --error: #cc0000;
    --font-display: 'Bebas Neue', 'Oswald', sans-serif;
    --font-body: 'Oswald', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;

    --bg: var(--black);
    --surface: var(--grey-dark);
    --surface2: var(--grey-mid);
    --border: var(--grey-light);
    --text: var(--white);
    --text-dim: var(--grey-text);
    --shadow: 5px 5px 0 var(--red-dark);
}

[data-theme="light"] {
    --bg: #e8e0d0;
    --surface: #d0c8b8;
    --surface2: #c0b8a8;
    --border: #888888;
    --text: #1a1a1a;
    --text-dim: #555555;
    --shadow: 5px 5px 0 var(--red);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    letter-spacing: 0.03em;
}

/* ── NOISE TEXTURE ─────────────────────────────────────────── */
.noise-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── CONSTRUCTIVIST DECORATIONS ────────────────────────────── */
.constructivist-bar {
    position: fixed;
    background: var(--red);
    z-index: 100;
    pointer-events: none;
}

.top-bar {
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.side-bar-left {
    top: 0;
    left: 0;
    width: 4px;
    bottom: 0;
}

/* ── HEADER ────────────────────────────────────────────────── */
.site-header {
    background: var(--black);
    border-bottom: 3px solid var(--red);
    position: sticky;
    top: 0;
    z-index: 200;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    max-width: 1400px;
    margin: 0 auto;
    gap: 2rem;
    min-height: 70px;
}

.logo-block {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.logo-star {
    color: var(--red);
    font-size: 2.2rem;
    line-height: 1;
    animation: star-pulse 3s ease-in-out infinite;
}

@keyframes star-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-main {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--white);
    line-height: 1;
    letter-spacing: 0.1em;
}

.logo-sub {
    font-size: 0.55rem;
    color: var(--red);
    letter-spacing: 0.2em;
    margin-top: 2px;
}

/* ── NAV ───────────────────────────────────────────────────── */
.main-nav {
    display: flex;
    gap: 0;
    flex: 1;
    justify-content: center;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.8rem 1.2rem;
    color: var(--grey-text);
    text-decoration: none;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    border-left: 1px solid var(--grey-mid);
    border-right: 1px solid var(--grey-mid);
    margin-right: -1px;
    transition: color 0.1s, background 0.1s;
    position: relative;
}

.nav-link .nav-icon {
    color: var(--red);
    font-size: 1rem;
}

.nav-link:hover {
    color: var(--white);
    background: var(--grey-dark);
}

.nav-link.active {
    color: var(--white);
    background: var(--red);
    border-color: var(--red-dark);
}

.nav-link.active .nav-icon {
    color: var(--white);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle {
    background: var(--grey-dark);
    border: 2px solid var(--grey-border);
    color: var(--white);
    width: 44px;
    height: 44px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, border-color 0.1s;
}

.theme-toggle:hover {
    background: var(--red);
    border-color: var(--red);
}

/* ── RED DIVIDER ───────────────────────────────────────────── */
.red-divider {
    height: 3px;
    background: repeating-linear-gradient(90deg, var(--red) 0, var(--red) 20px, transparent 20px, transparent 25px);
}

/* ── MAIN CONTENT ──────────────────────────────────────────── */
.main-content {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    position: relative;
}

/* ── DIAGONAL ACCENT ───────────────────────────────────────── */
.diagonal-accent {
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 200px;
    border-top: 40px solid var(--red);
    border-right: 40px solid var(--red);
    opacity: 0.3;
    pointer-events: none;
}

/* ── PAGE HEADER ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    position: relative;
}

.page-header::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 80px;
    height: 4px;
    background: var(--red);
}

.page-header-number {
    font-family: var(--font-display);
    font-size: 5rem;
    color: var(--red);
    opacity: 0.3;
    line-height: 1;
    flex-shrink: 0;
    margin-top: -0.5rem;
}

.page-title {
    font-family: var(--font-display);
    font-size: 2.8rem;
    color: var(--text);
    letter-spacing: 0.1em;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.page-desc {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.page-header-emblem {
    margin-left: auto;
    flex-shrink: 0;
}

.emblem-shape {
    width: 64px;
    height: 64px;
    background: var(--red);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--white);
    font-family: var(--font-display);
    box-shadow: 4px 4px 0 var(--red-dark);
}

/* ── CALC LAYOUT ───────────────────────────────────────────── */
.calc-layout {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* ── PANEL ─────────────────────────────────────────────────── */
.panel {
    background: var(--surface);
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1.2rem;
    background: var(--black);
    border-bottom: 2px solid var(--border);
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.2em;
    color: var(--white);
}

.panel-header-bar {
    width: 4px;
    height: 18px;
    background: var(--red);
    flex-shrink: 0;
}

/* ── INPUT GROUP ───────────────────────────────────────────── */
.input-group {
    padding: 1.2rem 1.2rem 0;
}

.input-label {
    display: block;
    font-size: 0.65rem;
    letter-spacing: 0.25em;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.brutal-input {
    width: 100%;
    background: var(--black);
    border: 2px solid var(--grey-border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 1.3rem;
    padding: 0.8rem 1rem;
    outline: none;
    transition: border-color 0.1s;
    -webkit-appearance: none;
}

.brutal-input:focus {
    border-color: var(--red);
    box-shadow: 0 0 0 2px rgba(204,0,0,0.2);
}

.brutal-input::placeholder {
    color: var(--grey-light);
    opacity: 1;
}

.brutal-select {
    width: 100%;
    background: var(--black);
    border: 2px solid var(--grey-border);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    padding: 0.8rem 1rem;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23cc0000' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

.brutal-select:focus {
    border-color: var(--red);
}

/* ── OPERATOR GRID ─────────────────────────────────────────── */
.operator-section {
    padding: 1.2rem 1.2rem 0;
}

.operator-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border: 2px solid var(--grey-border);
    margin-top: 0.5rem;
}

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

.op-btn {
    background: var(--black);
    border: 1px solid var(--grey-border);
    color: var(--grey-text);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    text-transform: uppercase;
}

.op-btn:hover {
    background: var(--grey-mid);
    color: var(--white);
}

.op-btn.active {
    background: var(--red);
    color: var(--white);
    border-color: var(--red-dark);
}

/* ── CALC BUTTON ───────────────────────────────────────────── */
.calc-btn {
    display: block;
    width: calc(100% - 2.4rem);
    margin: 1.2rem 1.2rem;
    background: var(--red);
    border: 2px solid var(--red-dark);
    color: var(--white);
    font-family: var(--font-display);
    font-size: 1.2rem;
    letter-spacing: 0.2em;
    padding: 1rem 1.5rem;
    cursor: pointer;
    box-shadow: 4px 4px 0 var(--red-dark);
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
}

.calc-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--red-dark);
}

.calc-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 var(--red-dark);
}

.calc-btn:disabled {
    background: var(--grey-mid);
    border-color: var(--grey-border);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.danger-btn {
    background: transparent;
    border: 2px solid var(--red);
    color: var(--red);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    padding: 0.7rem 1.2rem;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    text-transform: uppercase;
}

.danger-btn:hover {
    background: var(--red);
    color: var(--white);
}

/* ── ERROR BOX ─────────────────────────────────────────────── */
.error-box {
    margin: 0 1.2rem 1.2rem;
    padding: 0.8rem 1rem;
    background: rgba(204, 0, 0, 0.1);
    border: 2px solid var(--red);
    color: var(--red);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

.error-box.hidden { display: none; }

/* ── OUTPUT AREA ───────────────────────────────────────────── */
.output-area {
    padding: 1.2rem;
    min-height: 300px;
}

.output-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    text-align: center;
    color: var(--text-dim);
    gap: 1rem;
}

.placeholder-symbol {
    font-size: 3rem;
    opacity: 0.2;
    color: var(--red);
}

.output-placeholder p {
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    line-height: 2;
}

/* ── RESULT BLOCK ──────────────────────────────────────────── */
.result-block {
    padding: 1.5rem;
    background: var(--black);
    border: 2px solid var(--grey-border);
    margin-bottom: 1.2rem;
    box-shadow: 3px 3px 0 var(--red-dark);
}

.result-value {
    font-family: var(--font-display);
    font-size: 3.5rem;
    color: var(--white);
    line-height: 1;
    margin-bottom: 0.8rem;
    word-break: break-all;
}

.result-true { color: var(--success-bright) !important; }
.result-false { color: var(--red) !important; }

.result-formula {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.1em;
}

.result-formula code {
    font-family: var(--font-mono);
    color: var(--red);
    font-size: 0.85rem;
    background: var(--grey-dark);
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--grey-border);
}

/* ── STEPS BLOCK ───────────────────────────────────────────── */
.steps-block {
    margin-top: 0.5rem;
}

.steps-title {
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.2em;
    color: var(--red);
    margin-bottom: 0.8rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--grey-border);
}

.step-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--surface2);
    font-size: 0.85rem;
}

.step-row:last-child { border-bottom: none; }

.step-num {
    width: 24px;
    height: 24px;
    background: var(--red);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-text {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text);
    word-break: break-all;
    line-height: 1.5;
}

/* ── BOOL TOGGLE ───────────────────────────────────────────── */
.bool-toggle-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 2px solid var(--grey-border);
    margin-top: 0.5rem;
}

.bool-btn {
    background: var(--black);
    border: none;
    border-right: 1px solid var(--grey-border);
    color: var(--grey-text);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.bool-btn:last-child { border-right: none; }
.bool-btn:hover { background: var(--grey-mid); color: var(--white); }
.bool-btn.active { background: var(--red); color: var(--white); }

/* ── TRUTH TABLE ───────────────────────────────────────────── */
.truth-table-wrapper { margin-top: 1rem; }

.truth-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin-top: 0.8rem;
    border: 2px solid var(--grey-border);
}

.truth-table th {
    background: var(--black);
    color: var(--red);
    padding: 0.6rem 1rem;
    text-align: center;
    border: 1px solid var(--grey-border);
    font-family: var(--font-body);
    font-size: 0.75rem;
    letter-spacing: 0.15em;
}

.truth-table td {
    padding: 0.5rem 1rem;
    text-align: center;
    border: 1px solid var(--grey-border);
    color: var(--text);
}

.truth-table tbody tr:nth-child(even) {
    background: var(--surface2);
}

/* ── TRANSFORM PAGE ────────────────────────────────────────── */
.transform-page { }

/* ── TABS ──────────────────────────────────────────────────── */
.tab-nav {
    display: flex;
    gap: 0;
    border-bottom: 3px solid var(--red);
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.tab-btn {
    background: var(--surface);
    border: 2px solid var(--grey-border);
    border-bottom: none;
    color: var(--text-dim);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    padding: 0.7rem 1.2rem;
    cursor: pointer;
    margin-right: -2px;
    transition: background 0.1s, color 0.1s;
    text-transform: uppercase;
    white-space: nowrap;
}

.tab-btn:hover { color: var(--white); background: var(--grey-mid); }
.tab-btn.active { background: var(--red); color: var(--white); border-color: var(--red-dark); }

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

/* ── HISTORY ───────────────────────────────────────────────── */
.history-page { }

.history-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding: 1rem 1.2rem;
    background: var(--surface);
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
}

.history-label {
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    margin-right: 0.5rem;
}

.history-count {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--red);
}

.history-count-block {
    display: flex;
    align-items: center;
}

.history-table-wrapper {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.history-table th {
    background: var(--black);
    color: var(--red);
    padding: 0.8rem 1rem;
    text-align: left;
    border: 1px solid var(--grey-border);
    font-family: var(--font-body);
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    white-space: nowrap;
}

.history-table td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--grey-border);
    font-size: 0.85rem;
    vertical-align: middle;
}

.history-table tbody tr { transition: background 0.1s; }
.history-table tbody tr:hover { background: var(--surface2); }
.history-table tbody tr:nth-child(even) { background: var(--surface2); }
.history-table tbody tr:nth-child(even):hover { background: var(--grey-light); }

.row-num {
    font-family: var(--font-mono);
    color: var(--text-dim);
    font-size: 0.75rem;
    text-align: center;
}

.cat-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    border: 1px solid;
}

.cat-arithmetic { color: var(--white); background: var(--grey-dark); border-color: var(--grey-border); }
.cat-logic { color: var(--red); background: rgba(204,0,0,0.1); border-color: var(--red); }
.cat-transform { color: var(--white); background: rgba(100,100,100,0.3); border-color: var(--grey-light); }

.formula-cell code {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-dim);
}

.result-cell {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--white);
}

.time-cell {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.empty-history {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--text-dim);
    text-align: center;
    border: 2px solid var(--border);
    background: var(--surface);
    gap: 1rem;
}

.empty-icon {
    font-size: 3rem;
    color: var(--red);
    opacity: 0.3;
}

.empty-history p {
    font-size: 0.8rem;
    letter-spacing: 0.2em;
}

/* ── LOADING STATE ─────────────────────────────────────────── */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem;
    color: var(--text-dim);
    font-size: 0.8rem;
    letter-spacing: 0.2em;
}

.loading-bar {
    width: 200px;
    height: 4px;
    background: var(--grey-mid);
    position: relative;
    overflow: hidden;
}

.loading-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--red);
    animation: loading-sweep 1s linear infinite;
}

@keyframes loading-sweep {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* ── FOOTER ────────────────────────────────────────────────── */
.site-footer {
    background: var(--black);
    border-top: 3px solid var(--red);
    margin-top: 3rem;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    color: var(--grey-text);
}

.footer-star {
    color: var(--red);
    margin-right: 0.5rem;
}

/* ── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .calc-layout {
        grid-template-columns: 1fr;
    }

    .header-inner {
        flex-wrap: wrap;
        padding: 0.8rem 1rem;
        gap: 0.8rem;
    }

    .main-nav {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
    }

    .main-content {
        padding: 1rem;
    }

    .page-title {
        font-size: 2rem;
    }

    .page-header-number {
        font-size: 3rem;
    }

    .result-value {
        font-size: 2.5rem;
    }

    .footer-inner {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .diagonal-accent {
        display: none;
    }
}

@media (max-width: 600px) {
    .operator-grid {
        grid-template-columns: 1fr 1fr;
    }

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

    .logo-sub {
        display: none;
    }
}
