:root {
  --ruby: #ff315d;
  --ruby-hot: #ffd6df;
  --amber: #ff9d52;
  --bg: #080006;
  --panel: rgba(18, 0, 8, 0.64);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ruby);
  font-family: "Courier New", Courier, monospace;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.28) 50%),
    radial-gradient(circle at center, transparent 48%, rgba(18, 0, 8, 0.72));
  background-size: 100% 4px, 100% 100%;
  mix-blend-mode: screen;
}

.matrix-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  isolation: isolate;
  cursor: crosshair;
  touch-action: none;
}

#matrix-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(180, 0, 42, 0.24), transparent 34%),
    radial-gradient(circle at 50% 50%, transparent 0 44%, rgba(12, 0, 6, 0.68) 74%),
    #000;
}

.hud {
  position: fixed;
  left: clamp(16px, 4vw, 48px);
  top: clamp(16px, 4vw, 42px);
  z-index: 10;
  width: min(410px, calc(100vw - 32px));
  padding: 16px 18px;
  border: 1px solid rgba(255, 49, 93, 0.5);
  background: var(--panel);
  box-shadow: 0 0 22px rgba(255, 49, 93, 0.18);
  text-shadow: 0 0 8px rgba(255, 49, 93, 0.62);
  backdrop-filter: blur(3px);
  user-select: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.hud.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
}

.hide-hud,
.show-hud {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 49, 93, 0.66);
  background: rgba(18, 0, 8, 0.7);
  color: var(--ruby);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.hide-hud {
  position: absolute;
  top: 10px;
  right: 10px;
}

.show-hud {
  position: fixed;
  left: clamp(16px, 4vw, 48px);
  top: clamp(16px, 4vw, 42px);
  z-index: 11;
}

.music-toggle {
  position: fixed;
  left: clamp(14px, 3vw, 34px);
  bottom: clamp(12px, 2.5vw, 28px);
  z-index: 12;
  min-width: 112px;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 49, 93, 0.58);
  border-radius: 0;
  background: rgba(18, 0, 8, 0.72);
  color: var(--ruby);
  font: 700 11px "Courier New", Courier, monospace;
  letter-spacing: 0;
  cursor: pointer;
  text-shadow: 0 0 8px rgba(255, 49, 93, 0.78);
}

.music-toggle:hover,
.music-toggle:focus-visible,
.music-toggle[aria-pressed="true"] {
  background: var(--ruby);
  color: #160006;
  outline: none;
}

.book-status {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 14;
  width: min(420px, calc(100vw - 32px));
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 1px solid var(--ruby-hot);
  background: rgba(18, 0, 8, 0.92);
  box-shadow: 0 0 28px rgba(255, 49, 93, 0.42);
  color: var(--ruby-hot);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  text-align: center;
  text-shadow: 0 0 10px rgba(255, 49, 93, 0.88);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -42%);
  transition: opacity 180ms ease, transform 180ms ease;
}

.book-status.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.visit-counter {
  position: fixed;
  right: clamp(14px, 3vw, 34px);
  bottom: clamp(12px, 2.5vw, 28px);
  z-index: 12;
  display: flex;
  min-height: 28px;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid rgba(255, 49, 93, 0.46);
  background: rgba(18, 0, 8, 0.72);
  color: var(--ruby);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(255, 49, 93, 0.78);
  user-select: none;
}

.visit-counter output {
  min-width: 6ch;
  color: var(--ruby-hot);
  font: inherit;
  text-align: right;
}

.visit-counter[hidden] {
  display: none;
}

.hide-hud:hover,
.hide-hud:focus-visible,
.show-hud:hover,
.show-hud:focus-visible {
  background: var(--ruby);
  color: #160006;
  outline: none;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 2px;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0;
}

.hud p {
  margin: 0 0 14px;
  max-width: 36rem;
  color: rgba(255, 214, 223, 0.84);
  font-size: 14px;
  line-height: 1.45;
}

.quality-bar {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
}

.quality-bar button {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 49, 93, 0.66);
  background: transparent;
  color: var(--ruby);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.quality-bar button:hover,
.quality-bar button:focus-visible,
.quality-bar button.is-active {
  background: var(--ruby);
  color: #160006;
  outline: none;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid var(--ruby);
  color: var(--ruby);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}

.back-link:hover,
.back-link:focus-visible {
  color: #160006;
  background: var(--ruby);
  outline: none;
  box-shadow: 0 0 14px rgba(255, 49, 93, 0.52);
}

@media (max-width: 720px) {
  .hud {
    padding: 14px 15px;
  }

  .hud p {
    font-size: 12px;
  }

  .visit-counter {
    right: 10px;
    bottom: 10px;
    min-height: 25px;
    gap: 5px;
    padding: 4px 7px;
    font-size: 10px;
  }

  .music-toggle {
    left: 10px;
    bottom: 10px;
    min-width: 102px;
    min-height: 27px;
    padding: 5px 7px;
    font-size: 10px;
  }

  .book-status {
    min-height: 48px;
    padding: 10px 14px;
    font-size: 12px;
  }

  .back-link {
    min-height: 32px;
    padding: 6px 11px;
  }

}

@media (prefers-reduced-motion: reduce) {
  body::after {
    background:
      linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.18) 50%),
      radial-gradient(circle at center, transparent 56%, rgba(0, 0, 0, 0.52));
  }
}
