:root {
    /* Paleta de Cores do Tema Escuro Moderno */
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    
    /* Cores de Texto */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Cores de Destaque */
    --primary-color: #10b981;
    --primary-glow: rgba(16, 185, 129, 0.4);
    
    /* Cores das Teclas */
    --key-bg: #27303f;
    --key-border: #0f172a;
    --key-tested-bg: #064e3b;
    --key-tested-text: #34d399;
    --key-active-bg: #10b981;
    --key-active-text: #022c22;
    --led-off: #334155;
    --led-on: #34d399;
}

/* Reset Básico */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================
   CABEÇALHO E CONTROLES
   ========================================= */
.app-header {
    background-color: var(--surface-color);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--surface-hover);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.brand-link {
    text-decoration: none;
    color: var(--text-main);
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.highlight-text {
    color: var(--primary-color);
}

.version-badge {
    background-color: var(--primary-color);
    color: var(--key-active-text);
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.layout-form {
    display: flex;
    align-items: center;
    gap: 12px;
}

.layout-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.select-wrapper {
    position: relative;
}

select {
    appearance: none;
    background-color: var(--bg-color);
    color: var(--text-main);
    border: 1px solid var(--surface-hover);
    padding: 10px 40px 10px 16px;
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

select:focus, select:hover {
    border-color: var(--primary-color);
}

.select-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

/* =========================================
   ÁREA PRINCIPAL
   ========================================= */
.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    gap: 2rem;
}

/* =========================================
   STATUS E PROGRESSO
   ========================================= */
.test-status {
    width: 100%;
    max-width: 1100px;
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border: 1px solid var(--surface-hover);
}

.status-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.status-info h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

#keys-count-info {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background-color: var(--bg-color);
    border-radius: 5px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--primary-color);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 15px var(--primary-glow);
}

.btn-reset {
    align-self: flex-start;
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-reset:hover {
    background-color: var(--primary-color);
    color: var(--key-active-text);
}

/* =========================================
   TECLADO (Arquitetura de Blocos)
   ========================================= */
.keyboard-container {
    width: 100%;
    display: flex;
    justify-content: center;
}

.keyboard-wrapper {
    background-color: #1a2230;
    padding: 25px 30px 30px 30px;
    border-radius: 12px;
    border: 2px solid #2a3441;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), inset 0 2px 10px rgba(255,255,255,0.05);
    position: relative;
    user-select: none;
    
    /* NOVO: Transforma o wrapper na base que alinha os blocos lado a lado */
    display: flex;
    gap: 25px; /* Distância entre Letras, Setas e NumPad */
    align-items: flex-end; /* Garante que a barra de espaço e as setinhas fiquem alinhadas por baixo */
}

/* NOVO: Container de cada bloco individual */
.keyboard-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Estado de Carregamento */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    width: 100%;
    min-width: 800px;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--surface-hover);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 
    to { transform: rotate(360deg); } 
}

/* =========================================
   PAINEL DE LEDS
   ========================================= */
.led-panel {
    position: absolute;
    top: 15px;
    right: 40px;
    display: flex;
    gap: 20px;
}

.led-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.led-light {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--led-off);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
    transition: all 0.2s;
}

.led-light.on {
    background-color: var(--led-on);
    box-shadow: 0 0 8px var(--led-on), inset 0 1px 2px rgba(255,255,255,0.5);
}

.led-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* =========================================
   LINHAS E TECLAS INDIVIDUAIS
   ========================================= */
.keyboard-row {
    display: flex;
    gap: 6px;
    position: relative; /* Mantém as teclas altas contidas em sua própria linha */
}

/* Espaçadores (Agora suportam altura e largura flexíveis) */
.key-spacer {
    display: inline-block;
}

.key {
    background-color: var(--key-bg);
    border: 1px solid rgba(255,255,255,0.05);
    border-bottom: 4px solid var(--key-border);
    border-radius: 6px;
    min-height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-main);
    transition: all 0.05s ease;
    padding: 4px 8px;
    text-align: center;
    white-space: pre-line;
    line-height: 1.1;
    position: relative;
    cursor: default;
}

/* Tamanhos Padronizados */
.size-normal { min-width: 48px; max-width: 48px; }
.size-wide-1 { min-width: 75px; }
.size-wide-2 { min-width: 100px; }
.size-wide-3 { min-width: 130px; }
.size-space  { width: 335px; }

/* Teclas Altas (NumPad Plus e Enter) - Resolvido! */
.size-tall {
    min-width: 48px;
    height: 102px; /* 48px + 6px de gap + 48px */
    position: absolute; /* Descola do fluxo para ocupar duas linhas */
    z-index: 10;
}

/* Estados Visuais das Teclas */
.key.tested {
    background-color: var(--key-tested-bg);
    color: var(--key-tested-text);
    border-bottom-color: #022c22;
}

.key.active {
    background-color: var(--key-active-bg);
    color: var(--key-active-text);
    border-bottom-width: 0px;
    transform: translateY(4px);
    box-shadow: 0 -2px 10px var(--primary-glow);
}

/* =========================================
   LOG DE EVENTOS TÉCNICOS
   ========================================= */
.test-log-container {
    width: 100%;
    max-width: 1100px;
    background-color: var(--surface-color);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border: 1px solid var(--surface-hover);
}

.test-log-container h3 {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.log-wrapper {
    background-color: var(--bg-color);
    border-radius: 8px;
    padding: 12px;
    height: 150px;
    overflow-y: auto;
    border: 1px solid #000;
}

.test-log {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
}

.log-entry {
    padding: 6px 10px;
    border-radius: 4px;
    display: flex;
    gap: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.log-key-code {
    color: var(--primary-color);
    font-weight: bold;
    min-width: 160px;
}