:root {
  --parchment: #e8d8b5;
  --ink: #1b1308;
  --bg: #0e0a06;
  --bg2: #241a0f;
  --gold: #c9a24b;
  --gryffindor: #740001;
  --slytherin: #1a472a;
  --ravenclaw: #0e1a40;
  --hufflepuff: #726300;
}

* { box-sizing: border-box; }

/* Varje regel nedan som sätter display på ett element med en egen id/klass
   (t.ex. #talk-area, .screen) har SAMMA specificitet som webbläsarens
   standard-[hidden]-regel, och vinner alltid eftersom författarens CSS går
   före UA-stilen (origin, inte specificitet). Utan den här globala regeln
   ligger "dolda" element kvar synliga och överlappande — hittat med
   Playwright/WebKit (talk-knappen syntes före "Sätt på hatten" var tryckt). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--parchment);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  height: 100%;
  overflow-x: hidden;
}

body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%);
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
}

h1 {
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(201, 162, 75, 0.35);
  margin: 0;
}

.sub { color: #c9bda0; margin: 0; }

input[type="password"] {
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 0.6rem 1rem;
  border-radius: 0.6rem;
  border: 1px solid var(--gold);
  background: #1a1309;
  color: var(--parchment);
  width: 10rem;
}

button {
  font-family: inherit;
  font-size: 1.05rem;
  padding: 0.7rem 1.4rem;
  border-radius: 0.8rem;
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, #3a2a12, #1a1309);
  color: var(--parchment);
  cursor: pointer;
}

button.primary {
  background: linear-gradient(180deg, var(--gold), #8a6a24);
  color: #1b1308;
  font-weight: 600;
}

.ghost {
  background: transparent;
  border-color: #6b5a38;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid #6b5a38;
  border-radius: 0.8rem;
  color: var(--parchment);
  text-decoration: none;
  display: inline-block;
}

.header-knappar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.varning {
  color: #e0b84a;
  font-size: 0.8rem;
}

button.talk {
  width: 10rem;
  height: 10rem;
  border-radius: 50%;
  font-size: 1rem;
  background: radial-gradient(circle, #4a331a, #1a1309);
}

/* Lyssnar (VAD aktiv, väntar på att höra tal) — lugn guldpuls, skiljer sig
   tydligt från "recording" (talet faktiskt hörs) så barnet/David kan se
   skillnaden mellan "jag väntar" och "jag hör dig". */
button.talk.listening {
  background: radial-gradient(circle, #6b4f1f, #1a1309);
  box-shadow: 0 0 20px rgba(201, 162, 75, 0.45);
  animation: lyssnar-puls 1.6s ease-in-out infinite;
}

button.talk.recording {
  background: radial-gradient(circle, var(--gryffindor), #1a1309);
  box-shadow: 0 0 30px rgba(116, 0, 1, 0.6);
}

@keyframes lyssnar-puls {
  0%, 100% { box-shadow: 0 0 20px rgba(201, 162, 75, 0.45); }
  50% { box-shadow: 0 0 34px rgba(201, 162, 75, 0.75); }
}

/* Nivåmätaren (public/vad.js RMS → #niva-bar.style.width) — "Jag lyssnar…"
   ska synas göra NÅGOT när mikrofonen faktiskt hör en, inte bara en text. */
#niva-meter {
  width: 10rem;
  height: 0.5rem;
  border-radius: 0.3rem;
  background: #1a1309;
  border: 1px solid #6b5a38;
  overflow: hidden;
}

#niva-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), #e8d8b5);
  transition: width 60ms linear;
}

.error { color: #d96b6b; }

#main-screen header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  background: rgba(14, 10, 6, 0.85);
  z-index: 5;
}

#main-screen header h1 { font-size: 1.1rem; }

#main-screen main {
  margin-top: 3.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
}

#hat-stage { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
#hat-icon { font-size: 4rem; }
#hat-caption { max-width: 22rem; min-height: 3rem; font-size: 1.05rem; line-height: 1.4; }
.status { font-size: 0.85rem; color: #a08a5a; min-height: 1.2rem; }

#talk-area { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.hint { font-size: 0.8rem; color: #8a7a5a; margin: 0; }

#debug-panel {
  position: fixed;
  top: 3.3rem;
  left: 0;
  right: 0;
  background: rgba(10, 8, 5, 0.95);
  border-bottom: 1px solid var(--gold);
  padding: 0.6rem 1rem;
  font-size: 0.75rem;
  z-index: 4;
  max-height: 40vh;
  overflow-y: auto;
}

#debug-table { width: 100%; border-collapse: collapse; }
#debug-table th, #debug-table td { padding: 0.2rem 0.4rem; text-align: center; }
#debug-table th { color: var(--gold); }

#reveal-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  transition: background 0.8s ease;
}

#reveal-screen.Gryffindor { background: linear-gradient(160deg, var(--gryffindor), #3a0000); }
#reveal-screen.Slytherin { background: linear-gradient(160deg, var(--slytherin), #06130a); }
#reveal-screen.Ravenclaw { background: linear-gradient(160deg, var(--ravenclaw), #050a1c); }
#reveal-screen.Hufflepuff { background: linear-gradient(160deg, var(--hufflepuff), #2a2400); }

#reveal-house {
  font-size: 2.4rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#reveal-text { max-width: 24rem; font-size: 1.1rem; line-height: 1.5; }

@media (max-width: 420px) {
  button.talk { width: 8.5rem; height: 8.5rem; }
  h1 { font-size: 1.35rem; }
}
