/* ==========================================================================
   THE TIME REVERSAL - APP & CALCULATOR THEME (UNIFIED HEADER)
   ========================================================================== */

:root {
    /* Unified Header & Global Colors */
    --bg:            #0d1117;
    --bg-card:       #161b22;
    --bg-box:        #1c2333;
    --border:        #30363d;
    --text:          #e6edf3;
    --text-muted:    #8b949e;
    --gold-light:    #f0c060;
    
    /* App Specific Colors */
    --gold-dim:      #a07d1a;
    --app-bg:        #0d0d0d;
    --surface:       #181818;
    --surface-2:     #222222;
    --primary:       #8AB4F8;
    --primary-hover: #aac8ff;
    --text-main:     #E8EAED;
    --border-color:  #2e2e2e;
    --accent-blue:   var(--primary);
    --btn-bg:        #252525;
    --btn-hover:     #303030;
    --bg-color:      var(--app-bg);

    /* Premium Upgrade Tokens */
    --gold-glow:     rgba(201, 162, 39, 0.10);
    --gold-border:   rgba(201, 162, 39, 0.20);
    --gold-mid:      #c9a227; 
    --surface-hover: #202020;
    --border-subtle: rgba(255,255,255,0.05);
    
    /* Geometry & Shadows */
    --radius-btn:    50px;
    --shadow-sm:     0 1px 4px rgba(0,0,0,0.4);
    --shadow-md:     0 4px 20px rgba(0,0,0,0.5);
}

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

html {
    height: 100%;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--app-bg);
    color: var(--text-main);
    font-family: 'Source Serif 4', Georgia, serif;
    line-height: 1.6;
    overflow-x: hidden;
    background-image: radial-gradient(ellipse 70% 35% at 50% 0%, rgba(201,162,39,0.04) 0%, transparent 60%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Plotter page needs hard 100vh with no scroll */
body.plotter-page {
    height: 100vh;
    overflow: hidden;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ==========================================================================
   --- 1. UNIFIED HEADER & NAV ---
   ========================================================================== */
header.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    box-shadow: inset 0 1px 0 rgba(201,162,39,0.10), 0 1px 4px rgba(0,0,0,0.4);
    border-bottom-color: rgba(201,162,39,0.12);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
}

/* Fixed line-heights for logo text */
.header-inner > div {
    display: flex;
    flex-direction: column;
    gap: 0;
    line-height: 1;
}

.site-logo {
    width: 48px; 
    height: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    
}

.site-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain; 
    filter: invert(1) opacity(0.85); 
}

.site-name {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--gold-light);
    line-height: 1.2;
    margin-bottom: 2px;
    background: linear-gradient(135deg, #e2c06a 0%, #c9a227 55%, #a07d1a 100%);

    background-clip: text;
}

.site-tagline {
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    font-family: 'Source Serif 4', serif;
    font-style: italic;
    line-height: 1.2;
    margin-top: 0;
    margin-bottom: 0;
    display: block;
}

.nav-links {
    margin-left: auto;
    display: flex; 
    gap: 2rem;
    list-style: none;
}

.nav-links a {
    color: #d4a843; 
    text-decoration: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    transition: color 0.2s;
    text-transform: uppercase;
}

.nav-links a:hover, .nav-links a.active { 
    color: #f0c060; 
}

.lang-switcher {
    background: var(--bg-box);
    padding: 4px;
    border-radius: var(--radius-btn);
    display: flex;
    gap: 2px;
    align-items: center;
    margin-left: auto;
}

.lang-btn {
    text-decoration: none;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: var(--radius-btn);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.lang-btn.active {
    background: var(--surface);
    color: var(--gold-light);
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   --- 2. MAIN LAYOUT (CALCULATOR PAGE) ---
   ========================================================================== */
.main-wrapper {
    display: grid;
    grid-template-columns: 340px 620px 340px;
    gap: 20px;
    max-width: 1400px;
    margin: 24px auto 40px auto;
    padding: 0 24px;
    align-items: start;
    flex: 1;
}

.journal-entry {
    background: var(--surface);
    color: var(--text-main);
    padding: 28px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.journal-entry::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(201,162,39,0.2), transparent);
    pointer-events: none;
}

/* ==========================================================================
   --- 3. SYMMETRY INSPECTOR ---
   ========================================================================== */
.content {
    width: 92%;
    max-width: 1400px;
    margin: 28px auto;
    padding: 32px;
    background-color: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    flex: 1;
    position: relative;
    overflow: hidden;
}

.content::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(201,162,39,0.28), transparent);
    pointer-events: none;
}

/* Table */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 20px 0;
    font-family: 'Times New Roman', serif;
    table-layout: auto;
}

th, td {
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    text-align: center;
    color: var(--text-main);
}

th {
    background-color: #1f1f1f;
    color: var(--gold-mid);
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.95rem; 
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: none !important;
    white-space: nowrap;
    padding: 10px 8px;
    border-bottom: 1px solid rgba(201,162,39,0.18);
}

tr:nth-child(even) td { background-color: #1f1f1f; }
tr:nth-child(odd)  td { background-color: var(--surface); }
tr:hover td { background-color: rgba(201,162,39,0.04); transition: background 0.15s; }

/* Inputs & Select */
input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem; 
    background-color: var(--surface-2);
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

select {
    border-color: var(--gold-border);
    padding-right: 32px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c9a227' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--gold-mid);
    box-shadow: 0 0 0 3px var(--gold-glow);
}

select option {
    background-color: var(--surface-2);
    color: var(--text-main);
}

#input-section { margin-top: 24px; }
#input-section p {
    color: var(--text-muted);
    margin-bottom: 12px;
    font-size: 0.88rem;
}

#dynamic-inputs {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 10px;
    margin: 16px 0;
    overflow-x: auto;
    padding-bottom: 8px;
}

.char-case {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.char-case input {
    width: 52px;
    text-align: center;
    background-color: var(--surface-2);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 4px;
    font-size: 0.88rem;
}

.char-case input:focus {
    outline: none;
    border-color: var(--gold-mid);
    box-shadow: 0 0 0 3px var(--gold-glow);
}

.char-case label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

#output {
    font-size: 1.3rem;
    font-family: 'Times New Roman', serif;
    color: var(--text-main);
}

#table-container { width: 100%; overflow-x: auto; }

#result-display {
    margin-top: 28px;
    padding: 18px 20px;
    background: linear-gradient(135deg, #0f1e2e, #111a26);
    border-left: 4px solid var(--primary);
    color: var(--text-main);
    border-radius: 0 10px 10px 0;
}

#result-display h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* ==========================================================================
   --- 4. CALCULATOR BUTTONS ---
   ========================================================================== */
.calc-display { width: 100%; margin-bottom: 16px; }

#calc-input {
    width: 100%;
    box-sizing: border-box;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.4rem;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 8px;
    outline: none;
    background-color: var(--surface-2);
    color: var(--text-main);
    transition: border-color 0.2s;
}

#calc-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(138,180,248,0.1);
}

#calc-result {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-main) !important;
    text-align: right;
    min-height: 36px;
    padding: 0 8px;
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.calc-btn {
    background-color: var(--btn-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 14px 0;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.08s;
    font-family: inherit;
    font-weight: 500;
}

.calc-btn:hover  { background-color: var(--btn-hover); }
.calc-btn:active { transform: scale(0.96); }

.calc-btn.op {
    background-color: #1e2530;
    color: var(--primary);
    font-weight: 600;
}
.calc-btn.op:hover { background-color: #252e3d; }

.calc-btn.eval {
    background-color: var(--primary);
    color: #0d0d0d;
    font-weight: 700;
    border: none;
}
.calc-btn.eval:hover { background-color: var(--primary-hover); }

.calc-btn.clear {
    background-color: #2a1010;
    color: #ff9f9f;
    border-color: #3d1515;
}
.calc-btn.clear:hover { background-color: #3d1515; }

/* Backspace Button */
.calc-btn.btn-back {
    background-color: rgba(227, 160, 99, 0.12);
    color: var(--orange);
    border-color: rgba(227, 160, 99, 0.25);
}
.calc-btn.btn-back:hover { background-color: rgba(227, 160, 99, 0.22); }

/* Ans Button */
.calc-btn.btn-ans {
    background-color: rgba(212, 168, 67, 0.12);
    color: var(--gold-light);
    border-color: rgba(212, 168, 67, 0.25);
}
.calc-btn.btn-ans:hover { background-color: rgba(212, 168, 67, 0.22); }

button {
    background-color: var(--btn-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 9px 22px;
    font-size: 0.88rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}
button:hover { background-color: var(--btn-hover); }

.reset-btn {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 9px 22px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    transition: background 0.15s, color 0.15s;
}
.reset-btn:hover { background-color: var(--surface-2); color: var(--text-main); }

.button-group { display: flex; gap: 10px; margin-top: 18px; }

/* Premium Upgrade for Calculate Button */
.button-group button:first-child:not(.reset-btn) {
    background: linear-gradient(135deg, rgba(201,162,39,0.18), rgba(201,162,39,0.08));
    border-color: var(--gold-border);
    color: #e2c06a;
    font-weight: 600;
}
.button-group button:first-child:not(.reset-btn):hover {
    background: linear-gradient(135deg, rgba(201,162,39,0.26), rgba(201,162,39,0.12));
    border-color: var(--gold-mid);
    box-shadow: 0 4px 20px rgba(201,162,39,0.12);
    color: #f0d98a;
}

/* ==========================================================================
   --- 5. DIMENSIONAL PLOTTER ---
   ========================================================================== */
.top-nav {
    background: rgba(13,13,13,0.97);
    padding: 10px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.back-link {
    text-decoration: none;
    color: var(--primary);
    font-weight: 500;
    font-size: 0.82rem;
    letter-spacing: 0.03em;
    transition: color 0.2s;
}
.back-link:hover { color: var(--primary-hover); }

.logo-text {
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    padding: 18px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.control-group { margin-bottom: 14px; }

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.flex-row { display: flex; gap: 8px; }

.hint {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.error-text {
    color: #ff6b6b;
    font-size: 0.8rem;
    margin-top: 8px;
    font-weight: 600;
}

.primary-btn {
    width: 100%;
    background: var(--primary);
    color: #0d0d0d;
    border: none;
    padding: 10px;
    font-size: 0.88rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: background 0.2s, transform 0.08s;
    margin-top: 6px;
}
.primary-btn:hover  { background: var(--primary-hover); }
.primary-btn:active { transform: scale(0.98); }

.plot-area {
    flex: 1;
    padding: 12px;
    display: flex;
    min-width: 0;
    min-height: 0;
}

#plotContainer {
    width: 100%;
    height: 100%;
    background: #0d0d0d;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

/* ==========================================================================
   --- 6. SIDEBARS & CONSTANT LISTS ---
   ========================================================================== */
.sidebar-box {
    background: var(--surface);
    color: var(--text-main);
    padding: 22px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.sidebar-box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(201,162,39,0.2), transparent);
    pointer-events: none;
}

.sidebar-title {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gold-mid);
    border-bottom: 1px solid rgba(201,162,39,0.14);
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.constant-list { list-style: none; padding: 0; margin: 0; }

.constant-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding: 6px 0;
}

.constant-list li:hover {
    background-color: var(--surface-2);
    border-radius: 4px;
    padding-left: 4px;
    transition: all 0.15s;
}

.constant-item-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
    cursor: pointer;
    padding-right: 10px;
}

.constant-item-content:hover .const-name { color: var(--accent-blue); }

.const-left {
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex: 1;
    min-width: 0;
}

.const-name {
    font-weight: 700;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    flex-shrink: 0;
    color: var(--text-main);
    transition: color 0.15s;
}

.const-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.const-val {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8rem;
    margin-left: auto;
    flex-shrink: 0;
    color: var(--primary);
}

.delete-btn {
    background: none;
    border: none;
    color: #4a2020;
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 4px;
    transition: color 0.15s;
}
.delete-btn:hover { color: #ff6b6b; }

.custom-form input {
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--surface-2);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
}

.custom-form button { width: 100%; margin-top: 4px; }

/* ==========================================================================
   --- 7. FOOTER ---
   ========================================================================== */
footer {
    text-align: center;
    padding: 12px 20px;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(201,162,39,0.10);
    background-color: var(--surface);
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
    margin-top: auto;
}

footer a {
    color: var(--gold-dim);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

footer a:hover { color: var(--gold-light); }

/* ==========================================================================
   --- 8. RESPONSIVE ---
   ========================================================================== */
@media (max-width: 1400px) {
    .main-wrapper {
        grid-template-columns: 1fr;
        max-width: 780px;
    }
}

@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .site-tagline { display: none; }
    header.site-header { padding: 0 1rem; }
}

@media (max-width: 600px) {
    .calc-grid { grid-template-columns: repeat(4, 1fr); }
    .const-desc { display: none; }
}
