/* ==========================================================================
   Variables & Theme
   ========================================================================== */

:root {
    --font-sans: system-ui, -apple-system, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0b0d11;
    --surface: #151820;
    --surface-alt: #1c2028;
    --border: #2a2e38;
    --text: #e4e7ef;
    --text-muted: #7a8194;
    --accent: #7c6aef;
    --accent-hover: #8b7cf7;
    --accent-glow: rgba(124, 106, 239, 0.25);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.1);
    --success: #4ade80;
    --shadow-lg: none;
}

[data-theme="light"] {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-alt: #f0f1f5;
    --border: #dfe1e8;
    --text: #1a1c24;
    --text-muted: #6b7080;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd6;
    --accent-glow: rgba(108, 92, 231, 0.18);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.06);
    --success: #16a34a;
    --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.container {
    max-width: 620px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    display: flex;
    align-items: center;
    width: 100%;
}

/* ==========================================================================
   Header
   ========================================================================== */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    color: var(--accent);
    flex-shrink: 0;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ==========================================================================
   Theme Toggle
   ========================================================================== */

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

[data-theme="dark"] .icon-moon {
    display: none;
}

[data-theme="light"] .icon-sun {
    display: none;
}

/* ==========================================================================
   Card
   ========================================================================== */

.card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

/* ==========================================================================
   Form Fields
   ========================================================================== */

.field {
    margin-bottom: 1.5rem;
}

.field:last-child {
    margin-bottom: 0;
}

.field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.field-header label {
    margin-bottom: 0;
}

/* ==========================================================================
   Text Input (Secret Key)
   ========================================================================== */

.input-group {
    position: relative;
    display: flex;
}

.input-group input {
    flex: 1;
    padding: 0.75rem 1rem;
    padding-right: 3rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.icon-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
}

.icon-btn:hover {
    color: var(--text);
    background: var(--surface);
}

/* Eye icon visibility states */
.icon-eye-off {
    display: none;
}

.input-group.visible .icon-eye {
    display: none;
}

.input-group.visible .icon-eye-off {
    display: block;
}

/* ==========================================================================
   Textarea
   ========================================================================== */

textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    min-height: 120px;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea::placeholder {
    color: var(--text-muted);
    font-family: var(--font-sans);
}

textarea[readonly] {
    cursor: default;
}

textarea[readonly]:focus {
    border-color: var(--border);
    box-shadow: none;
}

/* ==========================================================================
   Mode Toggle (Segmented Control)
   ========================================================================== */

.mode-toggle {
    display: flex;
    position: relative;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 1.5rem;
}

.mode-btn {
    flex: 1;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: calc(var(--radius-md) - 2px);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    z-index: 1;
    transition: color var(--transition);
    user-select: none;
}

.mode-btn:hover:not(.active) {
    color: var(--text);
}

.mode-btn.active {
    color: #fff;
}

.mode-slider {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: calc(50% - 4px);
    background: var(--accent);
    border-radius: calc(var(--radius-md) - 2px);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
}

.mode-toggle.decrypt .mode-slider {
    left: 50%;
}

/* ==========================================================================
   Text Buttons (Paste, Copy)
   ========================================================================== */

.text-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.text-btn:hover {
    color: var(--text);
    border-color: var(--text-muted);
    background: var(--surface-alt);
}

.text-btn.success {
    color: var(--success);
    border-color: var(--success);
}

/* ==========================================================================
   Action Button
   ========================================================================== */

.action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1.5rem;
    transition: background var(--transition), box-shadow var(--transition), transform 0.1s ease;
}

.action-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.action-btn:active {
    transform: scale(0.98);
}

/* Lock/unlock icon toggle based on mode */
.card[data-mode="encrypt"] .icon-unlock {
    display: none;
}

.card[data-mode="decrypt"] .icon-lock {
    display: none;
}

/* Loading state */
.action-btn.loading {
    pointer-events: none;
    opacity: 0.8;
}

.action-btn .spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.action-btn.loading .spinner {
    display: inline-block;
}

.action-btn.loading .icon-lock,
.action-btn.loading .icon-unlock,
.action-btn.loading #actionText {
    display: none;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   Error Message
   ========================================================================== */

.error-message {
    font-size: 0.875rem;
    color: var(--danger);
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: all 0.3s ease;
}

.error-message.visible {
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    max-height: 120px;
    opacity: 1;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0.5rem;
    padding-top: 2rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-align: center;
}

.footer svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--success);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .container {
        padding: 1.25rem 1rem;
    }

    .card {
        padding: 1.5rem;
    }

    .logo h1 {
        font-size: 1.125rem;
    }

    .logo-icon {
        width: 24px;
        height: 24px;
    }
}
