:root {
  color-scheme: dark;
  --ink: #f7f5ef;
  --muted: rgba(247, 245, 239, 0.72);
  --panel: rgba(13, 18, 24, 0.72);
  --panel-strong: rgba(18, 25, 32, 0.88);
  --line: rgba(255, 255, 255, 0.17);
  --gold: #f5c84b;
  --coral: #e85b3f;
  --green: #69cf8c;
  --blue: #63c8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(ellipse at 50% 20%, #204c54 0%, #102e3a 42%, #07151e 100%);
  color: var(--ink);
}

button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  letter-spacing: 0;
  padding: 10px 14px;
  min-width: 84px;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.22);
}

button:hover {
  border-color: rgba(255, 255, 255, 0.36);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 14px;
}

.stage-wrap {
  position: relative;
  width: min(100vw - 28px, calc((100vh - 28px) * 1.6));
  aspect-ratio: 1280 / 800;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #050505;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.hud-item {
  position: absolute;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.58);
}

.hud-item span {
  display: block;
  color: rgba(255, 248, 240, 0.82);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1;
}

.hud-item strong {
  display: block;
  margin-top: 3px;
  font-size: 1.15rem;
  line-height: 1.1;
}

.hud-item:nth-child(1) {
  left: 26px;
  top: 18px;
  width: 380px;
}

.hud-item:nth-child(1) span {
  display: none;
}

.hud-item:nth-child(1) strong {
  color: #fff3be;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 3vw, 2.15rem);
  font-weight: 800;
}

.hud-item:nth-child(2) {
  right: 24px;
  top: 18px;
  width: 128px;
  height: 128px;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 50%;
  border: 4px solid rgba(232, 197, 96, 0.95);
  background: rgba(255, 246, 211, 0.96);
  box-shadow: 0 10px 28px rgba(54, 30, 11, 0.26);
  text-shadow: none;
}

.hud-item:nth-child(2) span {
  color: #914f1a;
  font-size: 0.62rem;
}

.hud-item:nth-child(2) strong {
  color: #914f1a;
  font-size: 1.05rem;
  max-width: 104px;
}

.hud-item:nth-child(3) {
  right: 164px;
  top: 18px;
  width: 290px;
  text-align: right;
}

.hud-item:nth-child(3) strong {
  color: #fff8f0;
  font-size: 1rem;
}

.hud-item:nth-child(4) {
  left: 126px;
  top: 8px;
  width: 170px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 247, 215, 0.24);
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 120ms ease, transform 120ms ease;
}

.hud-item:nth-child(4).is-active {
  opacity: 1;
  transform: scale(1);
}

.hud-item:nth-child(4) span {
  display: none;
}

.hud-item:nth-child(4) strong {
  color: #f8fcff;
  font-size: 1.65rem;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.hud-item:nth-child(5) {
  right: 18px;
  top: 148px;
  width: 140px;
  text-align: center;
}

.hud-item:nth-child(5) strong {
  color: #fff8f0;
  font-size: 1rem;
}

.top-actions {
  position: absolute;
  top: auto;
  bottom: 18px;
  right: 12px;
  display: flex;
  gap: 8px;
  transition: opacity 160ms ease;
}

.duck-test-control {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid #a8bdb0;
  border-radius: 5px;
  background: #193c34;
  color: #fff0ce;
  font: 600 12px system-ui, sans-serif;
}

.duck-test-control[hidden] { display: none; }

.master-volume {
  position: absolute;
  z-index: 30;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto minmax(64px, 1fr) 3.5ch;
  align-items: center;
  gap: 8px;
  width: min(250px, calc(100% - 28px));
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid rgba(241, 209, 138, .54);
  border-radius: 8px;
  background: rgba(10, 35, 44, .92);
  color: #fff4d5;
  font-size: 12px;
  font-weight: 650;
  pointer-events: auto;
}

.stage-wrap:has(.touch-controls:not([hidden])) .master-volume {
  bottom: max(72px, env(safe-area-inset-bottom));
}

.master-volume label,
.master-volume output {
  white-space: nowrap;
}

.master-volume output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.master-volume input {
  width: 100%;
  min-width: 0;
  height: 26px;
  margin: 0;
  accent-color: #f1d18a;
  cursor: pointer;
  touch-action: pan-y;
}

.master-volume input:focus-visible {
  outline: 3px solid #ffdc76;
  outline-offset: 3px;
  border-radius: 4px;
}

.stage-wrap.is-loading .master-volume,
.stage-wrap.is-loading:has(.touch-controls:not([hidden])) .master-volume {
  top: max(14px, env(safe-area-inset-top));
  bottom: auto;
}

.stage-wrap.is-title .hud,
.stage-wrap.is-title .top-actions,
.stage-wrap.is-loading .hud,
.stage-wrap.is-loading .top-actions,
.stage-wrap.is-demo .top-actions {
  opacity: 0;
  pointer-events: none;
}

.screen-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 13, 4, 0.05);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.screen-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.screen-panel {
  width: min(560px, 94%);
  text-align: center;
  padding: 24px 26px 22px;
  border-radius: 8px;
  border: 1px solid rgba(126, 77, 34, 0.24);
  background:
    linear-gradient(180deg, rgba(255, 250, 237, 0.96), rgba(246, 232, 210, 0.94));
  box-shadow: 0 20px 52px rgba(49, 25, 8, 0.22);
  color: #4c2b12;
}

.screen-panel p,
.screen-panel h1 {
  margin: 0;
}

#overlayKicker {
  color: #8f2e19;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#overlayTitle {
  margin-top: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4.5vw, 3.2rem);
  line-height: 1.02;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.84);
}

#overlayBody {
  margin: 14px auto 0;
  max-width: 46ch;
  color: #5e3a20;
  line-height: 1.48;
}

#overlayStats {
  min-height: 1.45em;
  margin-top: 12px;
  color: #8f2e19;
  font-weight: 800;
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

#primaryButton,
#startButton {
  background: linear-gradient(180deg, #f0b548, #c5422e);
  border-color: rgba(255, 236, 164, 0.42);
}

.screen-panel button {
  min-width: 132px;
  color: #4c2b12;
  background: linear-gradient(180deg, #fffaf0, #f1dfc4);
  border-color: rgba(132, 82, 38, 0.26);
  box-shadow: 0 10px 18px rgba(94, 58, 32, 0.14);
}

.screen-panel #primaryButton {
  color: #fff8ee;
  background: linear-gradient(180deg, #ef8e41, #c64f32);
  border-color: rgba(143, 46, 25, 0.32);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 14px);
  max-width: min(760px, 88%);
  min-width: 220px;
  padding: 11px 18px;
  border-radius: 8px;
  background: rgba(9, 12, 16, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--ink);
  text-align: center;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .game-shell {
    padding: 8px;
  }

  .stage-wrap {
    width: calc(100vw - 16px);
  }

  .master-volume {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: min(185px, calc(50% - 16px));
    min-height: 36px;
    grid-template-columns: auto minmax(40px, 1fr) 3.5ch;
    gap: 6px;
    padding: 4px 7px;
    font-size: 11px;
  }

  .stage-wrap:has(.touch-controls:not([hidden])) .master-volume {
    bottom: max(58px, env(safe-area-inset-bottom));
  }

  .hud {
    inset: 0;
  }

  .hud-item {
    transform-origin: top left;
  }

  .hud-item:nth-child(1) {
    left: 12px;
    top: 60px;
    width: 260px;
  }

  .hud-item:nth-child(1) strong {
    font-size: 1.22rem;
  }

  .hud-item:nth-child(2) {
    right: 12px;
    top: 58px;
    width: 86px;
    height: 86px;
  }

  .hud-item:nth-child(2) strong {
    font-size: 0.78rem;
  }

  .hud-item:nth-child(3) {
    right: 108px;
    top: 62px;
    width: 170px;
  }

  .hud-item:nth-child(5) {
    right: 12px;
    top: 150px;
    width: 90px;
  }

  .top-actions {
    left: 12px;
    right: 12px;
    bottom: 12px;
    justify-content: flex-end;
  }

  button {
    min-width: 0;
    padding: 9px 11px;
  }
}
