:root {
  --bg: #1a1c2c;
  --panel: #333c57;
  --panel-2: #29366f;
  --ink: #f4f4f4;
  --ink-dim: #94b0c2;
  --accent: #ffcd75;
  --green: #a7f070;
  --green2: #38b764;
  --purple: #5d275d;
  --red: #b13e53;
  --blue: #41a6f6;
  --font-pixel: 'Press Start 2P', monospace;
  --font-mono: ui-monospace, 'Cascadia Mono', Consolas, 'Courier New', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

.site-header { text-align: center; padding: 28px 16px 10px; }
.site-header h1 {
  font-family: var(--font-pixel);
  font-size: 28px;
  letter-spacing: 2px;
  margin: 0 0 14px;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--panel-2);
  display: inline-block;
  padding: 6px 10px;
}
.byline { margin: 0; color: var(--ink-dim); font-size: 13px; display: inline-block; padding: 4px 8px; }

main { display: flex; flex-direction: column; align-items: center; width: 100%; }

.game-frame {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
  margin: 12px 0 28px;
  max-width: 100vw;
}
.canvas-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
canvas#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--bg);
  border: 4px solid var(--panel);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--panel-2);
  outline: none;
}

/* narrator */
.narrator {
  margin-top: 14px;
  width: 100%;
  max-width: 1024px;
  min-height: 46px;
  background: #0f1020;
  border: 3px solid var(--panel);
  border-radius: 4px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  display: flex;
  gap: 10px;
  align-items: baseline;
}
/* always takes up the same space, so the page never shifts when he starts or stops talking */
.narrator { height: 92px; overflow: hidden; }
.narrator.hidden { visibility: hidden; }
.narrator.long { font-size: 12px; line-height: 1.35; }
.narrator .who {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--green);
  padding-top: 3px;
  flex: 0 0 auto;
}
.narrator .text { white-space: pre-wrap; }
.narrator .caret { display: inline-block; width: 8px; height: 15px; background: var(--ink-dim); margin-left: 2px; animation: blink 1s steps(1) infinite; align-self: center; }
.narrator[data-mood="panic"] { border-color: var(--red); animation: shake 0.3s linear infinite; }
.narrator[data-mood="panic"] .who { color: var(--red); }
.narrator[data-mood="quiet"] { color: var(--ink-dim); }
.narrator[data-mood="happy"] { border-color: var(--green); }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake { 0%{transform:translate(0,0)} 25%{transform:translate(1px,-1px)} 50%{transform:translate(-1px,1px)} 75%{transform:translate(1px,1px)} 100%{transform:translate(0,0)} }

/* code panel */
.codepanel {
  width: 420px;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  background: #0f1020;
  border: 3px solid var(--panel);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--panel-2);
}
.codepanel.hidden { display: none; }
.codepanel-tabs { display: flex; align-items: center; background: var(--panel); padding: 0; }
.codepanel-tabs .tab { padding: 7px 14px; background: #0f1020; color: var(--accent); font-size: 12px; border-right: 2px solid var(--panel); }
.codepanel-tabs .tab-spacer { flex: 1; }
.codepanel-tabs button {
  background: transparent; border: 0; color: var(--ink-dim); font-family: inherit; font-size: 11px; padding: 6px 10px; cursor: pointer;
}
.codepanel-tabs button:hover { color: var(--ink); }
.codepanel-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.codepanel .gutter {
  margin: 0; padding: 10px 6px 10px 10px; color: #566c86; text-align: right; user-select: none; font: inherit; line-height: 1.5; background: #0b0c18; min-width: 36px; overflow: hidden;
}
.codepanel .editor { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.codepanel .hl,
.codepanel textarea {
  position: absolute; inset: 0;
  margin: 0; padding: 10px 10px 10px 8px;
  border: 0; outline: none; resize: none;
  font: inherit; line-height: 1.5;
  white-space: pre; overflow-wrap: normal; overflow: auto;
  tab-size: 2;
  background: transparent;
}
.codepanel .hl { color: var(--ink); pointer-events: none; overflow: hidden; }
.codepanel .hl .c { color: #566c86; }
.codepanel .hl .n { color: var(--accent); }
.codepanel .hl .k { color: var(--sky); }
.codepanel .hl .b { color: var(--green); }
.codepanel .hl .o { color: #94b0c2; }
.codepanel textarea {
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--accent);
}
.codepanel textarea::selection { background: rgba(65,166,246,0.35); }
.codepanel-status { padding: 6px 12px; font-size: 11px; color: var(--ink-dim); background: #0b0c18; border-top: 2px solid var(--panel); min-height: 26px; }
.codepanel-status.error { color: var(--red); }
.codepanel-status.ok { color: var(--green); }

/* about + footer (these are platforms later, so give them real boxes) */
.about {
  width: min(92vw, 720px);
  margin: 0 0 60px;
  text-align: left;
}
.about.gone { display: none; }
.about h2 {
  font-family: var(--font-pixel);
  font-size: 13px;
  color: var(--blue);
  margin: 0 0 14px;
  display: inline-block;
  padding: 6px 8px;
  border-bottom: 3px solid var(--panel);
}
.about p { margin: 0 0 14px; color: var(--ink-dim); line-height: 1.6; padding: 6px 8px; display: inline-block; background: rgba(51,60,87,0.25); border-radius: 3px; }
.about b { color: var(--ink); }

.site-footer {
  margin-top: auto;
  padding: 26px 16px 36px;
  width: 100%;
  text-align: center;
  color: var(--ink-dim);
  font-size: 13px;
  border-top: 3px solid var(--panel);
  background: #15172a;
}
.site-footer .links { display: flex; justify-content: center; gap: 28px; margin-bottom: 14px; }
.site-footer a { color: var(--blue); text-decoration: none; padding: 8px 14px; border: 2px solid var(--panel); border-radius: 3px; display: inline-block; }
.site-footer a:hover { color: var(--ink); border-color: var(--ink-dim); }
.site-footer a.target { color: var(--accent); border-color: var(--accent); animation: glow 1s ease-in-out infinite alternate; }
.site-footer .copy { display: inline-block; padding: 4px 8px; }
@keyframes glow { from { box-shadow: 0 0 0 0 rgba(255,205,117,0); } to { box-shadow: 0 0 12px 2px rgba(255,205,117,0.6); } }

/* the player, when they are not where they are supposed to be */
.dom-player {
  position: absolute;
  left: 0; top: 0;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 50;
}
.dom-player.hidden { display: none; }

body.page-mode { position: relative; }
body.page-mode .site-header h1,
body.page-mode .byline,
body.page-mode .about h2,
body.page-mode .about p,
body.page-mode .site-footer a,
body.page-mode .site-footer .copy,
body.page-mode .narrator { outline: 2px dashed rgba(65,166,246,0.35); outline-offset: 2px; }

/* ---- the name prompt, before the build goes out ---- */
.nameprompt {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(26, 28, 44, 0.75);
  z-index: 200;
  padding: 16px;
}
.nameprompt.hidden { display: none; }
.namebox {
  width: min(92vw, 380px);
  background: #0f1020;
  border: 3px solid var(--panel);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--panel-2);
  padding: 0 0 16px;
  display: flex; flex-direction: column; gap: 12px;
  font-family: var(--font-mono);
}
.namebar { background: var(--panel); color: var(--ink); font-family: var(--font-pixel); font-size: 10px; padding: 8px 10px; display: flex; justify-content: space-between; }
.namebar .x { color: var(--red); }
.namebox label { padding: 6px 16px 0; color: var(--ink-dim); font-size: 14px; }
.namebox input {
  margin: 0 16px; padding: 10px 12px;
  background: #0b0c18; color: var(--accent);
  border: 2px solid var(--panel); border-radius: 3px;
  font: inherit; font-size: 16px; outline: none;
}
.namebox input:focus { border-color: var(--accent); }
.namebox button {
  margin: 0 16px; padding: 12px;
  background: var(--green2); color: var(--bg);
  border: 0; border-radius: 4px;
  font-family: var(--font-pixel); font-size: 11px;
  cursor: pointer;
}
.namebox button:hover { background: var(--green); }

/* ---- touch controls ---- */
.touch-controls { display: none; }
body.touch { touch-action: manipulation; padding-bottom: 150px; }
body.touch .touch-controls {
  display: block;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 0;
  z-index: 100;
  pointer-events: none;
}
.touch-controls .cluster {
  position: absolute;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 10px;
  align-items: flex-end;
  pointer-events: none;
}
.touch-controls .cluster-left { left: calc(12px + env(safe-area-inset-left, 0px)); }
.touch-controls .cluster-right { right: calc(12px + env(safe-area-inset-right, 0px)); }
.touch-controls .tbtn-restart {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  pointer-events: auto;
}
.tbtn {
  pointer-events: auto;
  width: 64px; height: 64px;
  border: 3px solid var(--panel);
  border-radius: 10px;
  background: rgba(15, 16, 32, 0.78);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 3px 0 var(--panel-2);
  cursor: pointer;
}
.tbtn.down { background: var(--blue); border-color: var(--sky); transform: translateY(2px); box-shadow: none; }
.tbtn-left, .tbtn-right { font-size: 22px; }
.tbtn-jump { width: 84px; height: 84px; border-color: var(--green2); color: var(--green); }
.tbtn-jump.down { background: var(--green2); color: var(--bg); }
.tbtn-flip { border-color: var(--purple); color: var(--yellow); }
.tbtn-flip.down { background: var(--purple); }
.tbtn-flip.disabled { opacity: 0.3; }
.tbtn-restart { width: 36px; height: 30px; font-size: 10px; color: var(--ink-dim); border-width: 2px; background: rgba(15, 16, 32, 0.6); }

/* ---- small screens ---- */
@media (max-width: 720px) {
  .site-header { padding: 18px 12px 6px; }
  .site-header h1 { font-size: 18px; letter-spacing: 1px; margin-bottom: 8px; text-shadow: 2px 2px 0 var(--panel-2); }
  .byline { font-size: 11px; }
  .game-frame { margin: 8px 0 18px; }
  canvas#game { border-width: 3px; }
  .narrator { font-size: 13px; padding: 8px 10px; margin-top: 10px; height: 82px; }
  .narrator .who { font-size: 8px; }
  .about { width: calc(100vw - 32px); margin-bottom: 40px; }
  .about p { font-size: 13px; }
  .site-footer .links { gap: 10px; flex-wrap: wrap; }
  .site-footer a { padding: 8px 10px; font-size: 12px; }
  .codepanel { width: calc(100vw - 32px); font-size: 12px; }
}

/* phone in landscape: the game gets the height, the header goes */
@media (max-height: 500px) and (orientation: landscape) {
  .site-header { display: none; }
  .game-frame { margin: 8px 0 12px; }
  body.touch { padding-bottom: 20px; }
  .narrator { margin-top: 8px; height: 62px; font-size: 12px; padding: 6px 8px; }
  .touch-controls .cluster { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
}
