/* ============================================================================
   Casa Marfori — visual "casa" acolhedor sobre fundo escuro.
   O canvas #matrix fica atrás (chuva verde sutil); a UI de controle vem por
   cima, legível, com cards semi-opacos. Paleta AlphaPró em tom quente.
   Otimizado para o painel 480x480 E para celular (responsivo, touch).
   ========================================================================== */

:root {
  --primary: #1a365b;
  --primary-claro: #2a4d7a;
  --gold: #d4a574;
  --gold-dark: #b38d67;

  /* Fundo escuro/quente para o Matrix verde aparecer sutilmente atrás */
  --fundo: #0d1220;
  --fundo-quente: #14100c;

  --card-bg: rgba(18, 22, 18, 0.62);
  --card-borda: rgba(212, 165, 116, 0.22);
  --card-borda-forte: rgba(212, 165, 116, 0.4);

  --texto: #f4ece1;
  --texto-suave: #cbbfae;
  --texto-fraco: #8b8072;

  --verde: #34d17a;
  --vermelho: #e0664f;
  --cinza-off: #6d6459;

  --raio: 18px;
  --raio-sm: 12px;
  --sombra: 0 10px 30px rgba(0, 0, 0, 0.45);

  --toque: 52px; /* alvo mínimo de toque */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  color: var(--texto);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(179, 141, 103, 0.10), transparent 60%),
    linear-gradient(160deg, var(--fundo) 0%, var(--fundo-quente) 100%);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* Canvas Matrix — atrás de tudo, discreto */
#matrix {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  opacity: 0.16;
  pointer-events: none;
}

.hidden { display: none !important; }

/* Telas ocupam a viewport e ficam acima do Matrix */
.tela {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
}

/* ============================ TELA SENHA ================================== */

.tela-senha {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.senha-box {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border: 1px solid var(--card-borda-forte);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 34px 28px 28px;
  text-align: center;
}

.senha-marca {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}

.senha-marca-linha {
  height: 1px;
  width: 34px;
  background: linear-gradient(90deg, transparent, var(--gold-dark));
}
.senha-marca-linha:last-child {
  background: linear-gradient(90deg, var(--gold-dark), transparent);
}

.senha-marca-nome {
  font-family: 'Georgia', 'EB Garamond', serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--gold);
}

.senha-titulo {
  font-family: 'Georgia', 'EB Garamond', serif;
  font-size: 1.8rem;
  margin: 6px 0 8px;
  color: var(--texto);
  font-weight: 500;
}

.senha-sub {
  color: var(--texto-suave);
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0 0 22px;
}

.senha-input {
  width: 100%;
  height: 56px;
  border-radius: var(--raio-sm);
  border: 1px solid var(--card-borda);
  background: rgba(0, 0, 0, 0.35);
  color: var(--texto);
  font-size: 1.5rem;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 0 14px;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.senha-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.18);
}

.senha-erro {
  color: var(--vermelho);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 12px 0 0;
}

/* ======================== BOTÕES GRANDES ================================= */

.btn-grande {
  width: 100%;
  min-height: var(--toque);
  border: none;
  border-radius: var(--raio-sm);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn-grande:active { transform: scale(0.985); }

.btn-entrar {
  color: #1c130a;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  box-shadow: 0 6px 18px rgba(179, 141, 103, 0.28);
}
.btn-entrar:hover { filter: brightness(1.05); }
.btn-entrar:disabled { opacity: 0.6; cursor: default; }

.btn-largo {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--card-borda);
  border-radius: var(--raio-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--texto);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-largo:hover { background: rgba(212, 165, 116, 0.12); border-color: var(--card-borda-forte); }
.btn-largo:active { transform: scale(0.99); }

/* ========================= TELA CONTROLE ================================= */

.tela-controle {
  display: flex;
  flex-direction: column;
  padding: 14px 14px 22px;
  gap: 12px;
}

.casa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 2px;
}

.casa-header-marca {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.casa-header-ponto {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 12px rgba(212, 165, 116, 0.7);
  flex-shrink: 0;
}

.casa-header-nome {
  font-family: 'Georgia', 'EB Garamond', serif;
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--gold);
  margin: 0;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.casa-header-acoes {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-icone {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--card-borda);
  background: rgba(255, 255, 255, 0.04);
  color: var(--gold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-icone:hover { background: rgba(212, 165, 116, 0.14); }
.btn-icone:active { transform: scale(0.94); }
.btn-icone svg { width: 22px; height: 22px; }
.btn-sair { color: var(--texto-suave); }

/* Aviso e loading */
.aviso {
  background: rgba(224, 102, 79, 0.12);
  border: 1px solid rgba(224, 102, 79, 0.4);
  color: #f0a897;
  border-radius: var(--raio-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 0;
  color: var(--texto-suave);
}
.loading-spin {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(212, 165, 116, 0.2);
  border-top-color: var(--gold);
  animation: girar 0.8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.casa-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grade-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* ============================== CARDS =================================== */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 16px;
}
.card.offline { opacity: 0.62; }

.card-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-topo-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.card-icone {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--gold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.card-icone svg { width: 24px; height: 24px; }

.card-topo-textos { min-width: 0; }

.card-nome {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--texto);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge-ligado { background: rgba(52, 209, 122, 0.18); color: var(--verde); }
.badge-desligado { background: rgba(109, 100, 89, 0.25); color: var(--texto-fraco); }
.badge-offline { background: rgba(224, 102, 79, 0.18); color: var(--vermelho); }

/* Toggle liga/desliga grande (touch) */
.toggle {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(109, 100, 89, 0.4);
  border-radius: 34px;
  transition: background 0.25s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background: #cbbfae;
  border-radius: 50%;
  transition: transform 0.25s, background 0.25s;
}
.toggle input:checked + .toggle-slider { background: rgba(52, 209, 122, 0.4); }
.toggle input:checked + .toggle-slider::before { transform: translateX(26px); background: var(--verde); }
.toggle input:disabled + .toggle-slider { cursor: not-allowed; opacity: 0.4; }

/* Corpo do card (controles) */
.card-corpo {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(212, 165, 116, 0.14);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.linha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.linha-rotulo {
  font-size: 0.86rem;
  color: var(--texto-suave);
}
.linha-valor {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--texto);
}

/* Stepper (temperatura / volume) */
.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stepper-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--card-borda);
  background: rgba(255, 255, 255, 0.05);
  color: var(--texto);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}
.stepper-btn:hover { background: rgba(212, 165, 116, 0.14); }
.stepper-btn:active { transform: scale(0.92); }
.stepper-valor {
  min-width: 62px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
}

/* Selects (modo / ventilação / entrada) */
.card-select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 42px;
  min-width: 130px;
  border: 1px solid var(--card-borda);
  border-radius: 12px;
  background:
    rgba(0, 0, 0, 0.35)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23d4a574' d='M6 8L0 0h12z'/%3E%3C/svg%3E")
    no-repeat right 12px center;
  color: var(--texto);
  font-size: 0.9rem;
  padding: 0 34px 0 12px;
  cursor: pointer;
  outline: none;
}
.card-select:focus { border-color: var(--gold); }
.card-select option { background: var(--fundo); color: var(--texto); }

/* Botão dentro do card (ex.: mudo) */
.card-btn {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--card-borda);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--texto);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.card-btn:hover { background: rgba(212, 165, 116, 0.12); }
.card-btn:active { transform: scale(0.99); }
.card-btn.ativa { background: rgba(212, 165, 116, 0.22); border-color: var(--card-borda-forte); color: var(--gold); }

.card-offline-msg {
  font-size: 0.82rem;
  color: var(--texto-fraco);
  margin: 12px 0 0;
}

/* ========================== MINI-PLAYER SPOTIFY ========================== */

.card-spotify .card-icone { background: var(--primary); }

.sp-now {
  font-size: 0.85rem;
  color: var(--texto-suave);
  margin: 3px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.sp-controles {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 14px;
}

.btn-redondo {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--card-borda);
  background: rgba(255, 255, 255, 0.05);
  color: var(--texto);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn-redondo svg { width: 22px; height: 22px; }
.btn-redondo:hover { background: rgba(212, 165, 116, 0.14); }
.btn-redondo:active { transform: scale(0.92); }

.btn-play {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: #1c130a;
  border: none;
  box-shadow: 0 6px 18px rgba(179, 141, 103, 0.3);
}
.btn-play svg { width: 28px; height: 28px; }
.btn-play:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%); }

.sp-volume {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.sp-volume-icone { color: var(--texto-suave); display: inline-flex; }
.sp-volume-icone svg { width: 20px; height: 20px; }
.sp-volume-val {
  min-width: 34px;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--texto-suave);
}

/* Slider */
.sp-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--gold-dark), rgba(255, 255, 255, 0.12));
  outline: none;
}
.sp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid #1c130a;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.sp-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid #1c130a;
  cursor: pointer;
}

.sp-toggle-busca { margin-top: 16px; }

.sp-busca { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }

.sp-tipos { display: flex; gap: 8px; }
.sp-tipo {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--card-borda);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--texto-suave);
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sp-tipo.ativa { background: rgba(212, 165, 116, 0.2); color: var(--gold); border-color: var(--card-borda-forte); }

.sp-busca-linha { display: flex; gap: 8px; }
.sp-input {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--card-borda);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--texto);
  padding: 0 12px;
  font-size: 0.92rem;
  outline: none;
}
.sp-input:focus { border-color: var(--gold); }
.sp-btn-buscar { width: auto; min-width: 96px; }

.sp-resultados { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.sp-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--card-borda);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.sp-result span {
  font-size: 0.86rem;
  color: var(--texto);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-result em { color: var(--texto-fraco); font-style: normal; font-size: 0.78rem; }
.sp-result button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: rgba(212, 165, 116, 0.2);
  color: var(--gold);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 1rem;
}
.sp-result button:active { transform: scale(0.92); }

/* ============================== TOASTS ================================== */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 380px);
}
.toast {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  text-align: center;
  box-shadow: var(--sombra);
  animation: toast-in 0.2s ease-out;
}
.toast-ok { background: rgba(24, 20, 16, 0.94); border: 1px solid var(--card-borda-forte); color: var(--texto); }
.toast-erro { background: rgba(224, 102, 79, 0.95); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== RESPONSIVO / PAINEL 480x480 ====================== */

/* Painel de parede quadrado — compacta tudo pra caber sem scroll excessivo */
@media (max-width: 520px), (max-height: 540px) {
  .tela-controle { padding: 10px 10px 16px; gap: 10px; }
  .casa-header-nome { font-size: 1.15rem; }
  .card { padding: 12px; border-radius: 14px; }
  .card-icone { width: 40px; height: 40px; }
  .card-nome { font-size: 0.95rem; }
  .stepper-valor { font-size: 1.05rem; }
  .btn-play { width: 58px; height: 58px; }
  .btn-redondo { width: 48px; height: 48px; }
  .sp-controles { gap: 14px; }
}

/* Telas largas (celular deitado / tablet): 2 colunas de cards */
@media (min-width: 720px) {
  .grade-cards { grid-template-columns: 1fr 1fr; }
  .card-spotify { grid-column: 1 / -1; }
  .casa-main { max-width: 900px; margin: 0 auto; width: 100%; }
}

/* AlphaBot — microfone em verde Matrix quando ouvindo */
.btn-voz.gravando {
  color: #2ddc6e;
  border-color: rgba(45, 220, 110, 0.6);
  background: rgba(45, 220, 110, 0.12);
  animation: alphabot-pulso 1.1s ease-in-out infinite;
}
@keyframes alphabot-pulso {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45, 220, 110, 0.55); }
  50%      { box-shadow: 0 0 14px 4px rgba(45, 220, 110, 0.35); }
}

/* Respeita quem prefere menos movimento */
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .loading-spin { animation-duration: 1.6s; }
  .btn-voz.gravando { animation: none; }
}
