* {
  box-sizing: border-box;
}
html {
  background: #080f1a;
  color: #e8e4d7;
  font-family: "Courier New", monospace;
}
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(
    ellipse at 50% 25%,
    #1e3347 0,
    #0c1826 48%,
    #080f1a 85%
  );
}
button {
  font:
    700 12px "Courier New",
    monospace;
  letter-spacing: 1px;
  color: #dfe8e9;
  background: #172a3c;
  border: 1px solid #455968;
  padding: 12px 17px;
  cursor: pointer;
}
button:hover {
  color: #fff0c8;
  border-color: #f1cb82;
  background: #263e50;
}
button:focus-visible {
  outline: 3px solid #f1cb82;
  outline-offset: 3px;
}
main {
  max-width: 1200px;
  margin: auto;
  padding: 30px 40px;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 14px;
}
.brand {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -2px;
  color: #f0c982;
}
.brand span {
  font-size: 13px;
  letter-spacing: 1px;
  border-left: 1px solid #65727b;
  padding-left: 12px;
  margin-left: 12px;
}
.edition {
  font-size: 12px;
  letter-spacing: 2px;
  color: #a5b2be;
}
.edition i {
  color: #d9b874;
  margin: 0 10px;
}
header button {
  padding: 9px 10px;
  font-size: 11px;
  background: transparent;
}
.cabinet {
  position: relative;
  border: 1px solid #5b6f7e;
  box-shadow:
    0 0 0 6px #101d2b,
    0 28px 70px #0009;
  aspect-ratio: 16/9;
  overflow: hidden;
  background: #0d1c30;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(#06101b25, #06101b66);
}
#overlay.hidden {
  display: none;
}
#panel {
  width: 90%;
  text-shadow: 0 3px #071322;
}
#panel .eyebrow {
  color: #e6c783;
  font-size: clamp(10px, 1.3vw, 14px);
  letter-spacing: 4px;
}
h1 {
  font-size: clamp(30px, 6.8vw, 78px);
  letter-spacing: -3px;
  line-height: 0.9;
  margin: 22px 0 5px;
  color: #f6e9c9;
  text-shadow:
    4px 4px #9d463c,
    7px 7px #071522;
  font-weight: 900;
}
h1 span {
  display: block;
  color: #efbf6e;
  font-size: 0.78em;
  letter-spacing: 14px;
  margin-top: 15px;
}
h2 {
  font-size: clamp(20px, 3vw, 34px);
  color: #f2d18e;
  margin: 15px 0;
}
#panel p {
  max-width: 590px;
  margin: 15px auto;
  font-size: clamp(11px, 1.4vw, 16px);
  line-height: 1.6;
}
#panel .sub {
  font-size: 11px;
  color: #b4c7d1;
  letter-spacing: 2px;
}
#panel button {
  background: #efd08f;
  color: #152335;
  border: 0;
  box-shadow: 4px 4px #7f5940;
  margin: 10px 7px;
  padding: 16px 25px;
  font-size: 14px;
}
#panel button.secondary {
  background: #20394b;
  color: #e9e2cf;
  box-shadow: 4px 4px #071522;
}
#panel a {
  color: #b9cfdd;
  font-size: 11px;
}
#toast {
  position: absolute;
  top: 23%;
  left: 5%;
  width: 90%;
  text-align: center;
  color: #ffe4a2;
  font-weight: bold;
  font-size: clamp(12px, 2vw, 22px);
  text-shadow: 2px 2px #091220;
  pointer-events: none;
}
.below {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 23px;
  font-size: 11px;
  color: #8095a8;
}
.below b {
  color: #c2cbd0;
  letter-spacing: 1px;
  margin-left: 9px;
}
.below em {
  font-style: normal;
  color: #dfc58e;
  margin-left: 15px;
}
.below button {
  font-size: 10px;
  padding: 7px 9px;
}
footer {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 2px;
  color: #667d90;
  margin-top: 40px;
}
.touch {
  display: none;
  justify-content: space-between;
  margin-top: 20px;
  gap: 10px;
  touch-action: none;
}
.touch > div {
  display: flex;
  gap: 12px;
}
.touch button {
  height: 65px;
  min-width: 66px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  font-size: 17px;
}
.touch button[data-key="jump"] {
  background: #b34e43;
  border-color: #d68d70;
}
.touch button[data-key="attack"] {
  font-size: 12px;
}
@media (pointer: coarse) {
  .touch {
    display: flex;
  }
  .keys {
    display: none;
  }
}
@media (max-width: 650px) {
  main {
    padding: 18px 12px;
  }
  header {
    margin-bottom: 18px;
  }
  .edition {
    display: none;
  }
  .below {
    font-size: 9px;
  }
  .keys,
  footer span {
    display: none;
  }
  footer {
    font-size: 8px;
    letter-spacing: 1px;
    margin-top: 25px;
  }
  #panel .sub {
    font-size: 8px;
    letter-spacing: 1px;
  }
  #panel button {
    padding: 10px 15px;
    font-size: 11px;
    margin: 6px;
  }
  h1 {
    margin-top: 12px;
  }
  #panel p {
    margin: 8px auto;
  }
  .touch > div {
    gap: 7px;
  }
}
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  main {
    padding: 6px 85px;
  }
  header,
  footer,
  .below {
    display: none;
  }
  .cabinet {
    max-height: 94dvh;
    margin: auto;
    max-width: 167dvh;
  }
  .touch {
    display: flex;
    position: fixed;
    inset: auto 8px 20px;
    pointer-events: none;
  }
  .touch > div {
    flex-direction: column;
  }
  .touch button {
    pointer-events: auto;
    height: 56px;
    min-width: 60px;
  }
}

#panel {
  max-height: 100%;
  overflow-y: auto;
  padding: 12px 0;
}

/* Keep essential controls available beside the game in phone landscape. */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  header {
    display: block;
    position: fixed;
    top: 8px;
    right: 8px;
    width: 72px;
    margin: 0;
    z-index: 2;
  }
  header .brand,
  header .edition {
    display: none;
  }
  header > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  header button {
    width: 72px;
    padding: 8px 1px;
    font-size: 9px;
  }
  .below {
    display: block;
    position: fixed;
    top: 8px;
    left: 8px;
    margin: 0;
  }
  .below span {
    display: none;
  }
  .below button {
    width: 64px;
    font-size: 9px;
  }
}
.touch button.held {
  background: #526d7b;
  border-color: #f1cb82;
  transform: translateY(2px);
}
.touch button {
  -webkit-touch-callout: none;
}
@media (max-width: 650px) {
  #panel button {
    font-size: 10px;
    padding: 10px 12px;
  }
  header {
    gap: 5px;
  }
  .brand span {
    margin-left: 7px;
    padding-left: 7px;
  }
  header button {
    font-size: 9px;
    padding: 9px 7px;
  }
}
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  main {
    padding-left: calc(85px + env(safe-area-inset-left, 0px));
    padding-right: calc(85px + env(safe-area-inset-right, 0px));
  }
  header {
    right: calc(8px + env(safe-area-inset-right, 0px));
  }
  .below {
    left: calc(8px + env(safe-area-inset-left, 0px));
  }
  .touch {
    left: calc(8px + env(safe-area-inset-left, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}
@media (max-width: 650px), (max-height: 500px) and (orientation: landscape) {
  #panel.chapter-select {
    padding: 3px 0;
  }
  #panel.chapter-select h1 {
    font-size: 27px;
    margin: 7px 0;
    line-height: 0.9;
  }
  #panel.chapter-select h1 span {
    margin-top: 6px;
  }
  #panel.chapter-select > p:not(.sub) {
    display: none;
  }
  #panel.chapter-select button {
    display: block;
    max-width: 270px;
    width: 90%;
    margin: 5px auto;
    padding: 9px 8px;
    font-size: 11px;
  }
  #panel.chapter-select .eyebrow {
    font-size: 9px;
    letter-spacing: 2px;
  }
  #panel.chapter-select .sub {
    margin: 6px auto;
    font-size: 7px;
  }
}

/* Desktop instructions depend on input capability, never browser width. */
.touch-copy {
  display: none;
}
.keyboard-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 30px;
  margin-top: 22px;
  padding: 17px 12px;
  border: 1px solid #405567;
  background: #122435;
  color: #e6e6d6;
  font-size: 14px;
}
.keyboard-controls > span {
  display: flex;
  align-items: center;
  gap: 7px;
}
.keyboard-controls small {
  font-size: 12px;
  color: #a9becb;
}
kbd {
  font:
    700 14px "Courier New",
    monospace;
  display: inline-block;
  background: #263f52;
  color: #ffda94;
  border: 1px solid #748895;
  border-bottom: 3px solid #748895;
  padding: 7px 10px;
}
@media (pointer: fine) {
  .touch {
    display: none !important;
  }
}
@media (pointer: coarse) {
  .keyboard-controls,
  .keyboard-copy {
    display: none;
  }
  .touch-copy {
    display: inline;
  }
  .touch {
    display: flex;
  }
}
/* Three chapters remain visible together in the smallest game viewport. */
@media (max-width: 650px), (max-height: 500px) and (orientation: landscape) {
  #panel.chapter-select h1 {
    font-size: 22px;
    margin: 5px 0;
  }
  #panel.chapter-select h1 span {
    margin-top: 3px;
  }
  #panel.chapter-select button {
    padding: 6px 8px;
    margin: 3px auto;
  }
  #panel.chapter-select .sub {
    margin: 4px auto;
    font-size: 7px;
  }
}

/* Four chapter choices fit as a compact two-column selector on phones. */
#panel.chapter-select button {
  width: 42%;
  max-width: 350px;
  padding-left: 8px;
  padding-right: 8px;
}
@media (max-width: 650px), (max-height: 500px) and (orientation: landscape) {
  #panel.chapter-select button {
    display: inline-block;
    width: 46%;
    margin: 3px 1%;
    font-size: 9px;
    min-height: 30px;
    padding: 5px 3px;
  }
}

#panel button:disabled {
  opacity: 0.43;
  cursor: not-allowed;
  box-shadow: none;
  color: #bdc6cb;
  background: #20303d;
}

#panel.finale h2 {
  color: #ffe09a;
  font-size: clamp(25px, 4.5vw, 54px);
  margin: 8px 0;
}
#panel.finale p {
  margin: 8px auto;
}
@media (max-width: 650px) {
  #panel.finale .eyebrow {
    letter-spacing: 1px;
  }
  #panel.finale button {
    padding: 8px;
  }
}

#panel.finale {
  background: #0c1929d9;
  padding: 16px;
  border: 1px solid #817350;
}
@media (max-width: 650px), (max-height: 500px) {
  #overlay:has(#panel.finale) {
    position: fixed;
    inset: 12px;
    z-index: 5;
    background: #08121df2;
  }
  #panel.finale {
    width: 100%;
    max-width: 680px;
  }
}

/* Stop iOS selection from starting on either a control or its surrounding UI. */
main,
.touch,
.touch * {
  -webkit-user-select: none;
  user-select: none;
}
.touch,
.touch * {
  -webkit-touch-callout: none;
  touch-action: none;
}
#panel.completion {
  background: #0c1929ed;
  padding: 14px;
  border: 1px solid #817350;
}
#panel.completion h2 {
  margin: 8px 0;
}
#panel.completion .result-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}
#panel.completion .result-actions button {
  margin: 5px;
}
@media (max-width: 650px), (max-height: 500px) {
  #overlay:has(#panel.completion) {
    position: fixed;
    inset: 12px;
    z-index: 5;
    background: #08121df2;
  }
  #panel.completion {
    width: 100%;
    max-width: 680px;
  }
  #panel.completion .eyebrow {
    letter-spacing: 1px;
  }
}

/* Let the finish animation and scenery breathe before the results panel. */
#overlay:has(#panel.mission-complete) {
  background: transparent;
  pointer-events: none;
}
#panel.mission-complete {
  transform: translateY(-35px);
  overflow: visible;
}
#panel.mission-complete h2 {
  font-size: clamp(22px, 4.8vw, 52px);
  color: #ffe3a0;
  text-shadow:
    3px 3px #152435,
    -1px -1px #152435;
}

/* Landscape thumb zones: raised controls with generous, separated hit targets. */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  .touch {
    left: calc(14px + env(safe-area-inset-left, 0px));
    right: calc(14px + env(safe-area-inset-right, 0px));
    bottom: calc(clamp(40px, 15dvh, 64px) + env(safe-area-inset-bottom, 0px));
    align-items: flex-end;
    margin-top: 0;
    z-index: 3;
  }
  .touch > div {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }
  .touch button {
    width: clamp(72px, 20dvh, 88px);
    min-width: 72px;
    height: clamp(72px, 20dvh, 88px);
    padding: 0;
    border-radius: 20px;
    border: 2px solid #8299aa;
    background: #20394bee;
    font-size: 24px;
    box-shadow: 0 4px 0 #080f1ab3;
  }
  .touch button[data-key="attack"] {
    font-size: 15px;
    position: relative;
    top: 0;
  }
  .touch button[data-key="jump"] {
    width: clamp(80px, 22dvh, 96px);
    height: clamp(80px, 22dvh, 96px);
    background: #b34e43f2;
    border-color: #f0ad8b;
    font-size: 19px;
  }
  .touch button.held {
    background: #526d7b;
    border-color: #ffe1a0;
  }
}

/* Reserve each thumb cluster's full width plus clearance outside the canvas. */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  main {
    --thumb-size: clamp(72px, 20dvh, 88px);
    --jump-size: clamp(80px, 22dvh, 96px);
    padding-left: calc(26px + var(--thumb-size) + env(safe-area-inset-left, 0px));
    padding-right: calc(26px + var(--jump-size) + env(safe-area-inset-right, 0px));
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .cabinet {
    width: 100%;
    flex-shrink: 0;
    margin: 0 auto;
  }
}

@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  header > div { gap:4px; }
  header button { padding:6px 1px; }
}
@media (pointer: coarse) and (max-height: 300px) and (orientation: landscape) {
  header { width:auto; }
  header > div { flex-direction:row; }
  header button { width:56px; }
}
