/* =========================================================================
   Calculadora Precisa — tema Fluent, responsivo, claro/escuro
   ========================================================================= */

:root {
    color-scheme: dark;

    --bg: #060a13;
    --bg-soft: #0b1220;
    --glow-a: rgba(124, 58, 237, 0.20);
    --glow-b: rgba(34, 211, 238, 0.14);

    --surface: rgba(15, 22, 38, 0.86);
    --surface-solid: #0f1626;
    --surface-2: #151f34;
    --surface-3: #1c2942;
    --surface-inset: rgba(3, 7, 18, 0.55);

    --border: rgba(148, 163, 184, 0.16);
    --border-strong: rgba(148, 163, 184, 0.28);

    --text: #eef2ff;
    --text-soft: #c7d2fe;
    --muted: #93a4bf;
    --muted-strong: #aab8d0;

    --accent: #8b5cf6;
    --accent-strong: #7c3aed;
    --accent-soft: rgba(139, 92, 246, 0.16);
    --accent-2: #22d3ee;
    --accent-2-soft: rgba(34, 211, 238, 0.14);

    --danger: #fb7185;
    --danger-soft: rgba(251, 113, 133, 0.14);
    --success: #34d399;

    --shadow-lg: 0 28px 70px -32px rgba(0, 0, 0, 0.85);
    --shadow-md: 0 16px 40px -26px rgba(0, 0, 0, 0.8);
    --shadow-key: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 1px 2px rgba(0, 0, 0, 0.35);

    --radius-xl: 26px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;

    --key-height: clamp(48px, 6.4vw, 64px);
    --memory-height: clamp(34px, 4vw, 40px);

    --font-ui: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Inter", "Roboto", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Code", "SFMono-Regular", "Consolas", "Roboto Mono", ui-monospace, monospace;

    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

:root[data-theme="light"] {
    color-scheme: light;

    --bg: #eef1f9;
    --bg-soft: #f8faff;
    --glow-a: rgba(109, 40, 217, 0.14);
    --glow-b: rgba(8, 145, 178, 0.12);

    --surface: rgba(255, 255, 255, 0.9);
    --surface-solid: #ffffff;
    --surface-2: #f4f6fc;
    --surface-3: #e9edf8;
    --surface-inset: rgba(226, 232, 245, 0.6);

    --border: rgba(15, 23, 42, 0.10);
    --border-strong: rgba(15, 23, 42, 0.18);

    --text: #0d1526;
    --text-soft: #24304a;
    --muted: #5b6880;
    --muted-strong: #46536c;

    --accent: #6d28d9;
    --accent-strong: #5b21b6;
    --accent-soft: rgba(109, 40, 217, 0.10);
    --accent-2: #0e7490;
    --accent-2-soft: rgba(14, 116, 144, 0.10);

    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.10);

    --shadow-lg: 0 30px 70px -40px rgba(30, 41, 59, 0.5);
    --shadow-md: 0 18px 40px -32px rgba(30, 41, 59, 0.45);
    --shadow-key: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 2px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        color-scheme: light;

        --bg: #eef1f9;
        --bg-soft: #f8faff;
        --glow-a: rgba(109, 40, 217, 0.14);
        --glow-b: rgba(8, 145, 178, 0.12);
        --surface: rgba(255, 255, 255, 0.9);
        --surface-solid: #ffffff;
        --surface-2: #f4f6fc;
        --surface-3: #e9edf8;
        --surface-inset: rgba(226, 232, 245, 0.6);
        --border: rgba(15, 23, 42, 0.10);
        --border-strong: rgba(15, 23, 42, 0.18);
        --text: #0d1526;
        --text-soft: #24304a;
        --muted: #5b6880;
        --muted-strong: #46536c;
        --accent: #6d28d9;
        --accent-strong: #5b21b6;
        --accent-soft: rgba(109, 40, 217, 0.10);
        --accent-2: #0e7490;
        --accent-2-soft: rgba(14, 116, 144, 0.10);
        --danger: #dc2626;
        --danger-soft: rgba(220, 38, 38, 0.10);
        --shadow-lg: 0 30px 70px -40px rgba(30, 41, 59, 0.5);
        --shadow-md: 0 18px 40px -32px rgba(30, 41, 59, 0.45);
        --shadow-key: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 2px rgba(15, 23, 42, 0.08);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(60rem 60rem at 8% -10%, var(--glow-a), transparent 60%),
        radial-gradient(50rem 50rem at 105% 10%, var(--glow-b), transparent 55%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 55%, var(--bg) 100%);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

[hidden] {
    display: none !important;
}

a {
    color: var(--accent-2);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--accent-strong);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-160%);
    transition: transform 0.2s var(--ease);
}

.skip-link:focus-visible {
    transform: translateY(0);
}

/* ------------------------------------------------------------------ layout */

.app {
    width: min(1460px, 100%);
    margin-inline: auto;
    padding: clamp(12px, 2vw, 28px);
    padding-bottom: max(clamp(12px, 2vw, 28px), env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 1.6vw, 22px);
    min-height: 100vh;
    min-height: 100dvh;
}

.app-header {
    display: flex;
    align-items: center;
    gap: clamp(12px, 2vw, 26px);
    flex-wrap: wrap;
    padding: clamp(10px, 1.4vw, 16px) clamp(14px, 2vw, 22px);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    place-items: center;
    width: clamp(40px, 4.6vw, 50px);
    aspect-ratio: 1;
    border-radius: 14px;
    background: linear-gradient(140deg, var(--accent), var(--accent-2));
    color: #fff;
    font-weight: 700;
    font-size: clamp(0.9rem, 2vw, 1.05rem);
    line-height: 1;
    box-shadow: 0 10px 24px -12px var(--accent);
    flex: none;
}

.brand-mark span {
    display: block;
    transform: translateY(-1px);
}

.brand-text {
    min-width: 0;
}

.brand-text h1 {
    margin: 0;
    font-size: clamp(1.05rem, 1.8vw, 1.28rem);
    font-weight: 650;
    letter-spacing: -0.015em;
    white-space: nowrap;
}

.brand-text h1 span {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-text p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: clamp(0.72rem, 1vw, 0.82rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mode-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    margin-inline: auto;
    overflow-x: auto;
    scrollbar-width: none;
    max-width: 100%;
}

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

.mode-tabs [role="tab"] {
    border: 0;
    background: transparent;
    color: var(--muted-strong);
    padding: clamp(6px, 0.9vw, 9px) clamp(10px, 1.4vw, 18px);
    border-radius: 999px;
    font-size: clamp(0.78rem, 1.1vw, 0.9rem);
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.mode-tabs [role="tab"]:hover {
    color: var(--text);
    background: var(--surface-2);
}

.mode-tabs [role="tab"][aria-selected="true"] {
    color: #fff;
    background: linear-gradient(140deg, var(--accent-strong), var(--accent));
    box-shadow: 0 8px 20px -10px var(--accent-strong);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.precision-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
}

.precision-picker select {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 999px;
    padding: 7px 26px 7px 11px;
    font-size: 0.8rem;
    font-weight: 600;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}

.icon-button,
.install-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 999px;
    min-height: 38px;
    min-width: 38px;
    padding: 7px 10px;
    transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.1s var(--ease);
}

.install-button {
    padding-inline: 14px;
    font-size: 0.82rem;
    font-weight: 650;
    background: linear-gradient(140deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #fff;
}

.icon-button:hover,
.install-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-3);
    transform: translateY(-1px);
}

.install-button:hover {
    background: linear-gradient(140deg, var(--accent-strong), var(--accent-2));
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 336px;
    gap: clamp(14px, 1.6vw, 22px);
    align-items: start;
    flex: 1;
}

.main-column {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 1.5vw, 18px);
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 1.4vw, 18px);
    position: sticky;
    top: clamp(12px, 2vw, 20px);
    min-width: 0;
}

/* -------------------------------------------------------------- calculadora */

.calculator-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    padding: clamp(12px, 1.8vw, 22px);
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 1.6vw, 18px);
    min-width: 0;
}

.calculator-card:focus {
    outline: none;
}

.card-plain {
    min-height: 320px;
}

.panel-heading {
    padding: 4px 4px 0;
}

.panel-heading h2 {
    margin: 0;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    letter-spacing: -0.01em;
}

.panel-heading p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.display {
    background:
        linear-gradient(180deg, var(--surface-inset), transparent 70%),
        var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(12px, 1.6vw, 18px);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 148px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    overflow: hidden;
}

.display-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.display-flags {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-2);
    background: var(--accent-2-soft);
    border: 1px solid transparent;
    white-space: nowrap;
}

.flag--soft {
    color: var(--muted);
    background: transparent;
    border-color: var(--border);
    letter-spacing: 0.02em;
    text-transform: none;
    font-weight: 600;
}

.flag--memory {
    color: var(--accent);
    background: var(--accent-soft);
}

.flag--offline {
    color: var(--danger);
    background: var(--danger-soft);
}

.display-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.ghost-button {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    transition: color 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.ghost-button:hover {
    color: var(--text);
    background: var(--surface-3);
    border-color: var(--border);
}

#toggle-history-mobile {
    display: none;
}

.angle-switch,
.width-switch {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    gap: 2px;
}

.angle-switch button,
.width-switch button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 4px 9px;
    border-radius: 999px;
    transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.angle-switch button.is-active,
.width-switch button.is-active {
    background: var(--accent-soft);
    color: var(--accent-2);
}

.expression {
    min-height: 1.4em;
    color: var(--muted-strong);
    font-family: var(--font-mono);
    font-size: clamp(0.82rem, 1.4vw, 0.98rem);
    text-align: right;
    overflow-wrap: anywhere;
    line-height: 1.45;
    padding-top: 6px;
}

.expression:empty::before {
    content: "Digite uma expressão";
    color: var(--muted);
    opacity: 0.6;
}

.result {
    display: block;
    width: 100%;
    text-align: right;
    font-size: clamp(2.1rem, 6.2vw, 3.6rem);
    font-weight: 650;
    letter-spacing: -0.025em;
    line-height: 1.05;
    font-variant-numeric: tabular-nums lining-nums;
    overflow-wrap: anywhere;
    color: var(--text);
    min-height: 1.1em;
}

.result.is-error {
    color: var(--danger);
    font-size: clamp(1.1rem, 2.4vw, 1.4rem);
    font-weight: 600;
    letter-spacing: 0;
}

.preview {
    min-height: 1.2em;
    text-align: right;
    color: var(--muted);
    font-size: clamp(0.8rem, 1.3vw, 0.92rem);
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
    transition: opacity 0.15s var(--ease);
}

.preview:empty {
    opacity: 0;
}

/* ----------------------------------------------------------------- teclados */

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

.memory-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
}

.keys {
    display: grid;
    gap: clamp(6px, 0.8vw, 9px);
}

.keys--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.keys--6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.key {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--radius-md);
    min-height: var(--key-height);
    min-width: 0;
    padding: 4px 2px;
    font-size: clamp(1rem, 1.5vw, 1.2rem);
    font-weight: 550;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.1;
    box-shadow: var(--shadow-key);
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease), box-shadow 0.15s var(--ease);
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-inline-size: 0;
    overflow: hidden;
}

.key:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.key:active {
    transform: translateY(1px) scale(0.995);
    background: var(--surface-3);
    box-shadow: none;
}

.key--digit {
    background: var(--surface-2);
    font-weight: 600;
}

.key--op {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--text-soft);
    font-size: clamp(1.15rem, 1.7vw, 1.35rem);
    font-weight: 600;
}

.key--op:hover {
    background: rgba(139, 92, 246, 0.26);
}

.key--fn {
    font-size: clamp(0.8rem, 1.15vw, 0.94rem);
    font-weight: 600;
    color: var(--muted-strong);
}

.key--util {
    font-size: clamp(0.82rem, 1.1vw, 0.92rem);
    font-weight: 650;
    color: var(--muted-strong);
    background: var(--surface-2);
}

.key--memory {
    min-height: var(--memory-height);
    font-size: clamp(0.7rem, 0.95vw, 0.78rem);
    font-weight: 700;
    border-radius: var(--radius-sm);
    color: var(--muted);
    letter-spacing: 0.02em;
}

.key--eq {
    background: linear-gradient(140deg, var(--accent-strong), var(--accent));
    color: #fff;
    border-color: transparent;
    font-size: clamp(1.2rem, 1.8vw, 1.45rem);
    font-weight: 700;
    box-shadow: 0 12px 26px -14px var(--accent-strong), var(--shadow-key);
}

.key--eq:hover {
    background: linear-gradient(140deg, var(--accent), var(--accent-2));
}

.key--danger {
    color: var(--danger);
}

.key[disabled],
.key[aria-disabled="true"] {
    opacity: 0.32;
    cursor: not-allowed;
    pointer-events: none;
}

.span-2 {
    grid-column: span 2;
}

.span-3 {
    grid-column: span 3;
}

.span-4 {
    grid-column: span 4;
}

.second-toggle[aria-pressed="true"] {
    color: var(--accent-2);
    border-color: var(--accent-2);
    background: var(--accent-2-soft);
}

.more-functions-toggle {
    border: 1px dashed var(--border-strong);
    background: transparent;
    color: var(--muted);
    border-radius: var(--radius-md);
    min-height: 38px;
    font-size: 0.8rem;
    font-weight: 650;
    transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.more-functions-toggle:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.keys--extra {
    padding-top: 4px;
    border-top: 1px dashed var(--border);
}

.keys--extra .key {
    min-height: clamp(38px, 4.6vw, 44px);
    font-size: clamp(0.72rem, 1vw, 0.82rem);
    border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------- programador */

.display--programmer {
    gap: 10px;
}

.base-display {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.base-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    text-align: right;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
    min-width: 0;
}

.base-row:hover {
    background: var(--surface-3);
}

.base-row[aria-pressed="true"] {
    background: var(--surface-inset);
    border-color: var(--border-strong);
}

.base-label {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.base-value {
    font-family: var(--font-mono);
    font-size: clamp(0.92rem, 2.4vw, 1.35rem);
    font-weight: 600;
    overflow-wrap: anywhere;
    line-height: 1.25;
    min-width: 0;
}

.base-row[data-base="16"] .base-value {
    color: var(--accent-2);
}

.base-row[data-base="10"] .base-value {
    color: var(--text);
}

.base-row[data-base="8"] .base-value,
.base-row[data-base="2"] .base-value {
    color: var(--muted-strong);
    font-size: clamp(0.8rem, 1.7vw, 1rem);
}

.programmer-expression {
    min-height: 1.2em;
    text-align: right;
    font-size: 0.78rem;
    font-family: var(--font-mono);
    color: var(--muted);
    overflow-wrap: anywhere;
}

.bits-panel {
    margin-top: 4px;
}

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

.bit {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    border-radius: 6px;
    min-height: 26px;
    padding: 0;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    transition: background 0.12s var(--ease), color 0.12s var(--ease), border-color 0.12s var(--ease);
}

.bit:hover {
    border-color: var(--accent-2);
}

.bit.is-on {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-2);
    font-weight: 700;
}

.bits-hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
    text-align: center;
}

/* ------------------------------------------------------------------- datas */

.date-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(12px, 1.6vw, 18px);
}

.date-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    padding: clamp(14px, 1.8vw, 20px);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.date-card h3 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.field > span {
    font-size: 0.76rem;
    font-weight: 650;
    color: var(--muted);
    letter-spacing: 0.01em;
}

.field input,
.field select {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--border);
    background: var(--surface-solid);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 11px;
    font-size: 0.95rem;
    min-height: 44px;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 30px;
}

.field input:focus,
.field select:focus {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px var(--accent-2-soft);
    outline: none;
}

.field-row {
    display: grid;
    grid-template-columns: 1.1fr 1fr 1fr;
    gap: 10px;
}

.primary-button {
    border: 1px solid transparent;
    background: linear-gradient(140deg, var(--accent-strong), var(--accent));
    color: #fff;
    border-radius: var(--radius-sm);
    min-height: 44px;
    padding: 10px 16px;
    font-weight: 650;
    font-size: 0.9rem;
    box-shadow: 0 12px 26px -18px var(--accent-strong);
    transition: filter 0.2s var(--ease), transform 0.1s var(--ease);
}

.primary-button:hover {
    filter: brightness(1.08);
}

.primary-button:active {
    transform: translateY(1px);
}

.date-results {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.date-results > div {
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    text-align: center;
}

.date-results dt {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 700;
}

.date-results dd {
    margin: 2px 0 0;
    font-weight: 700;
    font-size: 1.02rem;
    font-variant-numeric: tabular-nums;
}

.date-result {
    margin: 0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.date-result-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--accent-2);
    font-weight: 700;
}

.date-result strong {
    font-size: clamp(1.2rem, 2.6vw, 1.5rem);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.date-result-meta {
    color: var(--muted);
    font-size: 0.82rem;
}

.form-error {
    margin: 0;
    color: var(--danger);
    font-size: 0.82rem;
    font-weight: 600;
}

/* --------------------------------------------------------------- conversor */

.converter-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.converter-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 12px;
    align-items: end;
}

.converter-side {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.converter-output {
    display: flex;
    align-items: center;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-inset);
    padding: 8px 11px;
    font-family: var(--font-mono);
    font-size: clamp(1rem, 2.4vw, 1.35rem);
    font-weight: 650;
    overflow-wrap: anywhere;
    color: var(--accent-2);
}

.swap-button {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted-strong);
    border-radius: 999px;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    transition: border-color 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}

.swap-button:hover {
    border-color: var(--accent);
    color: var(--accent-2);
    transform: rotate(180deg);
}

.converter-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

/* ------------------------------------------------------------------ cartões */

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: clamp(14px, 1.6vw, 18px);
    min-width: 0;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.card-header h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.card-subtitle {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    margin-left: 4px;
    letter-spacing: 0.04em;
}

.rate-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rate-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid transparent;
    transition: border-color 0.2s var(--ease);
}

.rate-row:hover {
    border-color: var(--border);
}

.rate-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 24px;
    padding: 0 6px;
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--text-soft);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
    flex: none;
}

.rate-name {
    font-size: 0.82rem;
    color: var(--muted-strong);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rate-value {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-size: 0.98rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.rate-prefix {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin-right: 2px;
}

.rate-row--small .rate-value {
    font-size: 0.88rem;
    color: var(--muted-strong);
}

.rates-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 10px;
    font-size: 0.74rem;
    color: var(--muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    flex: none;
    box-shadow: 0 0 0 3px transparent;
}

.status-dot[data-state="ok"] {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.14);
}

.status-dot[data-state="stale"] {
    background: #fbbf24;
    box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.16);
}

.status-dot[data-state="offline"] {
    background: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}

.rates-disclaimer {
    margin: 8px 0 0;
    font-size: 0.71rem;
    color: var(--muted);
    line-height: 1.45;
}

.link-button {
    border: 0;
    background: none;
    color: var(--accent-2);
    font-size: 0.78rem;
    font-weight: 650;
    padding: 8px 0 0;
    text-align: left;
}

.link-button:hover {
    text-decoration: underline;
}

.history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 320px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.history-item {
    width: 100%;
    border: 1px solid transparent;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.history-item:hover {
    border-color: var(--border-strong);
    background: var(--surface-3);
}

.history-expression {
    font-size: 0.72rem;
    color: var(--muted);
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
    text-align: right;
}

.history-result {
    font-size: 0.92rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.empty-state {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.5;
}

.empty-state kbd,
.shortcuts kbd {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    padding: 1px 5px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--surface-2);
    color: var(--text-soft);
}

.shortcuts {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.shortcuts > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.78rem;
}

.shortcuts dt {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}

.shortcuts dd {
    margin: 0;
    color: var(--muted);
    text-align: right;
}

/* ------------------------------------------------------------------ rodapé */

.app-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px clamp(4px, 1vw, 8px);
    color: var(--muted);
    font-size: 0.73rem;
}

.app-footer p {
    margin: 0;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-footer a {
    color: var(--muted-strong);
}

.noscript-warning {
    position: fixed;
    inset: auto 16px 16px;
    background: var(--danger);
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    z-index: 50;
}

/* ------------------------------------------------------------- responsivo */

@media (max-width: 1180px) {
    .layout {
        grid-template-columns: minmax(0, 1fr) 300px;
    }
}

@media (max-width: 1040px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: static;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        align-items: start;
    }

    .history-card {
        grid-column: span 1;
    }

    .rate-list {
        gap: 5px;
    }

    .app-header {
        justify-content: space-between;
    }

    .mode-tabs {
        order: 3;
        width: 100%;
        margin-inline: 0;
        justify-content: space-between;
    }

    .mode-tabs [role="tab"] {
        flex: 1;
    }
}

@media (max-width: 860px) {
    .date-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .converter-body {
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
    }

    .swap-button {
        justify-self: center;
        margin: -2px 0;
        transform: rotate(90deg);
    }

    .swap-button:hover {
        transform: rotate(270deg);
    }

    .converter-side {
        gap: 10px;
    }

    .bits {
        grid-template-columns: repeat(8, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .brand-text p {
        display: none;
    }

    .app-header {
        gap: 10px;
        padding: 10px 12px;
    }

    .header-actions {
        margin-left: auto;
    }

    .precision-picker > span {
        display: none;
    }

    .calculator-card {
        border-radius: var(--radius-lg);
        padding: 10px;
        gap: 10px;
    }

    .display {
        border-radius: var(--radius-md);
        min-height: 132px;
        padding: 10px 12px;
    }

    .result {
        font-size: clamp(1.9rem, 9.5vw, 2.8rem);
    }

    #copy-result,
    #copy-result-sci {
        display: none;
    }

    #toggle-history-mobile {
        display: inline-flex;
    }

    .keys {
        gap: 6px;
    }

    .key {
        border-radius: 11px;
        min-height: clamp(44px, 11vw, 56px);
        font-size: clamp(0.98rem, 4vw, 1.12rem);
    }

    .key--fn {
        font-size: clamp(0.72rem, 2.9vw, 0.84rem);
    }

    .key--op {
        font-size: clamp(1.05rem, 4.4vw, 1.2rem);
    }

    .key--util {
        font-size: clamp(0.76rem, 3vw, 0.86rem);
    }

    .key--memory {
        min-height: 34px;
        font-size: 0.66rem;
    }

    .field-row {
        grid-template-columns: 1fr 1fr;
    }

    .field-row .field:first-child {
        grid-column: span 2;
    }

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

    .app-footer {
        flex-direction: column;
        align-items: flex-start;
        font-size: 0.7rem;
    }

    .app-footer p:first-child {
        max-width: 52ch;
    }
}

@media (max-width: 520px) {
    .app {
        padding: 8px;
        gap: 10px;
    }

    .app-header {
        border-radius: var(--radius-lg);
    }

    .brand-mark {
        width: 36px;
        border-radius: 11px;
        font-size: 0.82rem;
    }

    .brand-text h1 {
        font-size: 1rem;
    }

    .mode-tabs {
        gap: 2px;
        padding: 3px;
    }

    .mode-tabs [role="tab"] {
        padding: 7px 4px;
        font-size: 0.72rem;
    }

    .icon-button {
        min-height: 34px;
        min-width: 34px;
    }

    .precision-picker select {
        padding: 6px 22px 6px 9px;
        font-size: 0.74rem;
    }

    .keys--6 {
        gap: 4px;
    }

    .key {
        border-radius: 9px;
        min-height: clamp(42px, 11.4vw, 52px);
        padding-inline: 0;
    }

    .key--fn,
    .key--util {
        font-size: 0.68rem;
    }

    .memory-row {
        gap: 4px;
    }

    .key--memory {
        min-height: 30px;
        font-size: 0.6rem;
    }

    .bits {
        gap: 2px;
    }

    .bit {
        min-height: 22px;
        font-size: 0.6rem;
    }

    .sidebar {
        grid-template-columns: minmax(0, 1fr);
    }

    .display-flags .flag--soft {
        display: none;
    }

    .date-results {
        gap: 6px;
    }
}

@media (max-width: 380px) {
    .mode-tabs {
        gap: 2px;
    }

    .mode-tabs [role="tab"] {
        padding: 6px 2px;
        font-size: 0.66rem;
    }

    .keys--6 {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 3px;
    }

    .key {
        font-size: 0.9rem;
        min-height: 42px;
    }

    .key--fn {
        font-size: 0.62rem;
    }

    .key--op,
    .key--eq {
        font-size: 1rem;
    }

    .key--util {
        font-size: 0.62rem;
    }

    .key--memory {
        font-size: 0.56rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* Ajustes para instalação (janela sem barra do navegador) */
@media (display-mode: standalone) {
    .app {
        padding-top: max(clamp(12px, 2vw, 28px), env(safe-area-inset-top));
    }
}

@media (prefers-contrast: more) {
    :root {
        --border: rgba(148, 163, 184, 0.4);
        --border-strong: rgba(148, 163, 184, 0.6);
    }

    .key {
        border-width: 2px;
    }
}
