:root {
  color-scheme: dark;
  font-family: "Courier New", Courier, monospace;
  background: #050806;
  color: #d9ffd8;
  --green: #72ff78;
  --amber: #ffb33b;
  --cyan: #63efff;
  --panel: #0a100c;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 30%, rgba(59, 126, 67, 0.16), transparent 40%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 5px),
    #050806;
}

.cabinet {
  width: min(100%, 1040px);
  text-align: center;
}

.masthead { margin-bottom: 14px; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--amber);
  font-size: clamp(10px, 1.6vw, 14px);
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--green);
  font-size: clamp(28px, 6vw, 58px);
  line-height: 1;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(114, 255, 120, .35);
}

.screen-shell {
  position: relative;
  width: min(100%, calc((100vh - 245px) * 1.4583), 980px);
  margin: 0 auto;
  border: 5px solid #1d2b21;
  border-radius: 10px;
  background: #020403;
  box-shadow: 0 0 0 2px #080d09, 0 16px 55px rgba(0,0,0,.65), inset 0 0 22px #000;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 280 / 192;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--cyan); }

.screen-glow {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.11) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 16px auto 12px;
  color: #aac5ae;
  font-size: 12px;
  text-transform: uppercase;
}

.controls p { margin: 0; display: flex; align-items: center; gap: 4px; }
.controls span { margin-left: 4px; }

kbd {
  min-width: 23px;
  padding: 3px 6px;
  border: 1px solid #405846;
  border-bottom-width: 3px;
  border-radius: 3px;
  background: #111a13;
  color: var(--green);
  font: inherit;
}

#start-button {
  padding: 10px 20px;
  border: 1px solid var(--green);
  background: #0c180e;
  color: var(--green);
  font: bold 14px/1 "Courier New", monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}

#start-button:hover, #start-button:focus-visible { background: var(--green); color: #071008; }
.hint { min-height: 1em; margin: 10px 0 0; color: #718a75; font-size: 12px; }

.touch-controls {
  display: none;
  width: min(100%, 680px);
  margin: 12px auto;
  gap: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-row,
.touch-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.touch-row { justify-content: space-between; }
.movement-controls { flex: 1; }
.throw-controls { flex: 1; }

.touch-button {
  min-width: 48px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid #405846;
  border-bottom-width: 4px;
  border-radius: 6px;
  background: #111a13;
  color: var(--green);
  font: bold 12px/1.1 "Courier New", monospace;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: none;
}

.touch-button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.touch-button:active,
.touch-button.is-held { transform: translateY(2px); border-bottom-width: 2px; background: #1b3020; }
.touch-button[aria-pressed="true"] { border-color: var(--amber); background: #30230d; color: var(--amber); }
.touch-button:disabled { cursor: default; opacity: .38; transform: none; }
.direction-button { flex: 1; font-size: 20px; }
.throw-button { flex: 1.35; border-color: var(--green); background: #102814; font-size: 15px; }
.pause-button { flex: .8; }
.throw-choice { flex: 1; padding-inline: 5px; font-size: 10px; }

.touch-menu { position: relative; }
.touch-menu > summary { display: grid; place-items: center; list-style: none; }
.touch-menu > summary::-webkit-details-marker { display: none; }
.touch-menu-panel {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: calc(100% + 8px);
  display: grid;
  min-width: 145px;
  gap: 6px;
  padding: 8px;
  border: 1px solid #405846;
  border-radius: 6px;
  background: #080d09;
  box-shadow: 0 8px 24px rgba(0,0,0,.7);
}

@media (pointer: coarse), (max-width: 700px) {
  body {
    display: block;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    overscroll-behavior: none;
  }
  .controls { display: none; }
  .touch-controls { display: grid; }
  .screen-shell { width: min(100%, 680px); }
  .masthead { margin-bottom: 8px; }
  .eyebrow { display: none; }
  h1 { font-size: clamp(25px, 9vw, 42px); }
  #start-button { min-height: 48px; }
}

@media (pointer: coarse) and (orientation: landscape), (max-width: 700px) and (orientation: landscape) {
  .cabinet { max-width: 760px; margin: 0 auto; }
  .masthead { display: none; }
  .screen-shell { width: min(57vw, calc((100vh - 20px) * 1.4583)); margin-left: 0; }
  .touch-controls {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: calc(43vw - 28px);
    margin: 0;
    align-content: center;
  }
  .touch-row { flex-wrap: wrap; }
  .movement-controls, .throw-controls { flex-basis: 100%; }
  #start-button, .hint { margin-left: 0; max-width: 57vw; }
}

@media (max-height: 700px) {
  body { padding: 12px; }
  .masthead { margin-bottom: 8px; }
  .screen-shell { width: min(100%, calc((100vh - 190px) * 1.4583), 980px); }
  .controls { margin: 10px auto 8px; }
}
