* {
  box-sizing: border-box;
}

html {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: visible;
  overscroll-behavior-y: auto;
  color: #f8f0d0;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 218, 94, 0.18), transparent 30%),
    linear-gradient(180deg, #162831 0%, #10151c 58%, #15100d 100%);
  font-family: "Courier New", Courier, monospace;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.game-shell {
  width: min(100vw, 1000px);
  padding: 14px 20px 48px;
}

.canvas-wrap {
  position: relative;
  width: min(960px, calc(100vw - 40px));
  margin: 0 auto;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  margin: 0;
  background: #7fc8d7;
  border: 4px solid #f6e7a8;
  border-radius: 6px;
  image-rendering: pixelated;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
}

canvas:focus-visible {
  outline: 3px solid #9af3ff;
  outline-offset: 3px;
}

/* Keep iOS text selection, callouts, dragging, and browser pan/zoom gestures
   out of the game surface only. Portal content outside this wrapper keeps its
   normal browser behavior. */
.touch-input-available .canvas-wrap,
.touch-input-available .canvas-wrap canvas,
.touch-input-available .touch-controls,
.touch-input-available .touch-control-button {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

.touch-controls {
  display: none;
}

.touch-controls {
  --touch-control-size: clamp(88px, 20vmin, 120px);
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.overdrive-debug-panel {
  position: fixed;
  top: max(8px, calc(env(safe-area-inset-top) + 4px));
  left: max(8px, calc(env(safe-area-inset-left) + 4px));
  z-index: 70;
  max-width: min(260px, calc(100vw - 16px));
  padding: 7px 9px;
  border: 1px solid rgba(117, 220, 255, 0.72);
  border-radius: 6px;
  background: rgba(3, 10, 18, 0.78);
  color: #eafaff;
  font: 700 11px/1.35 "Courier New", monospace;
  white-space: pre-line;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-control-button {
  position: absolute;
  pointer-events: auto;
}

.touch-control-left,
.touch-control-right {
  bottom: max(12px, calc(env(safe-area-inset-bottom) + 6px));
}

.touch-control-left {
  left: max(12px, calc(env(safe-area-inset-left) + 6px));
}

.touch-control-right,
.touch-control-action {
  right: max(12px, calc(env(safe-area-inset-right) + 6px));
}

.touch-control-action {
  bottom: max(
    calc(88px + env(safe-area-inset-bottom)),
    calc(var(--touch-control-size) + 24px + env(safe-area-inset-bottom))
  );
}

.touch-control-button {
  width: var(--touch-control-size);
  height: var(--touch-control-size);
  padding: 0;
  border: 2px solid rgba(255, 242, 176, 0.78);
  border-radius: 50%;
  background: rgba(10, 20, 28, 0.54);
  box-shadow:
    0 5px 12px rgba(0, 0, 0, 0.3),
    inset 0 0 0 2px rgba(117, 220, 255, 0.12);
  color: #fff7cf;
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.75);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-control-button.is-pressed,
.touch-control-button:active {
  border-color: #ffffff;
  background: rgba(60, 190, 232, 0.78);
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.3),
    inset 0 0 18px rgba(255, 255, 255, 0.36);
  transform: translateY(2px) scale(0.96);
}

.touch-control-action[data-action-mode="overdrive-empty"] {
  opacity: 0.58;
  border-color: rgba(255, 242, 176, 0.46);
  background: rgba(10, 14, 18, 0.68);
}

.touch-control-action {
  display: grid;
  place-content: center;
  gap: 2px;
  border-color: rgba(117, 220, 255, 0.9);
}

.touch-control-icon {
  font-size: 0.72em;
}

.touch-control-label {
  font-size: clamp(9px, 1.5vw, 13px);
  letter-spacing: 0.04em;
}

.touch-input-available .touch-controls:not([hidden]) {
  display: block;
}

.touch-input-available.touch-game-active .game-shell {
  width: var(--game-visual-width, 100vw);
  max-width: none;
  padding:
    max(4px, env(safe-area-inset-top))
    max(6px, env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
}

.touch-input-available.touch-game-active .canvas-wrap {
  width: var(
    --game-fitted-width,
    min(
      960px,
      calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 12px),
      calc(177.777dvh - 14px)
    )
  );
}

.touch-input-available .toolbar,
.touch-input-available .controls,
.touch-input-available .key-config-panel {
  display: none;
}

.world-portal-link {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  padding: 7px 10px;
  border: 2px solid #f6e7a8;
  border-radius: 4px;
  background: rgba(16, 21, 27, 0.9);
  box-shadow: 3px 3px 0 rgba(20, 10, 8, 0.62);
  color: #fff2b0;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1;
  text-decoration: none;
}

.world-portal-link:hover,
.world-portal-link:focus-visible {
  background: #f6e7a8;
  color: #10151c;
  outline: 2px solid #10151c;
  outline-offset: 2px;
}

.world-portal-link[hidden] {
  display: none;
}

@media (max-width: 560px) {
  .world-portal-link {
    top: 9px;
    right: 9px;
    padding: 6px 8px;
    font-size: 10px;
  }
}

.toolbar {
  width: min(960px, calc(100vw - 40px));
  margin: 10px auto 0;
  display: flex;
  justify-content: flex-end;
}

button {
  font-family: "Courier New", Courier, monospace;
}

#keyConfigToggle,
#keyConfigClose,
#keyConfigReset,
.key-change-button {
  border: 2px solid #f6e7a8;
  border-radius: 5px;
  background: rgba(16, 21, 27, 0.86);
  color: #f8f0d0;
  cursor: pointer;
  font-weight: 700;
  padding: 7px 12px;
}

#keyConfigToggle:hover,
#keyConfigClose:hover,
#keyConfigReset:hover,
.key-change-button:hover {
  background: rgba(246, 231, 168, 0.18);
}

.key-config-panel {
  width: min(960px, calc(100vw - 40px));
  margin: 10px auto 24px;
  padding: 12px;
  /* keep the whole panel usable even on short viewports: the panel itself
     scrolls so Game Time / Difficulty at the bottom stay reachable */
  max-height: min(72vh, 640px);
  overflow-y: auto;
  border: 3px solid #f6e7a8;
  border-radius: 6px;
  background: rgba(12, 16, 22, 0.94);
  color: #f8f0d0;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.42);
}

.key-config-header,
.key-config-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
}

.key-config-header {
  margin-bottom: 10px;
}

.key-config-header h2 {
  margin: 0;
  color: #fff2b0;
  font-size: 18px;
}

.key-config-rows {
  display: grid;
  gap: 7px;
}

.key-config-row {
  min-height: 38px;
  padding: 6px 8px;
  background: rgba(255, 242, 176, 0.08);
  border: 1px solid rgba(246, 231, 168, 0.28);
  border-radius: 5px;
}

.key-action-name {
  color: #fff2b0;
  font-weight: 700;
}

.key-code {
  min-width: 170px;
  color: #9af3ff;
  text-align: right;
}

.game-config-header {
  margin: 14px 0 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(246, 231, 168, 0.28);
}

.game-config-select {
  border: 2px solid #f6e7a8;
  border-radius: 5px;
  background: rgba(16, 21, 27, 0.86);
  color: #9af3ff;
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  padding: 6px 8px;
  cursor: pointer;
}

.sound-config-range {
  width: min(260px, 38vw);
  accent-color: #75dcff;
  cursor: pointer;
}

.sound-config-value {
  min-width: 4ch;
  color: #9af3ff;
  font-weight: 700;
  text-align: right;
}

.key-config-status {
  margin: 10px 0;
  min-height: 20px;
  color: #efdf9d;
}

/* -------------------------------------------------------------------------
   GAME GUIDE
   Each topic is a self-contained card or section so future rules and story
   entries can be added without changing the game canvas or input code.
   ------------------------------------------------------------------------- */
.game-guide {
  --guide-ink: #f8f0d0;
  --guide-gold: #fff2b0;
  --guide-cyan: #9af3ff;
  width: min(960px, calc(100vw - 40px));
  margin: 26px auto 0;
  color: var(--guide-ink);
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

.game-guide * {
  touch-action: pan-y;
}

.guide-intro,
.guide-section {
  scroll-margin-top: 18px;
}

.guide-kicker,
.guide-step,
.card-label {
  margin: 0 0 7px;
  color: var(--guide-cyan);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.guide-intro > h1 {
  margin: 0;
  color: var(--guide-gold);
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.12;
}

.guide-intro > h1 span {
  display: inline-block;
  color: rgba(248, 240, 208, 0.58);
  font-size: 0.44em;
  letter-spacing: 0.08em;
  vertical-align: middle;
}

.guide-overview {
  margin-top: 16px;
  padding: clamp(18px, 3vw, 28px);
  border: 2px solid rgba(246, 231, 168, 0.52);
  border-left: 6px solid #f5cc4f;
  border-radius: 7px;
  background:
    linear-gradient(110deg, rgba(255, 206, 70, 0.13), transparent 56%),
    rgba(10, 17, 23, 0.78);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.25);
}

.guide-overview h2,
.guide-heading h2,
.guide-card h3,
.environment-grid h3 {
  color: var(--guide-gold);
}

.guide-overview h2 {
  margin: 0 0 10px;
  font-size: clamp(19px, 3vw, 25px);
}

.guide-overview p,
.guide-card p,
.environment-grid p,
.verification-note {
  line-height: 1.78;
}

.guide-overview p {
  max-width: 76ch;
  margin: 0;
  font-size: clamp(15px, 1.8vw, 17px);
}

.guide-section {
  margin-top: clamp(42px, 7vw, 68px);
}

.guide-heading {
  margin-bottom: 17px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(246, 231, 168, 0.3);
}

.guide-heading h2 {
  margin: 0;
  font-size: clamp(22px, 3.5vw, 31px);
}

.goal-grid,
.version-grid,
.control-layout,
.environment-grid {
  display: grid;
  gap: 14px;
}

.goal-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.guide-card {
  min-width: 0;
  padding: 19px;
  border: 1px solid rgba(246, 231, 168, 0.34);
  border-radius: 7px;
  background: rgba(12, 19, 25, 0.82);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
}

.guide-card h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.45;
}

.guide-card p {
  margin: 9px 0 0;
}

.guide-icon {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: 14px;
  place-items: center;
  border: 2px solid #f5cc4f;
  border-radius: 50%;
  color: #fff2b0;
  background: rgba(245, 204, 79, 0.1);
  font-size: 20px;
  font-weight: 900;
}

.control-layout {
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
}

.card-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 17px;
}

.card-label {
  margin-bottom: 4px;
}

.three-button-mark,
.config-mark {
  flex: none;
  padding: 5px 7px;
  border: 1px solid rgba(154, 243, 255, 0.6);
  border-radius: 4px;
  color: var(--guide-cyan);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.mobile-control-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.mobile-control-list > div {
  padding: 12px;
  border: 1px solid rgba(246, 231, 168, 0.24);
  border-radius: 5px;
  background: rgba(255, 242, 176, 0.06);
}

.mobile-control-list dt {
  color: var(--guide-gold);
  font-weight: 700;
}

.mobile-control-list dt span {
  display: inline-grid;
  width: 26px;
  height: 26px;
  margin-right: 5px;
  place-items: center;
  border: 1px solid rgba(154, 243, 255, 0.58);
  border-radius: 50%;
  color: var(--guide-cyan);
}

.mobile-control-list dd {
  margin: 7px 0 0;
  color: rgba(248, 240, 208, 0.86);
  font-size: 14px;
  line-height: 1.65;
}

.control-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.control-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.control-table th,
.control-table td {
  padding: 9px 8px;
  border-bottom: 1px solid rgba(246, 231, 168, 0.2);
  text-align: left;
  vertical-align: middle;
}

.control-table thead th {
  color: var(--guide-cyan);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.control-table tbody th {
  color: var(--guide-gold);
  font-weight: 700;
}

kbd {
  display: inline-block;
  min-width: 1.8em;
  margin: 2px 0;
  padding: 3px 6px;
  border: 1px solid rgba(246, 231, 168, 0.62);
  border-bottom-width: 3px;
  border-radius: 4px;
  background: #17242c;
  color: #fff;
  font: 700 12px/1.2 "Courier New", monospace;
  text-align: center;
}

.card-note {
  padding-top: 11px;
  border-top: 1px solid rgba(246, 231, 168, 0.2);
  color: rgba(248, 240, 208, 0.72);
  font-size: 12px;
}

.gamepad-card {
  margin-top: 14px;
}

.gamepad-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gamepad-grid p {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(246, 231, 168, 0.2);
  border-radius: 5px;
  background: rgba(255, 242, 176, 0.05);
  font-size: 13px;
}

.gamepad-grid strong {
  color: var(--guide-gold);
}

.version-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.version-card ul {
  margin: 15px 0 0;
  padding-left: 1.3em;
  line-height: 1.75;
}

.version-card li + li {
  margin-top: 6px;
}

.audio-note {
  display: flex;
  gap: 13px;
  margin-top: 14px;
  padding: 15px 17px;
  border: 1px solid rgba(117, 220, 255, 0.34);
  border-radius: 7px;
  background: rgba(39, 108, 127, 0.12);
  color: rgba(248, 240, 208, 0.86);
}

.audio-note-icon {
  flex: none;
  color: var(--guide-cyan);
  font-size: 21px;
}

.audio-note p {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
}

.audio-note strong {
  display: block;
  margin-bottom: 3px;
  color: var(--guide-cyan);
}

.environment-section {
  padding: clamp(18px, 3vw, 27px);
  border: 2px solid rgba(246, 231, 168, 0.4);
  border-radius: 7px;
  background: rgba(7, 12, 17, 0.62);
}

.environment-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.environment-grid section {
  padding: 4px 16px 4px 0;
}

.environment-grid section + section {
  padding-left: 20px;
  border-left: 1px solid rgba(246, 231, 168, 0.24);
}

.environment-grid h3 {
  margin: 0;
  font-size: 17px;
}

.environment-grid p {
  margin: 8px 0 0;
  font-size: 14px;
}

.verification-note {
  margin: 19px 0 0;
  padding-top: 15px;
  border-top: 1px solid rgba(246, 231, 168, 0.2);
  color: rgba(248, 240, 208, 0.62);
  font-size: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  .goal-grid,
  .control-layout,
  .version-grid,
  .environment-grid {
    grid-template-columns: 1fr;
  }

  .goal-card {
    display: grid;
    grid-template-columns: 42px 1fr;
    column-gap: 13px;
    align-items: center;
  }

  .goal-card .guide-icon {
    grid-row: 1 / 3;
    margin: 0;
  }

  .goal-card p {
    margin-top: 4px;
  }

  .environment-grid section,
  .environment-grid section + section {
    padding: 0;
    border-left: 0;
  }

  .environment-grid section + section {
    padding-top: 16px;
    border-top: 1px solid rgba(246, 231, 168, 0.2);
  }
}

@media (max-width: 560px) {
  .game-shell {
    padding: 9px 10px 38px;
  }

  .game-guide {
    width: calc(100vw - 20px);
    margin-top: 22px;
  }

  .guide-card {
    padding: 16px;
  }

  .gamepad-grid {
    grid-template-columns: 1fr;
  }

  .gamepad-grid p {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  }

  .control-table th,
  .control-table td {
    padding: 9px 5px;
    font-size: 12px;
  }

  .card-heading-row {
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

/* v0.8.5: no-damage reward movie overlay */
.reward-movie-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(4, 6, 10, 0.93);
  cursor: pointer;
}

.reward-movie-overlay video {
  max-width: min(92vw, 960px);
  max-height: 78vh;
  background: #000;
}

.reward-movie-skip {
  margin: 0;
  color: #fff2b0;
  font-family: "Courier New", Courier, monospace;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.controls {
  margin: 10px auto 0;
  max-width: 960px;
  color: #efdf9d;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
}
