:root {
    color-scheme: dark;
    --bg: #07080f;
    --panel: rgba(12, 14, 24, 0.96);
    --text: #f8f2e7;
    --muted: #aea696;
    --amber: #d4ac45;
    --cyan: #5fc7d4;
    --violet: #7f73d9;
    --danger: #e7667a;
    --border: rgba(212, 172, 69, 0.2);
    --shadow: rgba(0, 0, 0, 0.5);
    --radius: 8px;
    font-family: Inter, Roboto, "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    padding-bottom: 78px;
    color: var(--text);
    background:
        linear-gradient(rgba(212, 172, 69, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(95, 199, 212, 0.016) 1px, transparent 1px),
        linear-gradient(135deg, rgba(212, 172, 69, 0.045), transparent 34%),
        linear-gradient(315deg, rgba(127, 115, 217, 0.032), transparent 38%),
        var(--bg);
    background-size: 34px 34px, 34px 34px, auto, auto, auto;
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

a {
    color: var(--cyan);
    text-decoration: none;
}

.app-header {
    border-bottom: 1px solid rgba(212, 172, 69, 0.16);
    background: linear-gradient(90deg, rgba(212, 172, 69, 0.052), rgba(95, 199, 212, 0.032)), rgba(7, 8, 15, 0.94);
    box-shadow: 0 12px 28px var(--shadow);
}

h1 {
    margin: 0;
    font-family: "Cascadia Mono", "Segoe UI", monospace;
    font-size: clamp(1.55rem, 4vw, 2.65rem);
    line-height: 1.05;
    text-transform: uppercase;
    text-shadow: 0 0 12px rgba(212, 172, 69, 0.12);
}

h1 a,
h1 a:hover {
    color: inherit;
    text-decoration: none;
}

.header-tagline.is-typing {
    min-width: var(--typing-width, auto);
}

.header-tagline.is-typing::after {
    content: "";
    width: 8px;
    height: 1em;
    margin-left: 4px;
    display: inline-block;
    vertical-align: -2px;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
    animation: cursor-blink 800ms steps(2, start) infinite;
}

.header-tagline {
    max-width: 680px;
    margin: 8px 0 0;
    color: var(--muted);
    font-weight: 700;
}

.percentage-shell {
    width: min(980px, calc(100% - 32px));
    margin: 30px auto 56px;
}

.calculator-panel,
.info-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 0 14px rgba(212, 172, 69, 0.038), 0 12px 30px var(--shadow);
}

.calculator-panel {
    overflow: hidden;
}

.panel-heading {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(212, 172, 69, 0.12);
}

.panel-heading h2,
.info-panel h2 {
    margin: 0;
    color: var(--amber);
    font-size: 1rem;
    text-transform: uppercase;
}

#statusMessage {
    color: var(--muted);
    text-align: right;
}

#statusMessage.is-error {
    color: var(--danger);
}

#statusMessage.is-success {
    color: #83d9a0;
}

.mode-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    background: rgba(0, 0, 0, 0.18);
}

.mode-tab {
    min-height: 52px;
    padding: 8px 10px;
    color: var(--muted);
    border: 0;
    border-bottom: 1px solid rgba(212, 172, 69, 0.14);
    background: transparent;
    font-weight: 850;
    text-transform: uppercase;
}

.mode-tab:hover {
    color: var(--text);
    background: rgba(212, 172, 69, 0.045);
}

.mode-tab.is-active {
    color: #080b12;
    background: linear-gradient(135deg, var(--amber), var(--cyan));
    box-shadow: inset 0 -2px 0 rgba(255, 255, 255, 0.32);
}

.calculator-form {
    padding: clamp(18px, 4vw, 30px);
    display: grid;
    gap: 16px;
}

.fields-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    color: var(--amber);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

input {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    color: var(--text);
    border: 1px solid rgba(95, 199, 212, 0.22);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.28);
    outline: none;
}

input:focus {
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(212, 172, 69, 0.1);
}

input.is-invalid {
    border-color: var(--danger);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
}

.button-secondary,
.button-primary {
    min-height: 42px;
    min-width: 46px;
    padding: 9px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 6px;
    font-weight: 900;
    text-transform: uppercase;
}

.button-secondary {
    color: #071018;
    border: 1px solid rgba(95, 199, 212, 0.34);
    background: linear-gradient(135deg, rgba(95, 199, 212, 0.84), rgba(127, 115, 217, 0.62));
    box-shadow:
        inset 0 -3px 0 rgba(0, 0, 0, 0.24),
        0 4px 0 rgba(0, 0, 0, 0.34);
}

.button-clear {
    color: #fff7f8;
    border-color: rgba(231, 102, 122, 0.42);
    background: linear-gradient(135deg, rgba(231, 102, 122, 0.84), rgba(105, 26, 43, 0.82));
}

.button-copy {
    color: #071018;
    border-color: rgba(127, 115, 217, 0.44);
    background: linear-gradient(135deg, rgba(127, 115, 217, 0.82), rgba(95, 199, 212, 0.74));
}

.button-primary {
    color: #071018;
    border: 1px solid rgba(212, 172, 69, 0.34);
    background: linear-gradient(135deg, var(--amber), var(--cyan));
    box-shadow:
        inset 0 -3px 0 rgba(0, 0, 0, 0.28),
        0 5px 0 rgba(0, 0, 0, 0.34);
}

.button-secondary:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

.button-secondary:active,
.button-primary:active {
    transform: scaleY(0.92);
    transform-origin: bottom;
}

.result-panel {
    margin: 0 20px 20px;
    padding: 18px;
    display: grid;
    gap: 8px;
    border: 1px solid rgba(95, 199, 212, 0.18);
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, rgba(212, 172, 69, 0.07), rgba(95, 199, 212, 0.045)),
        rgba(0, 0, 0, 0.2);
}

.result-panel span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

#resultValue {
    color: var(--text);
    font-size: clamp(1.65rem, 5vw, 3rem);
    font-weight: 900;
    line-height: 1.05;
    overflow-wrap: anywhere;
}

#formulaText {
    margin: 0;
    color: var(--muted);
}

.info-panel {
    margin-top: 18px;
    padding: clamp(18px, 4vw, 30px);
}

.info-panel p {
    margin: 10px 0 0;
    color: var(--muted);
}

.info-panel strong {
    color: var(--text);
}

.privacy-note {
    padding: 10px 12px;
    border-left: 3px solid var(--cyan);
    border-radius: 6px;
    background: rgba(95, 199, 212, 0.045);
}

.noscript-alert {
    width: min(980px, calc(100% - 32px));
    margin: 16px auto 0;
    padding: 12px 14px;
    color: #ffe1e8;
    border: 1px solid rgba(231, 102, 122, 0.34);
    border-radius: var(--radius);
    background: rgba(231, 102, 122, 0.11);
}

.calculator-dialog {
    width: min(440px, calc(100% - 32px));
    padding: 0;
    color: var(--text);
    border: 1px solid rgba(212, 172, 69, 0.28);
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, rgba(212, 172, 69, 0.074), rgba(95, 199, 212, 0.044)),
        var(--panel);
    box-shadow: 0 16px 46px rgba(0, 0, 0, 0.56);
}

.calculator-dialog::backdrop {
    background: rgba(3, 5, 12, 0.72);
    backdrop-filter: blur(6px);
}

.calculator-dialog__panel {
    padding: 18px;
    display: grid;
    gap: 14px;
}

.calculator-dialog__header,
.calculator-dialog__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.calculator-dialog h2 {
    margin: 0;
    color: var(--danger);
    font-size: 1rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.calculator-dialog p {
    margin: 0;
    color: var(--muted);
}

.calculator-dialog__close {
    width: 34px;
    height: 34px;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 6px;
    background: #9f2f42;
    font-weight: 900;
}

.calculator-dialog__close:active {
    filter: brightness(0.92);
    transform: scale(0.97);
}

.calculator-dialog__actions {
    justify-content: flex-end;
}

.calculator-dialog__actions .button-secondary {
    min-width: 92px;
}

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

@media (max-width: 760px) {
    body {
        padding-bottom: 0;
    }

    .percentage-shell {
        width: calc(100% - 20px);
    }

    .panel-heading {
        align-items: stretch;
        flex-direction: column;
    }

    #statusMessage {
        text-align: left;
    }

    .mode-tabs {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .actions {
        display: flex;
        justify-content: center;
    }

    .button-secondary,
    .button-primary {
        width: auto;
    }
}

@media (max-width: 425px) {
    .percentage-shell {
        width: calc(100% - 16px);
        margin-top: 22px;
    }

    .mode-tab {
        min-height: 46px;
        font-size: 0.76rem;
        line-height: 1.15;
    }

    .calculator-form,
    .result-panel,
    .info-panel {
        padding: 14px;
    }

    .result-panel {
        margin-inline: 14px;
    }
}

.result-value,
.status-message,
output {
    font-family: var(--font-data), "Cascadia Mono", "Segoe UI", monospace;
}
