* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #fafaf2;
  --ink: #0a0a0a;
  --muted: #444444;
  --brand: #0f6e72;
  --accent: #ffe030;
  --card: #ffffff;
  --border: 2px solid #0a0a0a;
  --shadow: 4px 4px 0 #0a0a0a;
  --shadow-lg: 6px 6px 0 #0a0a0a;
}

body {
  background: linear-gradient(160deg, #fafaf2 0%, #f0f6f6 65%, #fff5cc 100%);
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  font-weight: bold;
  color: var(--ink);
}

#container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  max-width: 1120px;
  margin: 0 auto;
}

#simFrame {
  position: relative;
  width: min(100%, 1120px, calc(480px * 840 / 460));
  max-height: 480px;
  --control-band-height: 26.0869565%;
}

#simFrame::after {
  content: '';
  position: absolute;
  inset: 0;
  border: var(--border);
  pointer-events: none;
  z-index: 5;
}

#topTitleBar {
  position: absolute;
  top: 1px;
  left: 1px;
  right: 1px;
  background: var(--accent);
  border-bottom: var(--border);
  border-radius: 0;
  padding: 6px 10px;
  z-index: 3;
}

#topTitleBar h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(0.95rem, 1.5vw, 1.2rem);
  line-height: 1.1;
  font-weight: 700;
}

#simCanvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--card);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  cursor: grab;
  touch-action: none;
}

#simCanvas:active {
  cursor: grabbing;
}

#sidebar {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  height: calc(var(--control-band-height) - 4px);
  min-height: 0;
  background: rgba(255, 254, 248, 0.95);
  border-top: var(--border);
  border-radius: 0 0 4px 4px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr auto auto;
  grid-template-rows: auto auto;
  gap: 8px;
  align-items: center;
  backdrop-filter: blur(1px);
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 2;
}

#instructions,
#cogDisplay,
#forcesLabel,
#resetBtn {
  grid-row: 1;
}

#instructions {
  margin: 0;
  font-size: 0.68em;
  line-height: 1.2;
}

#instructions p {
  margin: 0;
  white-space: nowrap;
}

#instructions strong {
  color: var(--brand);
}

#cogDisplay {
  background: #fff8cc;
  border: var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  margin: 0;
  font-size: 0.75em;
  font-weight: bold;
  box-shadow: var(--shadow);
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
}

#statusDisplay {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  background: #f2fbfb;
  border: var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 0.72em;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  min-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#forcesLabel {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  margin: 0;
  padding: 6px 10px;
  font-size: 0.78em;
  font-weight: 700;
  white-space: nowrap;
  background: #fff8cc;
  border: var(--border);
  border-radius: 999px;
  box-shadow: 2px 2px 0 #0a0a0a;
  cursor: pointer;
}

#showForces {
  transform: scale(1.25);
  margin-right: 8px;
  vertical-align: middle;
  accent-color: var(--brand);
}

#forcesLabel:has(#showForces:checked) {
  background: #d7f5f2;
  box-shadow: 3px 3px 0 #0a0a0a;
}

#resetBtn {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 7px 12px;
  font-size: 0.82em;
  font-weight: bold;
  background: var(--accent);
  color: var(--ink);
  border: var(--border);
  border-radius: 6px;
  box-shadow: 3px 3px 0 #0a0a0a;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-shadow: none;
  transition: transform 0.1s, box-shadow 0.1s;
}

#resetBtn:hover, #resetBtn:focus {
  background: #fff8cc;
  color: var(--ink);
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 #0a0a0a;
  outline: none;
}

@media (max-width: 920px) {
  #container {
    padding: 16px 10px;
  }

  #sidebar {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    row-gap: 6px;
    height: calc(var(--control-band-height) - 4px);
    min-height: 0;
  }

  #cogDisplay,
  #forcesLabel,
  #resetBtn {
    grid-row: auto;
  }

  #statusDisplay {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  #instructions {
    display: none;
  }
}

@media (max-width: 760px) {
  #container {
    padding: 8px;
    max-width: 100%;
  }

  #simFrame {
    width: 100%;
  }

  #sidebar {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    height: auto;
    min-height: 0;
    border-top: var(--border);
    border-radius: 0;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    row-gap: 8px;
    margin-top: 0;
  }

  #instructions {
    display: none;
  }

  #cogDisplay,
  #forcesLabel,
  #resetBtn {
    grid-row: auto;
  }

  #statusDisplay {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}

@media (max-width: 760px) and (orientation: portrait) {
  #simFrame {
    max-height: none;
    width: 100%;
  }
}
