:root {
  --blood: #b00000;
  --blood-glow: #ff1a1a;
  --rust: #3b1a10;
  --bone: #d8d0bd;
  --phosphor: #7cff8c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 20%, #1c0d0a 0%, #080505 55%, #020202 100%);
  color: var(--bone);
  font-family: 'Oswald', sans-serif;
  overflow-x: hidden;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

.grain, .vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.grain {
  opacity: 0.12;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.6s steps(4) infinite;
}

.vignette {
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.9) 100%);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse at 20% 30%, rgba(180, 0, 0, 0.08), transparent 50%);
  animation: lightFlicker 5s infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3%, 2%); }
  50% { transform: translate(2%, -3%); }
  75% { transform: translate(-2%, -1%); }
  100% { transform: translate(0, 0); }
}

@keyframes lightFlicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.3; }
  94% { opacity: 1; }
  96% { opacity: 0.5; }
}

.hud {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 260px 1fr 440px;
  align-items: start;
  gap: 16px;
  padding: 18px 28px 0;
}

.gauge-wrap canvas {
  width: 240px;
  height: 240px;
  display: block;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.8));
}

.timer-wrap {
  text-align: center;
  padding-top: 8px;
}

.timer-label {
  font-family: 'Special Elite', cursive;
  color: #8a1f1f;
  letter-spacing: 3px;
  font-size: 14px;
  margin-bottom: 8px;
}

.timer-panel {
  display: inline-block;
  padding: 10px 26px 4px;
  background: linear-gradient(#0d0000, #030000);
  border: 2px solid #3a0000;
  border-radius: 10px;
  box-shadow: inset 0 0 30px rgba(255, 0, 0, 0.18), 0 0 25px rgba(120, 0, 0, 0.5);
}

.timer {
  font-family: 'Share Tech Mono', monospace;
  font-size: 96px;
  line-height: 1;
  color: var(--blood-glow);
  text-shadow: 0 0 4px #ff0000, 0 0 16px #ff0000, 0 0 40px #8a0000;
  letter-spacing: 4px;
  font-variant-numeric: tabular-nums;
}

.timer.danger { animation: pulse 0.9s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.tv {
  justify-self: end;
  width: 440px;
  padding: 16px 16px 12px;
  background: linear-gradient(160deg, #4a3a2c, #241b14 60%, #171109);
  border-radius: 18px 18px 26px 26px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08), 0 14px 30px rgba(0, 0, 0, 0.8);
  border: 1px solid #0a0704;
}

.tv-screen {
  position: relative;
  height: 230px;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #123a1a 0%, #06170b 75%, #020703 100%);
  border-radius: 46% 46% 42% 42% / 8% 8% 10% 10%;
  box-shadow: inset 0 0 40px #000, inset 0 0 6px rgba(124, 255, 140, 0.3);
  font-family: 'VT323', monospace;
  color: var(--phosphor);
  text-shadow: 0 0 5px rgba(124, 255, 140, 0.8);
  animation: tvFlicker 3.5s infinite;
}

.tv-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px);
}

.tv-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.12), transparent 45%);
}

@keyframes tvFlicker {
  0%, 100% { filter: brightness(1); }
  47% { filter: brightness(1); }
  48% { filter: brightness(0.82); }
  50% { filter: brightness(1.06); }
  52% { filter: brightness(0.9); }
}

.tv-title {
  font-size: 20px;
  text-align: center;
  letter-spacing: 2px;
  border-bottom: 1px dashed rgba(124, 255, 140, 0.4);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.tv-live {
  font-size: 19px;
  min-height: 22px;
  color: #ffd27a;
  text-shadow: 0 0 6px rgba(255, 180, 60, 0.7);
}

#history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #7cff8c transparent;
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  font-size: 19px;
  line-height: 1.25;
}

#history li { white-space: nowrap; }
#history .h-time { opacity: 0.6; }
#history .h-name { color: #fff; text-shadow: 0 0 6px rgba(255, 255, 255, 0.6); }

.tv-empty {
  display: none;
  text-align: center;
  font-size: 22px;
  margin-top: 40px;
  animation: blink 1.2s steps(2) infinite;
}

.tv-empty.show { display: block; }

@keyframes blink { 50% { opacity: 0; } }

.tv-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-right: 8px;
}

.tv-controls .led {
  width: 8px; height: 8px; border-radius: 50%;
  background: #ff3a1a; box-shadow: 0 0 8px #ff3a1a;
}

.tv-controls i {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #666, #111);
  box-shadow: 0 1px 2px #000;
}

.pipes {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#tanks {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 48px 56px;
  padding: 60px 40px 110px;
}

.tank {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 150px;
  transition: transform 0.4s ease;
}

.tank.active { transform: translateY(-10px); }

.inlet {
  width: 34px;
  height: 22px;
  background: linear-gradient(90deg, #2a2a2a, #7a7a7a 50%, #2a2a2a);
  border-radius: 6px 6px 0 0;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.7);
  margin-bottom: -2px;
  position: relative;
  z-index: 2;
}

.inlet::after {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  top: 0;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(#999, #333);
}

.glass {
  position: relative;
  width: 150px;
  height: 330px;
  overflow: hidden;
  border: 3px solid rgba(200, 235, 220, 0.28);
  border-top: 3px solid rgba(200, 235, 220, 0.12);
  border-radius: 16px 16px 30px 30px / 12px 12px 30px 30px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02) 40%, rgba(255, 255, 255, 0.1));
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.85), 0 0 18px rgba(0, 0, 0, 0.9);
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

.glass canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.glass .shine {
  position: absolute;
  top: 14px;
  bottom: 22px;
  left: 14px;
  width: 12px;
  border-radius: 8px;
  background: linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.05));
  z-index: 3;
}

.glass .marks {
  position: absolute;
  top: 30px;
  bottom: 14px;
  right: 8px;
  width: 14px;
  z-index: 3;
  background: repeating-linear-gradient(to bottom, rgba(220, 240, 230, 0.35) 0 1px, transparent 1px 28px);
  border-right: 1px solid rgba(220, 240, 230, 0.25);
}

.tank.active .glass {
  border-color: rgba(124, 255, 140, 0.6);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.85), 0 0 26px rgba(124, 255, 140, 0.35);
}

.tank-name {
  margin-top: 14px;
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #e6e0d0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tank.active .tank-name { color: #ff4a3a; text-shadow: 0 0 10px rgba(255, 0, 0, 0.6); }

.tank-score {
  white-space: nowrap;
  font-family: 'VT323', monospace;
  font-size: 40px;
  line-height: 1;
  color: var(--phosphor);
  text-shadow: 0 0 8px rgba(124, 255, 140, 0.6);
}

.tank-tag {
  height: 16px;
  font-family: 'Special Elite', cursive;
  font-size: 13px;
  letter-spacing: 2px;
  color: #8a1f1f;
}

.tank-tag.me { color: #c9a227; }

.pipe-outline { fill: none; stroke: #0a0908; stroke-width: 24; stroke-linecap: round; }
.pipe-metal { fill: none; stroke: url(#pipeMetal); stroke-width: 16; stroke-linecap: round; }
.pipe-rings { fill: none; stroke: #2b2622; stroke-width: 19; stroke-linecap: butt; stroke-dasharray: 2 34; }
.pipe-gas { fill: none; stroke: #8dff5a; stroke-width: 6; stroke-linecap: round; stroke-dasharray: 3 22; filter: drop-shadow(0 0 5px #5dff3a); }
.pipe-joint { fill: #1d1a17; stroke: #7a7064; stroke-width: 3; }

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  font-family: 'Special Elite', cursive;
  font-size: 14px;
  color: #6b2a2a;
}

.footer-quote { letter-spacing: 1px; }

.sensor-status { letter-spacing: 2px; font-size: 12px; color: #444; }
.sensor-status.online { color: #4cff6a; text-shadow: 0 0 6px #2dff4a; }

.link-btn, .btn {
  font-family: 'Special Elite', cursive;
  cursor: pointer;
  border: 1px solid #5a0000;
  color: #e8dcc0;
  background: transparent;
  padding: 8px 14px;
  letter-spacing: 1px;
  transition: background 0.2s, color 0.2s;
}

.link-btn:hover, .btn:hover { background: #5a0000; color: #fff; }

.btn { background: #6e0000; }

.flash {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  text-align: center;
  font-family: 'Special Elite', cursive;
  font-size: 46px;
  color: #ff2a2a;
  text-shadow: 0 0 18px #ff0000, 0 0 40px #600000;
  letter-spacing: 4px;
}

.flash small {
  display: block;
  font-family: 'VT323', monospace;
  font-size: 28px;
  color: #ffd0c0;
  letter-spacing: 2px;
}

.flash.show { animation: flash 3.2s ease-out; }

@keyframes flash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.3); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

body.alarm::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  box-shadow: inset 0 0 160px rgba(255, 0, 0, 0.35);
  animation: pulse 1.2s infinite;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.94);
}

.overlay[hidden] { display: none; }

.panel {
  width: min(540px, 92vw);
  padding: 34px 36px;
  background: linear-gradient(#150505, #050101);
  border: 1px solid #5a0000;
  box-shadow: 0 0 70px rgba(180, 0, 0, 0.3);
}

.quote {
  font-family: 'Special Elite', cursive;
  color: #8a1f1f;
  text-align: center;
  margin: 0 0 6px;
}

.panel h1 {
  margin: 0 0 18px;
  text-align: center;
  font-size: 40px;
  letter-spacing: 4px;
  color: var(--blood-glow);
  text-shadow: 0 0 14px rgba(255, 0, 0, 0.5);
}

.panel h2 {
  margin: 26px 0 10px;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 2px;
  color: #8a7a6a;
  text-transform: uppercase;
}

.panel label {
  display: block;
  margin-bottom: 8px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 14px;
}

.row { display: flex; gap: 10px; }

#pseudo {
  flex: 1;
  padding: 10px 6px;
  font-family: 'Special Elite', cursive;
  font-size: 20px;
  color: #f0e6d0;
  background: transparent;
  border: none;
  border-bottom: 2px solid #6e0000;
  outline: none;
}

#pseudo:focus { border-color: var(--blood-glow); box-shadow: 0 6px 14px -8px rgba(255, 0, 0, 0.6); }

.error { min-height: 20px; color: #ff5a5a; font-size: 14px; margin: 8px 0 0; }

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.player-btn {
  font-family: 'Oswald', sans-serif;
  letter-spacing: 1px;
  color: #e8dcc0;
  background: #120707;
  border: 1px solid #3a1010;
  padding: 8px 12px;
  cursor: pointer;
  text-transform: uppercase;
}

.player-btn span { color: var(--phosphor); font-family: 'VT323', monospace; font-size: 18px; margin-left: 6px; }
.player-btn:hover { border-color: var(--blood-glow); color: #fff; }

.empty { color: #6a5a4a; font-family: 'Special Elite', cursive; font-size: 14px; }

@media (max-width: 640px) {
  .hud {
    grid-template-columns: 120px 1fr 150px;
    gap: 6px;
    padding: 10px 8px 0;
  }
  .gauge-wrap canvas { width: 120px; height: 120px; }
  .timer-wrap { padding-top: 0; }
  .timer-label { font-size: 9px; letter-spacing: 1px; margin-bottom: 4px; }
  .timer-panel { padding: 4px 8px 0; border-radius: 6px; }
  .timer { font-size: 44px; letter-spacing: 2px; }
  .tv { width: 150px; padding: 8px 8px 6px; border-radius: 10px 10px 14px 14px; }
  .tv-screen { height: 120px; padding: 6px 8px; }
  .tv-title { font-size: 12px; padding-bottom: 2px; margin-bottom: 3px; }
  .tv-live { font-size: 12px; min-height: 14px; }
  #history { font-size: 13px; line-height: 1.2; }
  .tv-empty { font-size: 14px; margin-top: 20px; }
  .tv-controls { margin-top: 4px; }
  .tv-controls .led { width: 5px; height: 5px; }
  .tv-controls i { width: 10px; height: 10px; }
  #tanks {
    zoom: 0.5;
    gap: 24px 22px;
    padding: 30px 10px 70px;
  }
  .footer { padding: 6px 10px; font-size: 10px; gap: 8px; }
  .footer-quote { display: none; }
  .link-btn { padding: 5px 8px; font-size: 11px; }
  .sensor-status { font-size: 10px; }
  .flash { font-size: 26px; }
  .flash small { font-size: 18px; }
  .panel { padding: 20px; }
  .panel h1 { font-size: 28px; }
}

body.admin { display: block; }

.admin-wrap {
  position: relative;
  z-index: 3;
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 18px 60px;
  width: 100%;
}

.admin-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.admin-head h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 3px;
  color: var(--blood-glow);
  text-shadow: 0 0 12px rgba(255, 0, 0, 0.4);
}

.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-actions a { text-decoration: none; }

.card {
  margin-bottom: 18px;
  padding: 18px 20px;
  background: linear-gradient(#150505, #060202);
  border: 1px solid #4a0000;
  box-shadow: 0 0 30px rgba(120, 0, 0, 0.2);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #d8c9a8;
}

.muted { color: #8a7a6a; margin: 0 0 10px; font-family: 'Special Elite', cursive; }

.input {
  flex: 1;
  padding: 8px 10px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 16px;
  color: #f0e6d0;
  background: #0a0404;
  border: 1px solid #5a0000;
  color-scheme: dark;
}

.btn.danger { background: #3a0000; padding: 5px 10px; font-size: 13px; }

.notice { min-height: 22px; margin-bottom: 10px; color: #7cff8c; font-family: 'Special Elite', cursive; }
.notice.bad { color: #ff5a5a; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.admin-table th, .admin-table td { padding: 7px 8px; border-bottom: 1px solid #2a0c0c; text-align: left; }
.admin-table th { font-family: 'Special Elite', cursive; font-weight: 400; color: #8a4a4a; letter-spacing: 1px; }
.admin-table td.num { font-family: 'VT323', monospace; font-size: 20px; color: var(--phosphor); }
.admin-table td.strong { color: #f0e6d0; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.admin-table td.empty { color: #6a5a4a; font-family: 'Special Elite', cursive; }

@media (max-width: 640px) {
  .admin-table { font-size: 13px; }
  .admin-table th, .admin-table td { padding: 5px 4px; }
}
