/* ============================================================
   Virtual Dwelling Keyboard — Styles
   ============================================================ */

/* --- CSS Custom Properties (Theming) --- */
:root {
    /* Dark theme (default) */
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --surface: #1e2746;
    --surface-hover: #2a3562;
    --surface-active: #3a4a7a;
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0c0;
    --text-muted: #6a6a8a;
    --accent: #6c63ff;
    --accent-light: #8b83ff;
    --accent-glow: rgba(108, 99, 255, 0.35);
    --accent-secondary: #00d4aa;
    --accent-secondary-glow: rgba(0, 212, 170, 0.3);
    --danger: #ff6b6b;
    --border: rgba(255, 255, 255, 0.06);
    --border-focus: rgba(108, 99, 255, 0.5);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-key: 0 4px 12px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255,255,255,0.06);
    --shadow-key-hover: 0 6px 20px rgba(108, 99, 255, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --key-size: 64px;
    --key-font-size: 1.2rem;
    --key-gap: 6px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #f0f2f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8ecf4;
    --surface: #ffffff;
    --surface-hover: #eef1fa;
    --surface-active: #dde3f0;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #8a8aa0;
    --accent: #5b52e0;
    --accent-light: #7068f0;
    --accent-glow: rgba(91, 82, 224, 0.2);
    --accent-secondary: #00b894;
    --accent-secondary-glow: rgba(0, 184, 148, 0.2);
    --danger: #e74c3c;
    --border: rgba(0, 0, 0, 0.08);
    --border-focus: rgba(91, 82, 224, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-key: 0 3px 10px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255,255,255,0.8);
    --shadow-key-hover: 0 6px 20px rgba(91, 82, 224, 0.2), inset 0 1px 0 rgba(255,255,255,0.9);
}

/* High contrast theme */
[data-theme="high-contrast"] {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #111111;
    --surface: #1a1a1a;
    --surface-hover: #333333;
    --surface-active: #555555;
    --text-primary: #ffffff;
    --text-secondary: #dddddd;
    --text-muted: #999999;
    --accent: #ffff00;
    --accent-light: #ffff66;
    --accent-glow: rgba(255, 255, 0, 0.4);
    --accent-secondary: #00ff88;
    --accent-secondary-glow: rgba(0, 255, 136, 0.3);
    --danger: #ff4444;
    --border: rgba(255, 255, 255, 0.2);
    --border-focus: rgba(255, 255, 0, 0.6);
    --shadow-key: 0 2px 0 rgba(255, 255, 255, 0.15);
    --shadow-key-hover: 0 2px 0 rgba(255, 255, 0, 0.4);
}

/* Key sizes */
[data-key-size="small"] {
    --key-size: 52px;
    --key-font-size: 1rem;
    --key-gap: 4px;
}
[data-key-size="medium"] {
    --key-size: 64px;
    --key-font-size: 1.2rem;
    --key-gap: 6px;
}
[data-key-size="large"] {
    --key-size: 80px;
    --key-font-size: 1.5rem;
    --key-gap: 8px;
}
[data-key-size="xlarge"] {
    --key-size: 100px;
    --key-font-size: 1.8rem;
    --key-gap: 10px;
}

/* Font boost — overrides key font size */
[data-font-boost="large"] .key {
    font-size: 1.6rem !important;
}
[data-font-boost="xlarge"] .key {
    font-size: 2.2rem !important;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* --- App Container --- */
.app-container {
    max-width: 100%;
    margin: 0 auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: 12px;
    box-sizing: border-box;
}

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

/* --- Top Bar --- */
.top-bar {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
}

/* --- Quick Needs --- */
.quick-needs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    align-content: center;
    justify-content: center;
}

.need-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 10px;
    min-width: 64px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 1.4rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.need-btn .need-label {
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.need-btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.need-btn.dwelling {
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.need-btn .dwell-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    background: var(--accent);
    transition: width linear;
    width: 0%;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.need-btn.dwelling .dwell-fill {
    width: 100%;
}

.need-btn.activated {
    background: var(--accent) !important;
    transform: scale(0.95);
    transition: all 0.1s ease;
}

/* Emoji/need button sizes */
[data-emoji-size="small"] .need-btn {
    min-width: 52px;
    padding: 4px 8px;
    font-size: 1.1rem;
}
[data-emoji-size="small"] .need-btn .need-label {
    font-size: 0.5rem;
}
[data-emoji-size="medium"] .need-btn {
    min-width: 64px;
    padding: 6px 10px;
    font-size: 1.4rem;
}
[data-emoji-size="medium"] .need-btn .need-label {
    font-size: 0.6rem;
}
[data-emoji-size="large"] .need-btn {
    min-width: 80px;
    padding: 8px 14px;
    font-size: 2rem;
}
[data-emoji-size="large"] .need-btn .need-label {
    font-size: 0.75rem;
}
[data-emoji-size="xlarge"] .need-btn {
    min-width: 100px;
    padding: 10px 16px;
    font-size: 2.6rem;
}
[data-emoji-size="xlarge"] .need-btn .need-label {
    font-size: 0.9rem;
}

.top-bar-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    justify-content: center;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.action-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-focus);
    box-shadow: var(--shadow-sm);
}

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

.action-btn.dwelling {
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.action-btn .dwell-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    background: var(--accent);
    transition: width linear;
    width: 0%;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.action-btn.dwelling .dwell-fill {
    width: 100%;
}

.btn-icon {
    font-size: 1rem;
}

/* Larger action buttons (Copiar, Ajustes) to match Hablar/Borrar style */
.action-btn-large {
    flex-direction: column;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    border-width: 2px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.action-btn-large .btn-icon {
    font-size: 1.8rem;
}

/* --- Text Output --- */
.text-display-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
    flex-shrink: 0;
}

.text-display-section {
    flex: 1;
    flex-shrink: 0;
}

.clear-btn-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 24px;
    min-width: 100px;
    background: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.clear-btn-large .btn-icon {
    font-size: 2rem;
}

.clear-btn-large:hover {
    background: var(--surface-hover);
    border-color: #e74c3c;
    box-shadow: 0 4px 16px rgba(231, 76, 60, 0.3);
    transform: translateY(-1px);
}

.clear-btn-large.dwelling {
    border-color: #e74c3c;
    box-shadow: 0 4px 16px rgba(231, 76, 60, 0.4);
}

.clear-btn-large .dwell-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    background: #e74c3c;
    transition: width linear;
    width: 0%;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.clear-btn-large.dwelling .dwell-fill {
    width: 100%;
}

.delete-word-btn-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 24px;
    min-width: 100px;
    background: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.delete-word-btn-large .btn-icon {
    font-size: 2rem;
}

.delete-word-btn-large:hover {
    background: var(--surface-hover);
    border-color: #e67e22;
    box-shadow: 0 4px 16px rgba(230, 126, 34, 0.3);
    transform: translateY(-1px);
}

.delete-word-btn-large.dwelling {
    border-color: #e67e22;
    box-shadow: 0 4px 16px rgba(230, 126, 34, 0.4);
}

.delete-word-btn-large .dwell-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    background: #e67e22;
    transition: width linear;
    width: 0%;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.delete-word-btn-large.dwelling .dwell-fill {
    width: 100%;
}

.speak-btn-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 24px;
    min-width: 100px;
    background: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.speak-btn-large .btn-icon {
    font-size: 2rem;
}

.speak-btn-large:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
    transform: translateY(-1px);
}

.speak-btn-large.dwelling {
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.speak-btn-large.speaking {
    border-color: #2ecc71;
    box-shadow: 0 4px 16px rgba(46, 204, 113, 0.4);
    animation: pulse-speak 1s ease-in-out infinite;
}

@keyframes pulse-speak {
    0%, 100% { box-shadow: 0 4px 16px rgba(46, 204, 113, 0.3); }
    50% { box-shadow: 0 4px 24px rgba(46, 204, 113, 0.6); }
}

.speak-btn-large .dwell-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    background: var(--accent);
    transition: width linear;
    width: 0%;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.speak-btn-large.dwelling .dwell-fill {
    width: 100%;
}

.text-output {
    min-height: 100px;
    max-height: 180px;
    overflow-y: auto;
    padding: 20px 24px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 1.4rem;
    line-height: 1.8;
    color: var(--text-primary);
    word-wrap: break-word;
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition-normal);
}

.text-output:focus-within {
    border-color: var(--accent);
}

.cursor-blink {
    display: inline;
    color: var(--accent);
    font-weight: 300;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* --- Predictions Bar --- */
.predictions-bar {
    flex-shrink: 0;
}

.predictions-container {
    display: flex;
    gap: 8px;
    padding: 8px 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

.predictions-container::-webkit-scrollbar {
    display: none;
}

.prediction-btn {
    flex-shrink: 0;
    padding: 10px 22px;
    background: linear-gradient(135deg, var(--surface), var(--surface-hover));
    color: var(--accent-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    font-family: var(--font-family);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    min-width: 80px;
    text-align: center;
}

.prediction-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
    transform: translateY(-2px);
}

.prediction-btn.dwelling {
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.prediction-btn .dwell-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 5px;
    background: #fff;
    transition: width linear;
    width: 0%;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.prediction-btn.dwelling .dwell-fill {
    width: 100%;
}

.prediction-empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 10px 22px;
    font-size: 0.95rem;
}

/* --- Keyboard --- */
.keyboard-section {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: var(--key-gap);
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    width: 100%;
    box-sizing: border-box;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: var(--key-gap);
}

/* --- Key --- */
.key {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    min-width: 0;
    height: var(--key-size);
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--key-font-size);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-key);
    overflow: hidden;
}

.key .key-label {
    position: relative;
    z-index: 2;
    pointer-events: none;
}

.key .key-sublabel {
    position: absolute;
    top: 5px;
    right: 7px;
    font-size: 0.6em;
    color: var(--text-muted);
    z-index: 2;
    pointer-events: none;
}

/* Dwell progress fill inside keys */
.key .dwell-progress-bg {
    position: absolute;
    inset: 0;
    background: var(--accent);
    opacity: 0;
    z-index: 1;
    border-radius: var(--radius-md);
    transition: none;
}

.key.dwelling .dwell-progress-bg {
    opacity: 0.25;
    animation: dwellFill var(--dwell-duration, 800ms) linear forwards;
}

@keyframes dwellFill {
    from {
        clip-path: inset(100% 0 0 0);
    }
    to {
        clip-path: inset(0 0 0 0);
    }
}

/* Hover state */
.key:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    box-shadow: var(--shadow-key-hover);
    transform: translateY(-2px) scale(1.04);
    z-index: 10;
}

/* Dwelling state */
.key.dwelling {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow), var(--shadow-key-hover);
    transform: translateY(-2px) scale(1.06);
    z-index: 10;
}

/* Activated flash */
.key.activated {
    background: var(--accent) !important;
    color: #fff !important;
    transform: translateY(0) scale(0.96);
    transition: all 0.08s ease;
}

/* Cooldown state */
.key.cooldown {
    opacity: 0.5;
    pointer-events: none;
}

/* --- Special keys --- */
.key-space {
    flex: 6;
}

.key-backspace,
.key-enter {
    flex: 1.8;
    font-size: calc(var(--key-font-size) * 0.8);
}

.key-shift {
    flex: 2.2;
    font-size: calc(var(--key-font-size) * 0.8);
}

.key-tab {
    flex: 1.5;
    font-size: calc(var(--key-font-size) * 0.8);
}

.key-caps {
    flex: 1.7;
    font-size: calc(var(--key-font-size) * 0.75);
}

.key-special {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: calc(var(--key-font-size) * 0.85);
}

.key-special:hover {
    background: var(--surface-hover);
}

.key-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: #fff;
    font-weight: 600;
}

.key-accent:hover {
    box-shadow: 0 6px 24px var(--accent-glow);
}

/* High contrast: keep yellow space bar but use dark text for readability */
[data-theme="high-contrast"] .key-accent {
    color: #000;
}

/* Light theme: slightly deeper gradient for visibility */
[data-theme="light"] .key-accent {
    background: linear-gradient(135deg, #5b52e0, #7068f0);
    color: #fff;
}

/* Caps lock active indicator */
.key-caps.active {
    background: var(--accent);
    color: #fff;
}

/* Shift active indicator */
.key-shift.active {
    background: var(--accent-secondary);
    color: #fff;
}

/* --- Dwell Ring Indicator (follows cursor, shown globally) --- */
.dwell-indicator {
    position: fixed;
    width: 36px;
    height: 36px;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.15s ease;
    transform: translate(-50%, -50%);
}

.dwell-indicator.visible {
    opacity: 1;
}

.dwell-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.dwell-ring-bg {
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 3;
    opacity: 0.3;
}

.dwell-ring-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 100.53;
    stroke-dashoffset: 100.53;
    transition: stroke-dashoffset linear;
}

/* --- Settings Panel --- */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.settings-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: right var(--transition-normal);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.settings-panel.open {
    right: 0;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.settings-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.settings-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.slider-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--surface);
    outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 6px var(--accent-glow);
}

.slider-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    min-width: 60px;
    text-align: right;
}

select {
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
}

select:focus {
    border-color: var(--accent);
}

.setting-input {
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition-fast);
    width: 100%;
}

.setting-input:focus {
    border-color: var(--accent);
}

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

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex-direction: row !important;
}

.toggle-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* --- Arrow navigation focus --- */
.arrow-focused {
    outline: 3px solid var(--accent) !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px var(--accent-glow), var(--shadow-key-hover) !important;
    transform: scale(1.06);
    z-index: 20 !important;
    transition: all 0.1s ease !important;
}

[data-theme="high-contrast"] .arrow-focused {
    outline: 4px solid var(--accent) !important;
    outline-offset: 3px;
    box-shadow: 0 0 0 8px var(--accent-glow) !important;
}

/* --- Settings hint text --- */
.setting-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.3;
    margin-top: -4px;
}

/* --- Copy confirmation toast --- */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 28px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-xl);
    font-size: 0.95rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 10000;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Scrollbar --- */
.text-output::-webkit-scrollbar {
    width: 6px;
}

.text-output::-webkit-scrollbar-track {
    background: transparent;
}

.text-output::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: 3px;
}

/* =============================================================
   Responsive Design — adapt to any screen size
   ============================================================= */

/* Use viewport-relative key heights so the keyboard always fits */
.key {
    height: clamp(36px, var(--key-size), 100px);
}

/* --- Extra-large screens (> 1600px) --- */
@media (min-width: 1601px) {
    .app-container {
        max-width: 1600px;
    }
}

/* --- Large tablets / small laptops (≤ 1200px) --- */
@media (max-width: 1200px) {
    .app-container {
        padding: 12px 14px;
        gap: 10px;
    }

    .text-output {
        min-height: 80px;
        max-height: 150px;
        font-size: 1.25rem;
        padding: 16px 18px;
    }

    .speak-btn-large,
    .delete-word-btn-large,
    .clear-btn-large {
        padding: 10px 16px;
        min-width: 85px;
        font-size: 0.9rem;
    }

    .speak-btn-large .btn-icon,
    .delete-word-btn-large .btn-icon,
    .clear-btn-large .btn-icon {
        font-size: 1.6rem;
    }

    .keyboard {
        padding: 12px;
    }
}

/* --- Tablets landscape / narrow laptops (≤ 1024px) --- */
@media (max-width: 1024px) {
    :root {
        --key-gap: 4px;
    }

    .app-container {
        padding: 10px 10px;
        gap: 8px;
    }

    .need-btn {
        min-width: 56px;
        padding: 5px 8px;
        font-size: 1.2rem;
    }

    .need-btn .need-label {
        font-size: 0.55rem;
    }

    .quick-needs {
        gap: 4px;
        padding: 8px 10px;
    }

    .text-output {
        min-height: 65px;
        max-height: 130px;
        font-size: 1.15rem;
        padding: 12px 14px;
        line-height: 1.6;
    }

    .keyboard {
        padding: 10px;
    }

    .prediction-btn {
        padding: 8px 16px;
        font-size: 0.95rem;
        min-width: 70px;
    }
}

/* --- Tablets portrait / large phones landscape (≤ 900px) --- */
@media (max-width: 900px) {
    .app-container {
        padding: 8px 8px;
        gap: 6px;
    }

    .top-bar {
        flex-direction: column;
    }

    .top-bar-actions {
        flex-direction: row;
        justify-content: center;
    }

    .text-display-row {
        flex-wrap: wrap;
    }

    .text-display-section {
        flex: 1 1 100%;
    }

    .speak-btn-large,
    .delete-word-btn-large,
    .clear-btn-large {
        flex: 1 1 0;
        min-width: 0;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .speak-btn-large .btn-icon,
    .delete-word-btn-large .btn-icon,
    .clear-btn-large .btn-icon {
        font-size: 1.3rem;
    }

    .text-output {
        min-height: 60px;
        max-height: 120px;
        font-size: 1.1rem;
        padding: 12px 14px;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }

    .keyboard {
        padding: 8px;
    }

    .key .key-sublabel {
        font-size: 0.5em;
        top: 3px;
        right: 4px;
    }
}

/* --- Small tablets / phones landscape (≤ 700px) --- */
@media (max-width: 700px) {
    :root {
        --key-size: 48px;
        --key-font-size: 1rem;
        --key-gap: 3px;
    }

    .need-btn {
        min-width: 48px;
        padding: 4px 6px;
        font-size: 1rem;
    }

    .need-btn .need-label {
        font-size: 0.5rem;
    }

    .quick-needs {
        gap: 3px;
        padding: 6px 8px;
    }

    .text-output {
        min-height: 50px;
        max-height: 100px;
        font-size: 1rem;
        padding: 10px 12px;
    }

    .prediction-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
        min-width: 60px;
    }

    .predictions-container {
        gap: 5px;
    }

    .keyboard {
        padding: 6px;
        border-radius: var(--radius-md);
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

/* --- Phones portrait (≤ 500px) --- */
@media (max-width: 500px) {
    :root {
        --key-size: 40px;
        --key-font-size: 0.85rem;
        --key-gap: 2px;
    }

    .app-container {
        padding: 6px 4px;
        gap: 5px;
    }

    .need-btn {
        min-width: 40px;
        padding: 3px 5px;
        font-size: 0.9rem;
    }

    .need-btn .need-label {
        display: none;
    }

    .quick-needs {
        gap: 3px;
        padding: 5px 6px;
    }

    .text-display-row {
        gap: 5px;
    }

    .speak-btn-large span:last-child,
    .delete-word-btn-large span:last-child,
    .clear-btn-large span:last-child {
        font-size: 0.7rem;
    }

    .speak-btn-large .btn-icon,
    .delete-word-btn-large .btn-icon,
    .clear-btn-large .btn-icon {
        font-size: 1.1rem;
    }

    .speak-btn-large,
    .delete-word-btn-large,
    .clear-btn-large {
        padding: 6px 6px;
        gap: 2px;
    }

    .text-output {
        min-height: 45px;
        max-height: 80px;
        font-size: 0.9rem;
        padding: 8px 10px;
        line-height: 1.5;
    }

    .keyboard {
        padding: 4px;
        border-radius: var(--radius-sm);
    }

    .key {
        border-radius: var(--radius-sm);
    }

    .key .key-sublabel {
        display: none;
    }

    .prediction-btn {
        padding: 5px 10px;
        font-size: 0.8rem;
        min-width: 50px;
        border-radius: var(--radius-md);
    }

    .settings-body {
        padding: 14px 16px;
        gap: 18px;
    }

    .settings-header {
        padding: 14px 16px;
    }
}

/* --- Very small phones (≤ 380px) --- */
@media (max-width: 380px) {
    :root {
        --key-size: 34px;
        --key-font-size: 0.75rem;
        --key-gap: 2px;
    }

    .app-container {
        padding: 4px 2px;
        gap: 4px;
    }

    .text-output {
        min-height: 36px;
        max-height: 60px;
        font-size: 0.8rem;
        padding: 6px 8px;
    }

    .speak-btn-large span:last-child,
    .delete-word-btn-large span:last-child,
    .clear-btn-large span:last-child {
        display: none;
    }

    .speak-btn-large,
    .delete-word-btn-large,
    .clear-btn-large {
        padding: 5px 5px;
        min-width: 0;
    }
}

/* --- Height-constrained screens (landscape phones, short windows) --- */
@media (max-height: 600px) {
    .app-container {
        padding: 4px 8px;
        gap: 4px;
    }

    .quick-needs {
        max-height: 60px;
        overflow-y: auto;
        padding: 4px 8px;
    }

    .text-output {
        min-height: 36px;
        max-height: 60px;
        padding: 6px 10px;
        font-size: 0.95rem;
    }

    .keyboard {
        padding: 4px;
    }

    :root {
        --key-size: 36px;
        --key-gap: 2px;
    }

    .prediction-btn {
        padding: 4px 10px;
        font-size: 0.8rem;
    }

    .predictions-container {
        padding: 4px 2px;
    }

    .speak-btn-large,
    .delete-word-btn-large,
    .clear-btn-large {
        padding: 4px 8px;
        gap: 2px;
    }

    .speak-btn-large .btn-icon,
    .delete-word-btn-large .btn-icon,
    .clear-btn-large .btn-icon {
        font-size: 1rem;
    }

    .speak-btn-large span:last-child,
    .delete-word-btn-large span:last-child,
    .clear-btn-large span:last-child {
        font-size: 0.7rem;
    }
}

@media (max-height: 450px) {
    .quick-needs {
        max-height: 45px;
    }

    .need-btn .need-label {
        display: none;
    }

    .text-output {
        min-height: 30px;
        max-height: 45px;
    }

    :root {
        --key-size: 30px;
        --key-font-size: 0.7rem;
    }

    .key .key-sublabel {
        display: none;
    }
}

/* --- Combined: very short + narrow (landscape phone) --- */
@media (max-width: 700px) and (max-height: 500px) {
    .top-bar {
        flex-direction: row;
    }

    .top-bar-actions {
        flex-direction: column;
        padding: 4px 6px;
    }

    .action-btn {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .text-display-section {
        flex: 1 1 0;
    }

    .text-display-row {
        flex-wrap: nowrap;
    }
}
