/* Layout: un palco verticale. Logo in alto, occhio di bue con il fedora e la parola al centro,
   il pavimento luminoso di Billie Jean in prospettiva, i comandi in fondo. Look unico, sempre scuro. */
:root {
  --stage: #09080b;
  --ink: #f5f2f7;
  --muted: #9a93a3;
  --silver: #cfccd6;
  --red: #e1252f;
  --glow: #ffeac0;
  --tile: #16141b;
  --line: #2b2731;
  --beam: rgba(255, 244, 222, 0.12);

  --display: "Anton", Impact, "Arial Narrow", sans-serif;
  --body: "Chivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Chivo Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gutter: max(16px, 4vw);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--stage);
  color: var(--ink);
  font: 400 15px/1.5 var(--body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(340px, 1fr) auto auto;
  overflow-x: clip;
}

/* ---------- header ---------- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px var(--gutter) 0;
  position: relative;
  z-index: 4;
}
.logo {
  font-family: var(--display);
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  line-height: 1;
}
.logo span { color: var(--red); }
.counter { display: flex; align-items: baseline; gap: 10px; }
.counter-label {
  font: 500 0.7rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.counter-value {
  font-family: var(--display);
  font-size: 1.6rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ---------- palco ---------- */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px var(--gutter) 8px;
  text-align: center;
  isolation: isolate;
}
.beam {
  position: absolute;
  inset: -80px 0 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 30% 26% at 50% 78%, var(--beam), transparent 70%),
    linear-gradient(to bottom, var(--beam), transparent 95%);
  clip-path: polygon(44% 0, 56% 0, 84% 100%, 16% 100%);
  pointer-events: none;
}

.fedora {
  width: min(250px, 58vw);
  height: auto;
  overflow: visible;
  transform-origin: 50% 90%;
  animation: bob 5s ease-in-out infinite;
}
.fedora .crown, .fedora .brim { fill: #121016; stroke: var(--silver); stroke-width: 1.5; }
.fedora .band { fill: var(--ink); }
.fedora.tip { animation: tip 0.9s cubic-bezier(.3, 1.6, .5, 1); }

@keyframes bob { 50% { transform: translateY(-6px) rotate(-1.5deg); } }
@keyframes tip {
  0% { transform: none; }
  30% { transform: translateY(-26px) rotate(-16deg); }
  100% { transform: none; }
}

.word {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-inline: var(--gutter);
  font-family: var(--display);
  font-size: clamp(4.2rem, 19vw, 15rem);
  text-wrap: balance;
  line-height: 0.9;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-shadow: 0.045em 0.045em 0 var(--red);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}
.word.pop { animation: pop 1.9s cubic-bezier(.2, .9, .3, 1.3) forwards; }
@keyframes pop {
  0%   { opacity: 0; transform: scale(.35) rotate(-7deg); }
  12%  { opacity: 1; transform: scale(1.08) rotate(2deg); }
  22%  { transform: scale(1) rotate(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05); }
}

.intro { display: grid; justify-items: center; gap: 14px; max-width: 34rem; }
.intro h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1;
  text-transform: uppercase;
  text-wrap: balance;
}
.intro p { margin: 0; color: var(--muted); text-wrap: balance; }

.start {
  margin-top: 10px;
  font: 400 1.5rem/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 18px 34px;
  color: var(--stage);
  background: var(--ink);
  border: 0;
  box-shadow: 6px 6px 0 var(--red);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.start:hover { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--red); }
.start:active { transform: translate(4px, 4px); box-shadow: 2px 2px 0 var(--red); }
.start:disabled { cursor: progress; opacity: .7; }

.status {
  margin: 0;
  font: 500 0.78rem/1.4 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  max-width: 30rem;
  text-wrap: balance;
}
.status::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--red);
  vertical-align: 1px;
  animation: rec 1.6s steps(1) infinite;
}
.status.paused::before { background: var(--muted); animation: none; }
@keyframes rec { 50% { opacity: 0; } }

/* ---------- pavimento di Billie Jean ---------- */
.floor-wrap {
  height: clamp(120px, 22vh, 210px);
  perspective: 520px;
  perspective-origin: 50% 0;
  overflow: hidden;
  contain: paint;
  mask-image: linear-gradient(to bottom, #000 55%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
}
.floor {
  width: 170%;
  margin-left: -35%;
  height: 260%;
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: 6px;
  transform: rotateX(60deg);
  transform-origin: 50% 0;
}
.tile {
  background: var(--tile);
  border: 1px solid var(--line);
  transition: background-color .7s ease-out, box-shadow .7s ease-out;
}
.tile.dim { background: color-mix(in srgb, var(--glow) 22%, var(--tile)); transition-duration: .3s; }
.tile.lit {
  background: var(--glow);
  box-shadow: 0 0 40px 6px var(--glow);
  transition-duration: .06s;
}

/* ---------- comandi ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 28px;
  padding: 6px var(--gutter) 20px;
  position: relative;
  z-index: 4;
}
.modes {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.modes legend, .volume {
  font: 500 0.7rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.modes legend { padding: 0; margin-bottom: 8px; }
.modes label { cursor: pointer; }
.modes input { position: absolute; opacity: 0; pointer-events: none; }
.modes span {
  display: grid;
  gap: 4px;
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.1;
  transition: background-color .15s, color .15s, border-color .15s;
}
.modes b { font-weight: 600; }
.modes i {
  font: 400 0.68rem/1 var(--mono);
  font-style: normal;
  color: var(--muted);
  margin-left: 4px;
}
.modes small { font-weight: 400; font-size: 0.78rem; line-height: 1.25; color: var(--muted); }
.modes label:hover span { border-color: var(--silver); }
.modes input:checked + span { background: var(--ink); color: var(--stage); border-color: var(--ink); }
.modes input:checked + span :is(small, i) { color: var(--stage); opacity: .7; }
.modes input:focus-visible + span { outline: 2px solid var(--red); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.volume { display: flex; align-items: center; gap: 10px; }
.volume input { width: 110px; accent-color: var(--red); }
.ghost {
  font: 600 0.9rem/1 var(--body);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  padding: 10px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.ghost:hover:not(:disabled) { border-color: var(--silver); }
.ghost:disabled { color: var(--muted); cursor: not-allowed; opacity: .6; }
kbd {
  font: 400 0.65rem/1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 3px 5px;
}
.fine {
  flex-basis: 100%;
  margin: 0;
  font: 400 0.68rem/1.4 var(--mono);
  color: var(--muted);
  opacity: .8;
}

button:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

/* ---------- effetti ---------- */
.sparkles { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
body.shake .app { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  15%, 85% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(4px); }
  45%, 60% { transform: translateX(-6px); }
}

@media (max-width: 560px) {
  .controls { align-items: stretch; }
  .modes span { padding: 8px 10px; font-size: .82rem; }
  kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .fedora, .fedora.tip, body.shake .app, .status::before { animation: none; }
  .word.pop { animation: fade 1.9s linear forwards; }
  @keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
}

/* ---------- modalità OBS (?obs=1): solo la parola, sfondo trasparente ---------- */
html.obs, html.obs body { background: transparent; }
html.obs .top, html.obs .intro, html.obs .status, html.obs .beam, html.obs .fedora,
html.obs .floor-wrap, html.obs .controls { display: none; }
html.obs .word {
  position: fixed;
  filter: drop-shadow(0 0 14px rgba(0, 0, 0, 0.6));
}
.obs-hint {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  font: 500 0.8rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink);
  background: var(--stage);
  border: 1px solid var(--red);
}
