:root {
  font-family: Arial, Helvetica, sans-serif;
  color: #153e35;
  background: #bce4df;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, select { font: inherit; }
main {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #bce4df;
}
.game { position: static; }

header {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) clamp(16px, 3vw, 48px) 14px;
  background: linear-gradient(to bottom, #f3f3dff5 0%, #f3f3dfd9 60%, #f3f3df00 100%);
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: inherit;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.5px;
  line-height: 1.12;
  text-decoration: none;
}
.mark { color: #f08b35; font-size: 42px; line-height: 1; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 2px; }
button {
  border: 1px solid #153e3540;
  border-radius: 24px;
  padding: 10px 17px;
  background: #fff9e5cc;
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
button:hover { background: #fff9e5; }
button:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible {
  outline: 3px solid #ec743d;
  outline-offset: 3px;
}
button[hidden] { display: none; }
#clear-pile { border-color: #ec743d; color: #975125; }
#fullscreen { width: 42px; height: 42px; padding: 0; font-size: 23px; line-height: 1; }
.settings-panel { position: relative; }
.settings-panel summary { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid #153e3540; border-radius: 50%; background: #fff9e5e8; cursor: pointer; font-size: 22px; list-style: none; }
.settings-panel summary::-webkit-details-marker { display: none; }
.settings-panel summary:focus-visible { outline: 3px solid #ec743d; outline-offset: 3px; }
.settings-menu { position: absolute; z-index: 10; top: calc(100% + 9px); right: 0; width: min(250px, calc(100vw - 24px)); max-height: min(70vh, 410px); overflow: auto; padding: 14px; border: 1px solid #153e3540; border-radius: 13px; background: #fff9e5f7; box-shadow: 0 8px 24px #153e3533; font-size: 13px; }
.settings-menu strong { display: block; margin-bottom: 9px; font-size: 15px; }
.settings-menu label { display: flex; align-items: center; gap: 8px; padding: 7px 0; cursor: pointer; white-space: normal; }
.settings-menu input { flex: 0 0 auto; accent-color: #153e35; }
.settings-menu small { display: block; color: #52665c; line-height: 1.4; }
.settings-divider { height: 1px; margin: 8px 0; background: #153e3533; }
.settings-menu .end-setting { color: #9b3b22; font-weight: 800; }
.world-ended .brand, .world-ended .time-panel, .world-ended #settings-panel, .world-ended #reset, .world-ended #fullscreen, .world-ended .topline, .world-ended .controls { display: none; }
.world-impacted .controls { opacity: 0; pointer-events: none; transition: opacity 1.2s ease; }
.world-ended header { justify-content: flex-end; background: transparent; }
.world-ended #clear-pile { background: #261c20d9; color: #ffdbc0; border-color: #ff875c; }

.court {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  background: #bce4df;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.court-label { display: none; }
.swarm-hud { position: absolute; z-index: 2; top: 27%; left: 50%; transform: translateX(-50%); display: grid; gap: 3px; min-width: 160px; padding: 8px 14px; border: 2px solid #6f2e27; border-radius: 13px; background: #fff3d9e8; color: #8d3025; text-align: center; pointer-events: none; box-shadow: 0 6px 16px #40221a40; }
.swarm-hud[hidden] { display: none; }
.swarm-hud strong { font-size: 12px; letter-spacing: 1.8px; }
.swarm-hud span { font-size: 12px; font-weight: 700; }
.world-ended .swarm-hud, .world-impacted .swarm-hud { display: none; }

.topline {
  position: absolute;
  z-index: 3;
  top: clamp(80px, 10vh, 106px);
  left: clamp(16px, 3vw, 48px);
  right: clamp(16px, 3vw, 48px);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  pointer-events: none;
}
h1 {
  margin: 9px 0 0;
  font-size: clamp(32px, 4.5vw, 64px);
  font-weight: 900;
  letter-spacing: -3px;
  line-height: 1;
}
h1 > span { color: #ec743d; }
.scores {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2vw, 28px);
  padding: 10px 16px;
  border: 1px solid #153e351b;
  border-radius: 18px;
  background: #fff9e5db;
}
.scores div { min-width: 54px; text-align: center; }
.scores strong { display: block; font-size: clamp(25px, 3vw, 36px); line-height: 1.05; }
.scores span { font-size: 10px; font-weight: bold; letter-spacing: 1.2px; }
.scores .bird-score { display: block; margin-top: 4px; color: #9b3b22; font-size: 9px; font-weight: 800; white-space: nowrap; }

.time-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 9px;
  border: 1px solid #153e3530;
  border-radius: 11px;
  background: #fff9e5e8;
  font-size: 11px;
}
.time-readout { display: grid; flex: 1 1 auto; min-width: 180px; gap: 1px; }
.time-readout strong { font-size: 11px; white-space: nowrap; }
.time-readout span { color: #52665c; font-size: 10px; white-space: nowrap; }
.time-speed { display: flex; align-items: center; flex: 0 0 auto; gap: 5px; }
.time-speed input { width: 88px; margin: 0; accent-color: #153e35; cursor: pointer; }
.time-speed output { min-width: 55px; font-size: 10px; font-weight: 700; text-align: right; white-space: nowrap; }
.history-panel { position: relative; font-weight: 700; }
.history-panel summary { cursor: pointer; white-space: nowrap; list-style: none; }
.history-panel summary::-webkit-details-marker { display: none; }
.history-panel summary::after { content: ' ▾'; }
.history-panel[open] summary::after { content: ' ▴'; }
.history-content {
  position: absolute;
  z-index: 8;
  top: calc(100% + 14px);
  right: -11px;
  width: min(300px, calc(100vw - 24px));
  max-height: min(50vh, 360px);
  overflow: auto;
  border: 1px solid #153e3540;
  border-radius: 12px;
  padding: 12px;
  background: #fff9e5f7;
  box-shadow: 0 8px 24px #153e3533;
  font-weight: 400;
  line-height: 1.45;
}
.history-content b { display: block; margin-top: 8px; }
.history-content b:first-child { margin-top: 0; }
.history-content p { margin: 3px 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.controls {
  position: absolute;
  z-index: 4;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 30px clamp(16px, 3vw, 48px) calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, #f3f3dff7 0%, #f3f3dfe6 52%, #f3f3df00 100%);
}
.instruction { display: flex; align-items: center; gap: 12px; }
.instruction-icon { font-size: 30px; }
.instruction b { font-size: 16px; }
.instruction small {
  display: block;
  margin-top: 5px;
  color: #52665c;
  font-size: 13px;
}
.aim-controls { display: flex; align-items: center; gap: 16px; }
.aim-controls label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  width: 105px;
  font-size: 13px;
  font-weight: bold;
}
.aim-controls input {
  grid-column: 1 / 3;
  order: 3;
  width: 100%;
  accent-color: #153e35;
}
.aim-controls button { border-color: #153e35; background: #153e35; color: #fff9e5; }
.aim-controls button:hover { background: #286457; }
footer { display: none; }

@media (max-width: 1100px) {
  .time-readout span { display: none; }
  .time-readout { min-width: 0; }
}

@media (max-width: 1000px) {
  .instruction small { max-width: 260px; }
  header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }
  .header-actions { grid-column: 2; grid-row: 1; }
  .time-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    max-width: 100%;
  }
  .topline { top: calc(114px + env(safe-area-inset-top)); }
}

@media (max-width: 700px) {
  header {
    padding: calc(7px + env(safe-area-inset-top)) 12px 11px;
  }
  .brand { gap: 7px; font-size: 11px; letter-spacing: 1px; }
  .mark { font-size: 34px; }
  .header-actions { grid-column: 2; grid-row: 1; gap: 5px; }
  header button { padding: 8px 9px; font-size: 11px; }
  #fullscreen { width: 34px; height: 34px; font-size: 20px; }
  .settings-panel summary { width: 34px; height: 34px; font-size: 19px; }
  .topline {
    top: calc(111px + env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
  }
  .eyebrow { font-size: 9px; letter-spacing: 1.2px; }
  h1 { margin-top: 5px; font-size: clamp(28px, 7vw, 42px); letter-spacing: -1.5px; }
  .scores { justify-content: space-between; gap: 6px; padding: 8px 10px; }
  .scores div { min-width: 0; }
  .scores strong { font-size: 24px; }
  .scores span { font-size: 9px; letter-spacing: .8px; }
  .time-panel {
    width: max-content;
    gap: 5px;
    padding: 4px 7px;
    font-size: 10px;
  }
  .time-readout { min-width: 0; overflow: hidden; }
  .time-readout strong { overflow: hidden; text-overflow: ellipsis; font-size: 10px; }
  .time-speed input { width: 78px; }
  .history-panel { font-size: 10px; }
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 28px 12px calc(12px + env(safe-area-inset-bottom));
  }
  .instruction-icon { font-size: 24px; }
  .instruction b { font-size: 13px; }
  .instruction small { display: none; }
  .aim-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    width: 100%;
  }
  .aim-controls label { width: auto; min-width: 0; }
  .aim-controls button { padding: 11px 12px; font-size: 13px; }
}

@media (max-width: 360px) {
  .aim-controls { gap: 7px; }
  .aim-controls button { padding-inline: 9px; }
  .time-speed input { width: 68px; }
  .time-speed output { min-width: 50px; }
}

@media (max-width: 480px) {
  .brand span:last-child { display: none; }
}

@media (max-height: 560px) {
  header { padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 13px; }
  .brand { font-size: 10px; }
  .mark { font-size: 30px; }
  .topline {
    top: calc(62px + env(safe-area-inset-top));
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }
  .eyebrow, .instruction { display: none; }
  h1 { margin: 0; font-size: clamp(22px, 3vw, 34px); letter-spacing: -1px; }
  .scores { gap: 9px; padding: 5px 9px; }
  .scores strong { font-size: 19px; }
  .scores span { font-size: 8px; }
  .time-panel { padding: 3px 7px; }
  .time-readout strong { font-size: 10px; }
  .time-speed input { width: 78px; }
  .controls { padding-top: 20px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .aim-controls { margin-left: auto; }
}

@media (max-width: 1000px) and (max-height: 560px) {
  .topline { top: calc(96px + env(safe-area-inset-top)); }
}
