:root {
    --bg: #0e1013;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #272c37;
    --text: #e9ecf1;
    --muted: #8b93a3;
    --accent: #4f8cff;
    --accent-text: #fff;
    --radius: 14px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f6f9;
        --surface: #fff;
        --surface-2: #eef1f6;
        --border: #e0e4ea;
        --text: #14171c;
        --muted: #6b7280;
        --accent-text: #fff;
    }
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать display у классов ниже (.result в zen-режиме, .logout) */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 14px;
}

h1 {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

/* --- выбор языка --- */

.langbar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
    flex: 0 0 auto;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}

.chip:hover { background: var(--surface-2); }

.chip[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

select {
    flex: 0 0 auto;
    max-width: 44%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

/* --- карточки --- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

textarea {
    width: 100%;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 17px;
    min-height: 72px;
    max-height: 40vh;
}

textarea::placeholder { color: var(--muted); }

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}

.check input { accent-color: var(--accent); margin: 0; }

.counter {
    margin-left: auto;
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

button {
    font: inherit;
    cursor: pointer;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 8px 12px;
}

button:disabled { opacity: .55; cursor: default; }

.primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 550;
}

kbd {
    font: 12px/1 ui-monospace, monospace;
    background: rgba(255, 255, 255, .22);
    border-radius: 5px;
    padding: 3px 5px;
}

/* --- результат --- */

.result-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.tag {
    font-size: 12px;
    color: var(--muted);
}

.actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.actions button {
    padding: 5px 9px;
    font-size: 15px;
    line-height: 1.2;
}

.output {
    font-size: 21px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 1.45em;
    cursor: pointer;
}

.output.error { color: #ff6b6b; font-size: 16px; }

.output.pending::after {
    content: "";
    display: inline-block;
    width: .5em;
    height: 1.05em;
    margin-left: 2px;
    background: var(--accent);
    vertical-align: -.15em;
    animation: blink .9s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

/* --- полноэкранный режим --- */

body.zen .result {
    position: fixed;
    inset: 0;
    z-index: 20;
    border: 0;
    border-radius: 0;
    padding: 20px calc(20px + env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: var(--bg);
}

body.zen .result-head {
    position: absolute;
    top: 14px;
    left: 16px;
    right: 16px;
}

body.zen .output {
    text-align: center;
    font-size: clamp(28px, 7vw, 56px);
    font-weight: 500;
}

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

/* --- страница входа --- */

.login {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(320px, 100%);
    padding: 20px;
}

.login-box h1 {
    margin: 0 0 4px;
    font-size: 19px;
    text-align: center;
}

.login-box input {
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    outline: 0;
}

.login-box input:focus { border-color: var(--accent); }
.login-box .primary { justify-content: center; }

.login-box .error {
    margin: 0;
    font-size: 13px;
    color: #ff6b6b;
    text-align: center;
}

.login-box .note {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.logout {
    float: right;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 400;
    color: var(--muted);
}

/* --- уведомление --- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 40;
    padding: 9px 16px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 14px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
    animation: rise .18s ease-out;
}

@keyframes rise {
    from { opacity: 0; transform: translate(-50%, 8px); }
}
