/* Ohm's Law Calculator Styles */
/* Light/Dark theme based on calculator-styles.css */

:root {
    /* Light Theme (Default) */
    --bg-page: #f5f5f5;
    --bg-card: white;
    --bg-section: #f8f9fa;

    --text-primary: #333;
    --text-secondary: #555;
    --text-muted: #666;

    --border-color: #ddd;

    --color-accent: #2196F3;
    --color-accent-hover: #1976D2;
    --color-success: #2e7d32;

    --number-bg: #e0e0e0;
    --number-bg-active: #bdbdbd;
    --function-bg: #d0d0d0;
    --function-bg-active: #b0b0b0;

    --font-display: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Dark Theme - explicit class */
.dark-theme {
    --bg-page: #121212;
    --bg-card: #1e1e1e;
    --bg-section: #2a2a2a;

    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #888;

    --border-color: #444;

    --color-accent: #64b5f6;
    --color-accent-hover: #42a5f5;
    --color-success: #66bb6a;

    --number-bg: #333333;
    --number-bg-active: #4a4a4a;
    --function-bg: #424242;
    --function-bg-active: #616161;
}

/* Dark Theme - OS preference (when no explicit class) */
@media (prefers-color-scheme: dark) {
    :root:not(.light-theme):not(.dark-theme) {
        --bg-page: #121212;
        --bg-card: #1e1e1e;
        --bg-section: #2a2a2a;

        --text-primary: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-muted: #888;

        --border-color: #444;

        --color-accent: #64b5f6;
        --color-accent-hover: #42a5f5;
        --color-success: #66bb6a;

        --number-bg: #333333;
        --number-bg-active: #4a4a4a;
        --function-bg: #424242;
        --function-bg-active: #616161;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-display);
    background: var(--bg-page);
    height: 100%;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 12px;
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.calculator {
    width: 100%;
    max-width: 400px;
    height: 100%;
    min-height: 500px;
    max-height: 850px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: auto;
}

.display {
    flex: 0 1 auto;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: background-color 0.3s ease;
}

.values {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.value-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    height: 56px;
}

.value-label {
    font-size: 2.2rem;
    font-weight: 400;
    color: var(--text-muted);
}

.value-result {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.value-number {
    font-size: 2.2rem;
    font-weight: 500;
    color: var(--text-primary);
}

.value-unit {
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--text-muted);
}

.value-row.calculated .value-label,
.value-row.calculated .value-number,
.value-row.calculated .value-unit {
    color: var(--color-success);
}

.formula-used {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--color-success);
    height: 2rem;
    flex-shrink: 0;
}

.entry {
    background: transparent;
    padding: 8px 0;
    font-size: 2.2rem;
    font-weight: 300;
    height: 3.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    color: var(--text-primary);
}

.entry-cursor {
    display: inline-block;
    width: 2px;
    height: 0.8em;
    background: var(--color-accent);
    margin-left: 2px;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    flex-shrink: 0;
    padding-bottom: 8px;
}

.key {
    aspect-ratio: 1.6;
    border: none;
    border-radius: 12px;
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.key:active {
    transform: none;
}

/* Number keys */
.key-number {
    background: var(--number-bg);
    color: var(--text-primary);
}

.key-number:active {
    background: var(--number-bg-active);
}

/* Action key (backspace) */
.key-action {
    background: var(--function-bg);
    color: var(--text-primary);
}

.key-action:active {
    background: var(--function-bg-active);
}

/* Variable keys - accent color */
.key-variable {
    background: var(--color-accent);
    color: white;
}

.key-variable:active {
    background: var(--color-accent-hover);
}

.key-variable.disabled {
    background: var(--color-success);
    color: white;
    opacity: 0.7;
    cursor: not-allowed;
}

/* Clear button - spans full width */
.key-clear {
    grid-column: span 4;
    aspect-ratio: 7;
    background: var(--function-bg);
    color: var(--text-primary);
}

.key-clear:active {
    background: var(--function-bg-active);
}

.title {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--text-muted);
    padding: 8px 0;
    position: relative;
}

/* Theme Toggle Button */
.theme-toggle {
    position: absolute;
    right: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--function-bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Light theme (default): show moon, hide sun */
.theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0deg);
    color: #5c6bc0;
}

.theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(-90deg);
    color: #ff9800;
}

/* Dark theme: show sun, hide moon */
.dark-theme .theme-toggle .icon-moon {
    opacity: 0;
    transform: rotate(90deg);
}

.dark-theme .theme-toggle .icon-sun {
    opacity: 1;
    transform: rotate(0deg);
}

/* OS dark preference (no explicit class): show sun, hide moon */
@media (prefers-color-scheme: dark) {
    :root:not(.light-theme):not(.dark-theme) .theme-toggle .icon-moon {
        opacity: 0;
        transform: rotate(90deg);
    }

    :root:not(.light-theme):not(.dark-theme) .theme-toggle .icon-sun {
        opacity: 1;
        transform: rotate(0deg);
    }
}
