:root {
    color-scheme: dark;
    --bg: #08070f;
    --panel: rgba(19, 17, 31, 0.72);
    --panel-strong: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.16);
    --text: #f6f2ff;
    --muted: #aaa1bd;
    --accent: #a879ff;
    --accent-strong: #c3a1ff;
    --success: #7df2c7;
    --error: #ff8ba7;
    --shadow: 0 28px 80px rgba(0, 0, 0, 0.46);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(168, 121, 255, 0.25), transparent 34rem),
        radial-gradient(circle at bottom right, rgba(73, 211, 255, 0.13), transparent 30rem),
        linear-gradient(145deg, #05040a 0%, #10101d 55%, #070611 100%);
    color: var(--text);
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.app-shell {
    width: 100%;
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 560px) minmax(320px, 420px);
    align-items: start;
    justify-content: center;
    gap: 24px;
    padding: 32px 18px;
}

.cipher-card {
    width: 100%;
    padding: 34px;
    border: 1px solid var(--border);
    border-radius: 28px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px);
}

.card-header {
    text-align: center;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent-strong);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(2.2rem, 7vw, 4rem);
    line-height: 1;
    letter-spacing: 0;
}

.subtitle {
    max-width: 410px;
    margin: 16px auto 0;
    color: var(--muted);
    line-height: 1.6;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.06);
}

.tab-button {
    min-height: 48px;
    border-radius: 14px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 700;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.tab-button:hover,
.tab-button:focus-visible {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

.tab-button.active {
    color: #120d1d;
    background: linear-gradient(135deg, var(--accent-strong), #8f68ff);
    box-shadow: 0 14px 30px rgba(168, 121, 255, 0.28);
}

.cipher-form {
    display: grid;
    gap: 18px;
    margin-top: 24px;
}

.field-group {
    display: grid;
    gap: 9px;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 15px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.055);
    cursor: pointer;
}

.toggle-row span {
    display: grid;
    gap: 4px;
}

.toggle-row strong {
    color: var(--text);
    font-size: 0.94rem;
}

.toggle-row small {
    color: var(--muted);
    line-height: 1.4;
}

.toggle-row input {
    width: 48px;
    height: 28px;
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    appearance: none;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
    position: relative;
    transition: background 180ms ease, border-color 180ms ease;
}

.toggle-row input::before {
    content: "";
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--muted);
    position: absolute;
    top: 3px;
    left: 4px;
    transition: transform 180ms ease, background 180ms ease;
}

.toggle-row input:checked {
    border-color: rgba(195, 161, 255, 0.9);
    background: rgba(168, 121, 255, 0.45);
}

.toggle-row input:checked::before {
    transform: translateX(18px);
    background: var(--text);
}

label,
.result-label {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

input,
textarea {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    outline: none;
    padding: 15px 16px;
    transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

textarea {
    resize: vertical;
    min-height: 132px;
}

input::placeholder,
textarea::placeholder {
    color: rgba(246, 242, 255, 0.42);
}

input:focus,
textarea:focus {
    border-color: rgba(195, 161, 255, 0.9);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 4px rgba(168, 121, 255, 0.14);
}

.form-message {
    min-height: 20px;
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.form-message.success {
    color: var(--success);
}

.form-message.error {
    color: var(--error);
}

.action-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
}

.primary-button,
.ghost-button,
.copy-button,
.mini-button,
.text-button {
    min-height: 48px;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 800;
    transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, color 180ms ease;
}

.primary-button {
    background: linear-gradient(135deg, var(--accent), #7b61ff);
    color: white;
    box-shadow: 0 18px 34px rgba(123, 97, 255, 0.25);
    padding: 0 20px;
}

.ghost-button,
.copy-button,
.mini-button,
.text-button {
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    padding: 0 18px;
}

.primary-button:hover,
.ghost-button:hover,
.copy-button:hover,
.mini-button:hover,
.text-button:hover {
    transform: translateY(-2px);
}

.primary-button:hover {
    box-shadow: 0 22px 42px rgba(123, 97, 255, 0.35);
}

.ghost-button:hover,
.copy-button:hover,
.mini-button:hover,
.text-button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.primary-button:focus-visible,
.ghost-button:focus-visible,
.copy-button:focus-visible,
.mini-button:focus-visible,
.text-button:focus-visible {
    outline: 3px solid rgba(195, 161, 255, 0.45);
    outline-offset: 3px;
}

.result-panel {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: start;
    margin-top: 22px;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.065);
}

.result-label {
    margin: 0 0 8px;
}

.result-text {
    min-height: 28px;
    margin: 0;
    color: var(--text);
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.history-panel {
    width: 100%;
    max-height: calc(100vh - 64px);
    overflow: auto;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 28px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px);
}

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

.history-hint {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.text-button {
    min-height: 38px;
    border-radius: 999px;
    padding: 0 13px;
    color: var(--accent-strong);
    font-size: 0.82rem;
}

.history-list {
    display: grid;
    gap: 10px;
}

.history-list.empty {
    color: var(--muted);
    font-size: 0.92rem;
}

.history-item {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.055);
}

.history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.history-meta span {
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(168, 121, 255, 0.14);
    color: var(--accent-strong);
    font-size: 0.72rem;
    font-weight: 800;
}

.history-result {
    margin: 9px 0 0;
    color: var(--text);
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.history-actions {
    display: flex;
    align-items: start;
    gap: 8px;
}

.mini-button {
    min-height: 36px;
    border-radius: 999px;
    padding: 0 12px;
    font-size: 0.78rem;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: minmax(0, 640px);
        justify-content: center;
    }

    .history-panel {
        max-height: none;
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding: 18px 12px;
    }

    .cipher-card {
        padding: 24px;
        border-radius: 22px;
    }

    .action-row,
    .result-panel,
    .history-item {
        grid-template-columns: 1fr;
    }

    .history-header {
        align-items: start;
        flex-direction: column;
    }

    .history-actions {
        width: 100%;
    }

    .mini-button {
        flex: 1;
    }

    .copy-button,
    .ghost-button,
    .text-button {
        width: 100%;
    }
}
