/* ========================================
   TRIAD CALCULATOR
   ======================================== */

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    color-scheme: dark;

    --bg: #0b0b0b;
    --surface: #141414;
    --button: #1d1d1d;
    --button-hover: #292929;
    --text: #f5f5f5;
    --muted: #858585;
    --accent: #d7ff6b;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: rgba(0, 0, 0, 0.35);
}

body.light-mode {
    color-scheme: light;

    --bg: #f4f4f0;
    --surface: #ffffff;
    --button: #f0f0ec;
    --button-hover: #e4e4df;
    --text: #171717;
    --muted: #777777;
    --accent: #b6df38;
    --border: rgba(0, 0, 0, 0.08);
    --shadow: rgba(0, 0, 0, 0.12);
}

/* Base */
body {
    min-height: 100vh;
    min-height: 100dvh;

    background: var(--bg);
    color: var(--text);

    font-family: Arial, Helvetica, sans-serif;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 20px;

    transition:
        background 0.25s ease,
        color 0.25s ease;
}

body.menu-open {
    overflow: hidden;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
    border: none;
    cursor: pointer;
}

button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

/* App */
.app-container {
    width: 100%;
    max-width: 390px;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 35px;
}

.logo {
    color: var(--text);
    text-decoration: none;

    font-size: 25px;
    font-weight: 800;
    letter-spacing: 4px;
}

.logo span,
.about-logo span {
    color: var(--accent);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-button {
    width: 42px;
    height: 42px;

    display: flex;
    justify-content: center;
    align-items: center;

    background: var(--surface);
    color: var(--text);

    border: 1px solid var(--border);
    border-radius: 50%;

    transition:
        background 0.2s ease,
        transform 0.2s ease;
}

.icon-button:hover {
    background: var(--button-hover);
}

.theme-toggle {
    font-size: 19px;
}

.menu-toggle {
    flex-direction: column;
    gap: 5px;
}

.menu-toggle span {
    width: 17px;
    height: 2px;

    border-radius: 2px;
    background: var(--text);

    transition:
        transform 0.2s ease,
        opacity 0.2s ease;
}

/* Calculator */
.calculator,
.page-view {
    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 25px;
    padding: 22px;

    box-shadow: 0 20px 60px var(--shadow);
}

/* View navigation */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: view-enter 0.22s ease;
}

@keyframes view-enter {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Calculator display */
.display {
    min-height: 135px;

    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;

    padding: 15px 5px 25px;
    overflow: hidden;
}

.history {
    min-height: 24px;
    margin-bottom: 10px;

    color: var(--muted);
    font-size: 14px;
    text-align: right;
    overflow-wrap: anywhere;
}

.display-value {
    width: 100%;

    color: var(--text);
    text-align: right;

    font-size: clamp(32px, 10vw, 46px);
    font-weight: 500;
    letter-spacing: -1px;

    overflow-wrap: anywhere;
}

/* Calculator buttons */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.btn {
    min-width: 0;
    aspect-ratio: 1 / 0.9;

    background: var(--button);
    color: var(--text);

    border-radius: 15px;

    font-size: 20px;
    font-weight: 500;

    transition:
        background 0.15s ease,
        transform 0.1s ease;
}

.btn:hover {
    background: var(--button-hover);
}

.btn:active {
    transform: scale(0.94);
}

.utility {
    color: var(--muted);
    font-size: 16px;
}

.operator {
    color: var(--accent);
    font-size: 25px;
}

.equals {
    background: var(--accent);
    color: #171717;

    font-size: 26px;
    font-weight: 700;
}

.equals:hover {
    background: var(--accent);
    filter: brightness(0.94);
}

/* Footer */
.footer-text {
    margin-top: 22px;

    color: var(--muted);
    text-align: center;

    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* ========================================
   NAVIGATION DRAWER
   ======================================== */

.menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;

    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);

    opacity: 0;
    visibility: hidden;

    transition:
        opacity 0.25s ease,
        visibility 0.25s ease;
}

.menu-overlay.open {
    opacity: 1;
    visibility: visible;
}

.side-menu {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 101;

    width: min(320px, 88vw);
    height: 100vh;
    height: 100dvh;

    display: flex;
    flex-direction: column;

    padding: 25px 22px;

    background: var(--surface);
    border-left: 1px solid var(--border);

    transform: translateX(105%);
    visibility: hidden;

    transition:
        transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0.3s ease;
}

.side-menu.open {
    transform: translateX(0);
    visibility: visible;
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    padding-bottom: 30px;
    border-bottom: 1px solid var(--border);
}

.menu-header .logo {
    font-size: 22px;
}

.close-button {
    font-size: 27px;
    font-weight: 300;
}

.menu-caption {
    margin: 28px 0 15px;

    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2px;
}

.menu-links {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.menu-link {
    display: grid;
    grid-template-columns: 28px 1fr 16px;
    align-items: center;
    gap: 12px;

    width: 100%;
    padding: 15px 12px;

    background: transparent;
    color: var(--text);

    border-radius: 12px;
    text-align: left;
    font-size: 14px;

    transition:
        background 0.2s ease,
        color 0.2s ease;
}

.menu-link:hover {
    background: var(--button);
}

.menu-link:active {
    background: var(--button-hover);
}

.menu-icon {
    color: var(--accent);
    font-size: 20px;
    text-align: center;
}

.menu-arrow {
    color: var(--muted);
    font-size: 22px;
    text-align: right;
}

.menu-footer {
    display: flex;
    flex-direction: column;
    gap: 7px;

    margin-top: auto;
    padding-top: 20px;

    border-top: 1px solid var(--border);

    color: var(--muted);
    font-size: 11px;
}

.menu-footer-brand {
    color: var(--text);
    font-size: 10px;
    letter-spacing: 2px;
}

/* ========================================
   SHARED PAGE STYLES
   ======================================== */

.page-view {
    min-height: 400px;
}

.page-heading {
    display: flex;
    align-items: center;
    gap: 14px;

    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.back-button {
    width: 38px;
    height: 38px;
    flex-shrink: 0;

    background: var(--button);
    color: var(--text);

    border-radius: 50%;
    font-size: 21px;

    transition: background 0.2s ease;
}

.back-button:hover {
    background: var(--button-hover);
}

.eyebrow {
    margin-bottom: 5px;

    color: var(--accent);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 2px;
}

.page-heading h1 {
    font-size: 23px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.page-content {
    padding-top: 23px;
}

.page-description {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.8;
}

/* ========================================
   HISTORY PAGE
   ======================================== */

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;

    margin-bottom: 15px;

    color: var(--muted);
    font-size: 12px;
}

.text-button {
    background: transparent;
    color: var(--accent);

    font-size: 12px;
    font-weight: 600;
}

.text-button:hover {
    opacity: 0.75;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;

    max-height: 360px;
    overflow-y: auto;
}

.empty-history {
    padding: 25px 8px;

    color: var(--muted);
    text-align: center;
    font-size: 13px;
    line-height: 1.7;
}

.history-item {
    width: 100%;

    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;

    padding: 13px;

    background: var(--button);
    color: var(--text);

    border: 1px solid var(--border);
    border-radius: 12px;

    text-align: left;

    transition: background 0.2s ease;
}

.history-item:hover {
    background: var(--button-hover);
}

.history-item:active {
    transform: scale(0.99);
}

.history-expression {
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.history-result {
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    text-align: right;
    overflow-wrap: anywhere;
}

/* ========================================
   CONTACT PAGE
   ======================================== */

.contact-card {
    display: flex;
    align-items: center;
    gap: 13px;

    margin-top: 15px;
    padding: 16px 13px;

    color: var(--text);
    text-decoration: none;

    background: var(--button);
    border: 1px solid var(--border);
    border-radius: 14px;

    transition:
        background 0.2s ease,
        transform 0.2s ease;
}

.contact-card:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
}

.contact-icon {
    width: 42px;
    height: 42px;
    flex-shrink: 0;

    display: grid;
    place-items: center;

    background: var(--surface);
    border-radius: 12px;

    color: var(--accent);
    font-size: 22px;
}

.contact-details {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;

    min-width: 0;
}

.contact-label {
    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.contact-value {
    font-size: 13px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.contact-arrow {
    flex-shrink: 0;
    color: var(--accent);
    font-size: 20px;
}

.contact-note {
    margin-top: 15px;

    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}

/* ========================================
   SETTINGS PAGE
   ======================================== */

.settings-group {
    margin-bottom: 27px;
}

.settings-group-title {
    margin-bottom: 12px;

    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.setting-row {
    width: 100%;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    padding: 15px 12px;

    background: var(--button);
    color: var(--text);

    border-bottom: 1px solid var(--border);
    text-align: left;
}

.setting-row:first-of-type {
    border-radius: 12px 12px 0 0;
}

.setting-row:last-child {
    border-bottom: none;
    border-radius: 0 0 12px 12px;
}

.setting-row:only-of-type {
    border-radius: 12px;
}

.setting-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-title {
    font-size: 13px;
    font-weight: 600;
}

.setting-description {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.setting-action {
    cursor: pointer;
}

.setting-action:hover {
    background: var(--button-hover);
}

/* Theme switch */
.switch {
    position: relative;

    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    width: 1px;
    height: 1px;
    position: absolute;
    opacity: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;

    background: var(--button-hover);
    border: 1px solid var(--border);
    border-radius: 30px;

    cursor: pointer;

    transition: background 0.2s ease;
}

.switch-slider::before {
    content: "";

    position: absolute;
    top: 3px;
    left: 3px;

    width: 16px;
    height: 16px;

    background: var(--muted);
    border-radius: 50%;

    transition:
        transform 0.2s ease,
        background 0.2s ease;
}

.switch input:checked + .switch-slider {
    background: var(--accent);
}

.switch input:checked + .switch-slider::before {
    background: #171717;
    transform: translateX(18px);
}

.switch input:focus-visible + .switch-slider {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ========================================
   ABOUT PAGE
   ======================================== */

.about-content {
    text-align: center;
}

.about-logo {
    margin: 8px 0 12px;

    font-size: 34px;
    font-weight: 800;
    letter-spacing: 6px;
}

.about-tagline {
    margin-bottom: 22px;

    color: var(--muted);
    font-size: 12px;
}

.about-info {
    margin-top: 25px;

    background: var(--button);
    border: 1px solid var(--border);
    border-radius: 14px;

    text-align: left;
    overflow: hidden;
}

.about-info > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;

    padding: 14px;

    border-bottom: 1px solid var(--border);
}

.about-info > div:last-child {
    border-bottom: none;
}

.about-info span {
    color: var(--muted);
    font-size: 12px;
}

.about-info strong {
    font-size: 12px;
    text-align: right;
}

.about-footer {
    margin-top: 25px;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 360px) {
    body {
        padding: 12px;
        align-items: flex-start;
    }

    .app-container {
        margin: auto 0;
    }

    .header {
        margin-bottom: 22px;
    }

    .calculator,
    .page-view {
        padding: 15px;
        border-radius: 20px;
    }

    .buttons {
        gap: 7px;
    }

    .btn {
        border-radius: 12px;
        font-size: 18px;
    }

    .page-heading h1 {
        font-size: 21px;
    }

    .contact-card {
        padding: 13px 10px;
        gap: 10px;
    }

    .contact-value {
        font-size: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}