:root {
  color-scheme: dark;
  --bg: #07090d;
  --text: #e8eef5;
  --accent: #39e0c2;
  --accent2: #ffb347;
  --title-desktop: 48px;
  --title-mobile: 28px;
  --title-align: center;
  --joy-size: 150px;
  --joy-justify: center;
  --panel: rgba(16, 22, 30, 0.82);
  --line: rgba(255, 255, 255, 0.09);
  --muted: color-mix(in srgb, var(--text) 62%, transparent);
  --brand: linear-gradient(100deg, var(--accent), var(--accent2));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background:
    radial-gradient(900px 520px at 12% -8%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(800px 500px at 96% 108%, color-mix(in srgb, var(--accent2) 12%, transparent), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.micro {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.page {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  height: 100dvh;
  max-width: 1500px;
  margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.section-title { flex: none; text-align: var(--title-align); }

#site-title {
  margin: 0;
  font-size: var(--title-desktop);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.02em;
  background: var(--brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  overflow-wrap: anywhere;
}

#site-tagline { margin: 4px 0 0; color: var(--muted); font-size: 15px; }

.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #0d1219;
}

#game { display: block; width: 100%; height: 100%; touch-action: none; }

/* HUD */
.hud { position: absolute; inset: 0; padding: 12px; pointer-events: none; }
.hud-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.vitals { display: grid; gap: 6px; min-width: 0; }
.vital { display: grid; gap: 3px; }
.vital-name {
  max-width: 180px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px #000;
}
.bar {
  display: block;
  width: min(180px, 34vw);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  background: var(--brand);
  transform-origin: left;
}
.bar-ally { background: #7be08a; }
.bar-boss { background: linear-gradient(90deg, #ff4d5e, #ff9a4d); }
.bar-wide { width: 100%; height: 10px; }

.stats { display: flex; align-items: center; gap: 12px; flex: none; }
.stat { display: inline-flex; align-items: baseline; gap: 5px; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px #000; }

.icon-btn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.icon-btn svg { width: 14px; height: 14px; fill: currentColor; }

.boss-vital { max-width: 420px; margin: 8px auto 0; text-align: center; }
.boss-name { display: block; margin-bottom: 3px; font-size: 13px; font-weight: 800; text-shadow: 0 1px 3px #000; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
}

/* Start, pause and end screens */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow-y: auto;
  background: rgba(5, 8, 12, 0.62);
  backdrop-filter: blur(3px);
}

.card {
  width: min(520px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  text-align: center;
}
.card h2 { margin: 0 0 6px; font-size: 22px; overflow-wrap: anywhere; }
.overlay-text { margin: 0 0 14px; color: var(--muted); font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }

.roster {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 16px;
}
.roster-item { display: grid; justify-items: center; gap: 3px; min-width: 0; }
.roster-item canvas { width: 46px; height: 46px; }
.roster-name {
  width: 100%;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

.primary {
  min-width: 170px;
  min-height: 46px;
  padding: 10px 26px;
  border: 0;
  border-radius: 14px;
  background: var(--brand);
  color: #06100e;
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.primary:focus-visible, .icon-btn:focus-visible, .admin-link:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.controls-hint { margin: 12px 0 0; }

.admin-link {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 6px;
  text-decoration: none;
}

/* Joystick: only on phones and tablets */
.joy-panel {
  display: none;
  flex: none;
  justify-content: var(--joy-justify);
  align-items: center;
}

.joy {
  position: relative;
  width: var(--joy-size);
  height: var(--joy-size);
  border: 1px solid var(--line);
  border-radius: 50%;
  background:
    radial-gradient(circle, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    var(--panel);
  touch-action: none;
  cursor: grab;
}

.joy-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 42%;
  height: 42%;
  margin: -21% 0 0 -21%;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

body[data-layout="mobile"] .page { gap: 10px; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
body[data-layout="mobile"] #site-title { font-size: var(--title-mobile); }
body[data-layout="mobile"] #site-tagline { font-size: 13px; margin-top: 2px; }
body[data-layout="mobile"] .joy-panel { display: flex; }
body[data-layout="mobile"] .roster-item canvas { width: 36px; height: 36px; }
body[data-layout="mobile"] .card { padding: 14px; }
body[data-layout="mobile"] .card h2 { font-size: 18px; }
body[data-layout="mobile"] .overlay-text { font-size: 14px; margin-bottom: 10px; }
body[data-layout="mobile"] .roster { margin-bottom: 10px; }
body[data-layout="mobile"] .controls-hint { display: none; }

/* A phone held sideways has no height to spare: the joystick moves beside the game. */
@media (orientation: landscape) and (max-height: 560px) {
  body[data-layout="mobile"] .page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px 12px;
  }
  body[data-layout="mobile"] .section-title { grid-column: 1 / -1; grid-row: 1; }
  body[data-layout="mobile"] #site-title { font-size: min(var(--title-mobile), 20px); }
  body[data-layout="mobile"] #site-tagline { display: none; }
  body[data-layout="mobile"] .stage { grid-column: 1; grid-row: 2; }
  body[data-layout="mobile"] .joy-panel { grid-column: 2; grid-row: 2; }
  body[data-layout="mobile"] .roster { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay { backdrop-filter: none; }
}
