/* ========================================
   Numi Web - Refined Minimalist Theme
   A calculator that feels like a blank canvas
   ======================================== */

/* ========================================
   Design Tokens
   ======================================== */
:root {
    /* Light Theme - Warm Paper */
    --bg-canvas: #fafaf9;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-subtle: #f5f5f4;
    --bg-muted: #e7e5e4;

    --text-primary: #1c1917;
    --text-secondary: #57534e;
    --text-muted: #a8a29e;
    --text-placeholder: #d6d3d1;

    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --accent-muted: #93c5fd;

    --success: #059669;
    --error: #dc2626;

    --border-subtle: #e7e5e4;
    --border-muted: #f5f5f4;

    /* Shadows - Soft & Diffused */
    --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-md: 0 4px 12px rgba(28, 25, 23, 0.06), 0 1px 3px rgba(28, 25, 23, 0.04);
    --shadow-lg: 0 12px 32px rgba(28, 25, 23, 0.08), 0 4px 8px rgba(28, 25, 23, 0.04);
    --shadow-float: 0 20px 40px rgba(28, 25, 23, 0.1), 0 8px 16px rgba(28, 25, 23, 0.06);

    /* Typography */
    --font-display: 'Instrument Serif', Georgia, serif;
    --font-body: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-8: 3rem;
    --space-10: 4rem;
    --space-12: 6rem;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Syntax - Soft pastels */
    --syntax-number: #2563eb;
    --syntax-unit: #059669;
    --syntax-currency: #d97706;
    --syntax-operator: #a8a29e;
    --syntax-function: #db2777;
    --syntax-variable: #7c3aed;
    --syntax-bracket: #a8a29e;
}

[data-theme="dark"] {
    --bg-canvas: #0c0a09;
    --bg-surface: #1c1917;
    --bg-elevated: #292524;
    --bg-subtle: #1c1917;
    --bg-muted: #292524;

    --text-primary: #fafaf9;
    --text-secondary: #a8a29e;
    --text-muted: #78716c;
    --text-placeholder: #57534e;

    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --accent-muted: #3b82f6;

    --success: #34d399;
    --error: #f87171;

    --border-subtle: #292524;
    --border-muted: #1c1917;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4), 0 4px 8px rgba(0, 0, 0, 0.2);
    --shadow-float: 0 20px 40px rgba(0, 0, 0, 0.5), 0 8px 16px rgba(0, 0, 0, 0.3);

    --syntax-number: #93c5fd;
    --syntax-unit: #6ee7b7;
    --syntax-currency: #fcd34d;
    --syntax-operator: #78716c;
    --syntax-function: #f9a8d4;
    --syntax-variable: #c4b5fd;
    --syntax-bracket: #78716c;
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-body);
    background: var(--bg-canvas);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--duration-slow) var(--ease-out),
                color var(--duration-slow) var(--ease-out);
}

::selection {
    background: var(--accent-soft);
    color: var(--accent);
}

/* ========================================
   App Layout - Centered Canvas
   ======================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-5);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Header - Minimal & Elegant
   ======================================== */
.header {
    padding: var(--space-4) 0;
    margin-bottom: var(--space-6);
}

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

.logo {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 400;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
}

.logo::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: var(--radius-full);
    opacity: 0.8;
}

.header-actions {
    display: flex;
    gap: var(--space-2);
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-icon:hover {
    background: var(--bg-subtle);
    color: var(--text-secondary);
}

.btn-icon:active {
    transform: scale(0.95);
}

.btn-icon svg {
    stroke-width: 1.5;
}

/* ========================================
   Main Content Area
   ======================================== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.content-wrapper {
    display: flex;
    flex-direction: row;
    gap: var(--space-5);
    flex: 1;
    align-items: flex-start;
}

/* ========================================
   Editor - The Canvas
   ======================================== */
.editor-container {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--space-6);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-muted);
    transition: box-shadow var(--duration-normal) var(--ease-out);
    min-height: 500px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

.editor-container:focus-within {
    box-shadow: var(--shadow-float);
}

.editor {
    flex: 1;
    display: flex;
    flex-direction: column;
}

#linesContainer {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* ========================================
   Calculation Lines - Clean & Focused
   ======================================== */
.calculation-line {
    display: flex;
    align-items: flex-start;
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast) var(--ease-out);
    animation: lineAppear var(--duration-normal) var(--ease-out);
}

@keyframes lineAppear {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calculation-line.removing {
    animation: lineRemove var(--duration-fast) var(--ease-out) forwards;
}

@keyframes lineRemove {
    to {
        opacity: 0;
        transform: translateX(-8px);
        height: 0;
        padding: 0;
        margin: 0;
    }
}

.line-content {
    display: flex;
    width: 100%;
    gap: var(--space-5);
    align-items: flex-start;
}

.line-input-wrapper {
    flex: 1;
    position: relative;
    min-width: 0;
}

/* Input & Syntax Overlay */
.line-input,
.syntax-overlay {
    font-family: var(--font-mono);
    font-size: 1.0625rem;
    line-height: 1.7;
    width: 100%;
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    letter-spacing: -0.01em;
    font-weight: 400;
}

.line-input {
    color: transparent;
    caret-color: var(--accent);
    position: relative;
    z-index: 2;
    outline: none;
    resize: none;
    overflow: hidden;
    -webkit-text-fill-color: transparent;
}

.line-input::placeholder {
    color: var(--text-placeholder);
    -webkit-text-fill-color: var(--text-placeholder);
    font-style: italic;
    font-weight: 300;
}

.syntax-overlay {
    position: absolute;
    top: 0;
    left: 0;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 1;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Syntax Highlighting - Subtle Colors */
.syntax-number {
    color: var(--syntax-number);
}

.syntax-unit {
    color: var(--syntax-unit);
    font-weight: 500;
}

.syntax-currency {
    color: var(--syntax-currency);
    font-weight: 500;
}

.syntax-operator {
    color: var(--syntax-operator);
}

.syntax-function {
    color: var(--syntax-function);
}

.syntax-variable {
    color: var(--syntax-variable);
    font-weight: 500;
}

.syntax-bracket {
    color: var(--syntax-bracket);
}

.syntax-bracket.matched {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 1px;
}

/* Results - Right Aligned, Elegant */
.line-result {
    font-family: var(--font-mono);
    font-size: 1.0625rem;
    font-weight: 500;
    color: var(--accent);
    min-width: 100px;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding-top: 2px;
    line-height: 1.7;
}

.line-result.error {
    color: var(--error);
    font-weight: 400;
    font-size: 0.875rem;
}

.result-text {
    transition: opacity var(--duration-fast) var(--ease-out);
}

.result-text.pulse {
    animation: resultPulse var(--duration-normal) var(--ease-spring);
}

@keyframes resultPulse {
    0% {
        opacity: 0;
        transform: translateX(8px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Copy Button */
.copy-btn {
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast) var(--ease-out);
    display: flex;
    align-items: center;
    justify-content: center;
}

.line-result:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: var(--bg-subtle);
    color: var(--text-secondary);
}

.copy-btn.copied {
    color: var(--success);
    opacity: 1;
}

/* ========================================
   Variables Panel - Floating Card
   ======================================== */
.variables-panel {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-muted);
    display: none; /* Hidden by default, shown when variables exist */
}

.variables-panel:has(.variable-item) {
    display: block;
    animation: panelAppear var(--duration-normal) var(--ease-out);
}

@keyframes panelAppear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.variables-header {
    margin-bottom: var(--space-3);
}

.variables-header h3 {
    font-family: var(--font-body);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
}

.variables-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.variable-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    transition: all var(--duration-fast) var(--ease-out);
}

.variable-item:hover {
    background: var(--bg-muted);
}

.var-name {
    color: var(--syntax-variable);
    font-weight: 600;
}

.variable-equals {
    color: var(--text-muted);
}

.var-value {
    color: var(--text-secondary);
}

/* ========================================
   Examples - Inline Hints
   ======================================== */
.examples-panel {
    margin-top: auto;
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-muted);
}

.examples-panel h3 {
    font-family: var(--font-body);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: var(--space-3);
}

.examples-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.example-item {
    display: inline-flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.example-item:hover {
    background: var(--bg-surface);
    border-color: var(--border-subtle);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.example-item:active {
    transform: translateY(0);
}

.example-arrow {
    display: none;
}

/* ========================================
   Help Panel - Side Panel
   ======================================== */
.help-panel {
    flex: 0 0 340px;
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-muted);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 500px;
    max-height: calc(100vh - 160px);
    position: sticky;
    top: var(--space-6);
}

.help-tabs {
    display: flex;
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--border-muted);
    background: var(--bg-subtle);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.help-tabs::-webkit-scrollbar {
    display: none;
}

.help-tab {
    padding: var(--space-3) var(--space-4);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.8125rem;
    transition: all var(--duration-fast) var(--ease-out);
    margin-bottom: -1px;
}

.help-tab:hover {
    color: var(--text-secondary);
}

.help-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--bg-surface);
}

.help-content {
    padding: var(--space-5);
    max-height: 400px;
    overflow-y: auto;
}

.help-content::-webkit-scrollbar {
    width: 6px;
}

.help-content::-webkit-scrollbar-track {
    background: transparent;
}

.help-content::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}

.help-tab-content {
    display: none;
}

.help-tab-content.active {
    display: block;
    animation: fadeIn var(--duration-normal) var(--ease-out);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.help-section {
    margin-bottom: var(--space-6);
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: var(--space-3);
    color: var(--text-primary);
}

.help-examples {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.help-example {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    transition: all var(--duration-fast) var(--ease-out);
}

.help-example:hover {
    background: var(--bg-surface);
    border-color: var(--border-subtle);
}

.help-example code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.try-btn {
    padding: var(--space-1) var(--space-3);
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.try-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

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

/* Tips */
.help-tips {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tip-item {
    padding: var(--space-3) var(--space-4);
    background: var(--accent-soft);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent);
}

.tip-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ========================================
   Custom Scrollbar
   ======================================== */
.editor-container::-webkit-scrollbar {
    width: 6px;
}

.editor-container::-webkit-scrollbar-track {
    background: transparent;
}

.editor-container::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}

.editor-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 900px) {
    .content-wrapper {
        flex-direction: column;
    }

    .help-panel {
        flex: none;
        width: 100%;
        max-height: 400px;
        position: static;
        order: 2;
    }

    .editor-container {
        max-height: none;
        min-height: 350px;
        order: 1;
    }

    .variables-panel {
        order: 3;
    }
}

@media (max-width: 640px) {
    .container {
        padding: var(--space-4) var(--space-4);
    }

    .header {
        margin-bottom: var(--space-4);
    }

    .logo {
        font-size: 1.5rem;
    }

    .editor-container {
        padding: var(--space-4);
        border-radius: var(--radius-lg);
        min-height: 280px;
    }

    .line-input,
    .syntax-overlay,
    .line-result {
        font-size: 0.9375rem;
    }

    .line-content {
        flex-direction: column;
        gap: var(--space-2);
    }

    .line-result {
        text-align: left;
        justify-content: flex-start;
        padding-left: 0;
        min-width: auto;
        padding-top: 0;
        opacity: 0.9;
    }

    .examples-panel {
        padding-top: var(--space-4);
    }

    .example-item {
        font-size: 0.75rem;
        padding: var(--space-1) var(--space-2);
    }

    .variables-panel {
        padding: var(--space-3) var(--space-4);
    }

    .variable-item {
        font-size: 0.75rem;
        padding: var(--space-1) var(--space-2);
    }

    .help-panel {
        max-height: 350px;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    body {
        background: white;
    }

    .header-actions,
    .examples-panel,
    .help-panel,
    .copy-btn {
        display: none !important;
    }

    .editor-container {
        box-shadow: none;
        border: 1px solid #e5e5e5;
    }
}

/* ========================================
   Focus States (Accessibility)
   ======================================== */
.btn-icon:focus-visible,
.example-item:focus-visible,
.try-btn:focus-visible,
.help-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.line-input:focus {
    outline: none;
}

/* ========================================
   Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
