:root {
  color-scheme: dark;
  font: 1rem system-ui, sans-serif;
  background: #333;
  color: #f4eeee;
}

*, *::before, *::after { box-sizing: border-box; }

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

header {
  border-bottom: 1px solid #6c7d8f;
  padding: .75rem 1rem;
  text-align: center;
}

h1 { margin: 0; font-size: clamp(1.4rem, 6vw, 2rem); }
h2 { margin: 0 0 1rem; }
h2 small { font-size: .75rem; text-transform: uppercase; }

main {
  width: 100%;
  max-width: 38rem;
  margin-inline: auto;
  padding: clamp(1rem, 4vw, 2rem);
  text-align: center;
}

main:has(#home:not([hidden])),
main:has(#instructor:not([hidden])) { margin-block: auto; }

button, input { font: inherit; }

button {
  background: #245fb0;
  color: white;
  border: 1px solid #a3b5c9;
  border-radius: 5px;
  min-height: 48px;
  padding: .6rem 1rem;
  margin: .35rem;
  cursor: pointer;
}

button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
button.green { background: #72d813; color: #262626; }
input { width: 7ch; min-height: 48px; padding: .6rem; text-align: center; }
label { display: block; margin: .6rem; }
ul { list-style: none; padding: 0; }
#back { margin-top: 1rem; }

body:has(#dea:not([hidden])) > header { display: none; }

main:has(#dea:not([hidden])) {
  display: flex;
  flex: 1;
  flex-direction: column;
  max-width: none;
  padding: 0;
}

#dea {
  flex: 1;
  padding: clamp(.875rem, 4vw, 1.5rem);
  background: #55575b;
}

.dea-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: .375rem;
  margin-bottom: .75rem;
}

#dea-back {
  justify-self: start;
  width: 48px;
  padding: 0;
  margin: 0;
  background: #3d3f43;
  border-color: #a7a9ae;
  font-size: 1.65rem;
  line-height: 1;
}

.dea-heading h2 {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  font-size: clamp(1rem, 5.2vw, 1.5rem);
}

#dea-mode {
  grid-column: 1 / -1;
  color: #fff;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 800;
  line-height: 1.1;
}

.screen {
  position: relative;
  display: grid;
  align-content: center;
  gap: .75rem;
  background: #101b24;
  min-height: 8.5rem;
  padding: 1rem;
  color: #a8edff;
  font-size: clamp(1.125rem, 2.5vw, 1.375rem);
  text-shadow: 0 0 .4rem #47d6ff55;
  overflow-wrap: anywhere;
}

#dea .screen:has(#instruction:not(:empty)) {
  padding-top: 2rem;
}

.screen:has(#instruction:not(:empty)) #dea-status {
  position: absolute;
  top: .65rem;
  right: .75rem;
  font-size: .875rem;
  line-height: 1.2;
  text-align: right;
}

#metronome-progress {
  --remaining-color: #00c853;
  appearance: none;
  justify-self: center;
  width: min(85%, 24rem);
  height: .55rem;
  border: 0;
  border-radius: 1rem;
  background: #39443d;
  overflow: hidden;
}

#metronome-progress[data-level="warning"] { --remaining-color: #ffd600; }
#metronome-progress[data-level="low"] { --remaining-color: #ff4040; }
#metronome-progress::-webkit-progress-bar { background: #39443d; }
#metronome-progress::-webkit-progress-value { background: var(--remaining-color); }
#metronome-progress::-moz-progress-bar { background: var(--remaining-color); }

.screen p { margin: 0; }
.screen p:empty { display: none; }
#dea-code { font-size: clamp(1rem, 5vw, 1.25rem); font-weight: bold; }

.device-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  gap: .75rem;
  margin-top: 1.25rem;
}

.device-controls:has(#shock-control[hidden]) { grid-template-columns: 1fr; }

.device-controls span {
  display: block;
  margin-top: .5rem;
  font-size: .9rem;
  line-height: 1.2;
}

.device-controls button {
  display: inline-grid;
  place-items: center;
  width: clamp(3.5rem, 18vw, 5rem);
  height: clamp(3.5rem, 18vw, 5rem);
  padding: 0;
  margin: 0;
  font-size: 2rem;
}

.power { background: #a51a25; border-radius: 50%; }
.power[aria-pressed="true"] {
  background: #ed2336;
  border-color: #ffb4ba;
  box-shadow: 0 0 1rem #ff334bcc;
}

.device-controls .shock {
  position: relative;
  isolation: isolate;
  background: transparent;
  border: 0;
  padding-top: 1.1rem;
  color: #eee;
}

.shock::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #a74a09;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

.shock:enabled {
  color: #261806;
  filter: drop-shadow(0 0 .6rem #ff951f);
  animation: glow 1.3s ease-in-out infinite;
}

.shock:enabled::before { background: #ff951f; }
@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 .15rem #ff951f) brightness(.82); }
  50% { filter: drop-shadow(0 0 .9rem #ff951f) brightness(1.35); }
}

@media (max-width: 480px) {
  #home button, #instructor button:not(#pair button):not([hidden]), #back:not([hidden]) {
    display: block;
    width: 100%;
    margin: .65rem 0;
  }

  #home button + button { margin-top: 1.35rem; }

  #instructor-status { overflow-wrap: anywhere; }
}


@media (orientation: landscape) and (max-height: 540px) and (min-width: 480px) {
  #dea:not([hidden]) {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(6rem, 1fr);
    align-items: center;
    gap: .625rem 1rem;
    padding: clamp(.75rem, 3dvh, 1.125rem);
  }

  .dea-heading { grid-column: 1 / -1; margin: 0; }
  #dea .screen { align-self: stretch; gap: .375rem; padding: .5rem; }
  #dea .device-controls { margin: 0; row-gap: clamp(.75rem, 5dvh, 1.5rem); }
  #dea .device-controls button { width: clamp(3.75rem, 19dvh, 5.5rem); height: clamp(3.75rem, 19dvh, 5.5rem); }
}

@media (prefers-reduced-motion: reduce) {
  .shock:enabled { animation: none; }
}