:root {
  /* Second Grade Studios house colours (light scheme: the sprites need a light field) */
  --bg: #ECEEF1;          /* light grey page */
  --panel: #FFFFFF;       /* cards */
  --ink: #111111;
  --muted: #4d4f52;       /* ~70% ink, 4.5:1+ on both greys */
  --slate: #22272E;       /* deep slate: outlines, pixel shadows */
  --slate-2: #2E343C;
  --grid: #dde1e6;
  --earth: #BD4B37;       /* Radiant Earth: the main "go" button */
  --yellow: #FCD93B;      /* Positively Yellow: on / selected (black text) */
  --blue: #5D88BF;        /* Offline Blue: links, secondary */
  --pink: #EF8B81;
  --green: #CFE2D6;
  --ground: #2E343C;      /* used by game.js via the canvas, kept here for reference */
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px;
  background-position: -1px -1px;
  color: var(--ink);
  display: flex;
  justify-content: center;
  padding: 24px 12px 40px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  touch-action: manipulation;
}

#app { width: 100%; max-width: 860px; position: relative; }

/* iPhone/iPad: fast repeated taps must never select text, open the copy/look-up menu, the magnifier or zoom.
   The game area is not selectable; only the footer (email address) is. */
#app {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#stage, #touchPad { touch-action: none; } /* the rest of the page still scrolls normally */
footer { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

a { color: #2f5f9a; }
:focus-visible { outline: 3px solid var(--slate); outline-offset: 2px; box-shadow: 0 0 0 6px #fff; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
header h1 { font-size: 26px; margin: 0; letter-spacing: 0.5px; }

.iconBtn, .bigBtn {
  border: 2px solid var(--slate);
  background: var(--panel);
  color: var(--ink);
  border-radius: 4px;
  padding: 10px 16px;
  font: 700 14px Arial, Helvetica, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--slate);
}
.iconBtn:hover { background: var(--yellow); }
.iconBtn:active, .bigBtn:active { box-shadow: 1px 1px 0 var(--slate); transform: translate(2px, 2px); }
.bigBtn { font-size: 18px; padding: 12px 40px; }
.bigBtn.primary { background: var(--earth); color: #fff; }
.bigBtn.primary:hover { background: #a63f2d; }

#hud { display: flex; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.stat {
  background: var(--panel);
  border: 2px solid var(--slate);
  border-radius: 4px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 96px;
  flex: 1 1 0;
  box-shadow: 3px 3px 0 var(--slate);
}
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; text-align: center; }
.stat span:last-child { font-size: 22px; font-weight: 700; }

#stage { position: relative; }
canvas#game {
  width: 100%;
  height: auto;
  background: #fff;
  border: 3px solid var(--slate);
  border-radius: 4px;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#titleScreen {
  position: absolute;
  inset: 0;
  z-index: 20;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--panel);
  border: 3px solid var(--slate);
  border-radius: 4px;
  box-shadow: 5px 5px 0 var(--slate);
  padding: 24px;
  text-align: center;
}
#titleScreen.hidden { display: none; }
#titleLogo { width: 72px; height: auto; border-radius: 8px; background: #000; }
#titleGameName { margin: 0; font-size: 40px; letter-spacing: 0.5px; color: var(--ink); }
#titleSub { margin: 0; color: var(--muted); font-size: 14px; letter-spacing: 1.5px; text-transform: uppercase; }
#titleMadeWith { margin: 0; color: var(--muted); font-size: 13px; }
#titleDifficulty { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 8px 0 4px; }
#titleDifficulty .slider-label { font-weight: 700; text-transform: uppercase; font-size: 13px; letter-spacing: 0.5px; }
#titleDifficulty input[type="range"] { width: 220px; accent-color: var(--earth); }
#titlePrompt {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#overlay.hidden { display: none; }
#overlayCard {
  background: rgba(255,255,255,0.97);
  border: 3px solid var(--slate);
  border-radius: 4px;
  padding: 16px 28px;
  text-align: center;
  box-shadow: 5px 5px 0 var(--slate);
  max-width: 90%;
}
#overlayCard h2 { margin: 0 0 6px; text-transform: uppercase; letter-spacing: 1px; font-size: 22px; }
#overlayCard p { margin: 0; color: var(--muted); }

/* Touch controls: shown on touch screens (and once a touch is seen) */
#touchPad { display: none; }
body.touch #touchPad {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  margin-top: 12px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
@media (pointer: coarse) {
  #touchPad {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    margin-top: 12px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
}
.padBtn {
  min-height: 96px;
  border: 3px solid var(--slate);
  border-radius: 8px;
  font: 700 24px Arial, Helvetica, sans-serif;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 4px 4px 0 var(--slate);
  touch-action: none;
  cursor: pointer;
}
.padBtn.jump { background: var(--earth); color: #fff; }
.padBtn.duck { background: var(--yellow); color: #111; }
.padBtn.down { box-shadow: 1px 1px 0 var(--slate); transform: translate(3px, 3px); }
.padSmall { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.padMini {
  min-height: 44px;
  min-width: 92px;
  border: 2px solid var(--slate);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font: 700 13px Arial, Helvetica, sans-serif;
  text-transform: uppercase;
  touch-action: none;
}

#controlsRow {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  align-items: center;
  margin-top: 14px;
  background: var(--panel);
  border: 2px solid var(--slate);
  border-radius: 4px;
  padding: 12px 16px;
}
.toggle, .slider-label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--earth); }
.slider-label input { accent-color: var(--earth); }

#hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; line-height: 1.6; }
kbd {
  background: var(--panel);
  border: 1px solid #9aa0a8;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
}

footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 2px solid var(--slate);
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}
footer p { margin: 4px 0; }
footer strong { color: var(--ink); }
footer .fine { font-size: 12px; }

/* High contrast mode */
body.hc {
  --bg: #000;
  --panel: #111;
  --ink: #fff;
  --muted: #ddd;
  --slate: #fff;
  --grid: #222;
}
body.hc canvas#game { background: #000; border-color: #fff; }
body.hc a { color: #ffdd00; }
body.hc #overlayCard { background: rgba(0,0,0,0.95); }
body.hc kbd { background: #111; }

/* Modal */
.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
.modalOverlay.hidden { display: none; }
.modal {
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--slate);
  border-radius: 4px;
  padding: 24px 28px;
  width: 90%;
  max-width: 460px;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.3);
}
.modal h2 { margin-top: 0; text-transform: uppercase; letter-spacing: 1px; }
.modalHint { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.bindRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #c9ced5;
  gap: 10px;
}
.bindLabel { flex: 1; font-size: 15px; }
.bindKey {
  min-width: 90px;
  text-align: center;
  background: var(--bg);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
}
.setBtn {
  border: 2px solid var(--slate);
  background: transparent;
  color: var(--ink);
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font: 700 12px Arial, Helvetica, sans-serif;
  text-transform: uppercase;
}
.setBtn.listening { background: var(--yellow); color: #111; }
.modalActions { display: flex; justify-content: space-between; margin-top: 20px; gap: 10px; }
.modalActions button {
  border: 2px solid var(--slate);
  background: transparent;
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
  font: 700 12px Arial, Helvetica, sans-serif;
  text-transform: uppercase;
  color: var(--ink);
}
.modalActions button.primary { background: var(--earth); color: #fff; box-shadow: 3px 3px 0 var(--slate); }

@media (max-width: 520px) {
  header h1 { font-size: 22px; }
  #titleGameName { font-size: 32px; }
  .stat { min-width: 0; padding: 6px 8px; }
  .stat span:last-child { font-size: 18px; }
  .padBtn { min-height: 84px; font-size: 20px; }
  .padMini { min-width: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .iconBtn:active, .bigBtn:active, .padBtn.down { transform: none; }
}

.hidden { display: none !important; }
