:root {
  --panel: #151722;
  --panel-dark: #090c15;
  --text: #f7efd9;
  --gold: #e3b54a;
  --gold-dark: #84652d;
  --blue: #182541;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #090b12;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: radial-gradient(circle at 50% 0, #1e2942, #090b12 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
  text-align: center;
  overscroll-behavior: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.site-shell {
  width: min(1040px, 100%);
  margin: auto;
  padding: 14px 12px 24px;
}

.site-header .eyebrow {
  margin: 0 0 3px;
  color: #a8b5cd;
  font-size: 12px;
  letter-spacing: .16em;
}

h1 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: clamp(21px, 4vw, 31px);
  letter-spacing: .1em;
  line-height: 1.2;
  text-shadow: 3px 3px #000;
}

.game-card {
  width: 100%;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 1024px;
  aspect-ratio: 16 / 9;
  margin: auto;
  overflow: hidden;
  border: 5px solid var(--gold-dark);
  background: #000;
  box-shadow: 0 0 28px #000;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.start-screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    linear-gradient(rgba(3, 5, 12, .58), rgba(3, 5, 12, .82)),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(255, 255, 255, .035) 3px 4px);
}

.start-screen[hidden] {
  display: none;
}

.dialogue-next,
.ending-restart {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 13px;
  min-width: 154px;
  min-height: 38px;
  padding: 7px 16px;
  transform: translateX(-50%);
  border: 2px solid #ffe277;
  border-radius: 0;
  background: #6f2034;
  color: #fff7dc;
  font-weight: 900;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, .65);
  cursor: pointer;
  touch-action: manipulation;
}

.dialogue-next {
  right: clamp(8px, 3%, 28px);
  bottom: 14px;
  left: auto;
  min-width: 126px;
  transform: none;
  border-color: #f1ca66;
  background: #29466c;
}

.dialogue-next:hover,
.dialogue-next:focus-visible,
.ending-restart:hover,
.ending-restart:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  background: #96304a;
}

.dialogue-next[hidden],
.ending-restart[hidden] {
  display: none;
}

.start-card {
  width: min(310px, 88%);
  padding: 18px 20px;
  border: 2px solid var(--gold);
  background: rgba(9, 12, 21, .94);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, .52);
}

.start-kicker {
  margin: 0;
  color: #7dd9ef;
  font: 700 11px ui-monospace, monospace;
  letter-spacing: .18em;
}

.start-card h2 {
  margin: 4px 0 12px;
  color: #ffe071;
  font: 900 28px ui-monospace, monospace;
  letter-spacing: .12em;
}

.start-card p:last-child {
  margin: 10px 0 0;
  color: #b8c0cf;
  font-size: 11px;
}

.primary-button,
.panel button,
.utility-bar button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid #9b7835;
  border-radius: 0;
  background: #292318;
  color: var(--text);
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.primary-button {
  min-width: 190px;
  border: 2px solid #f4c95d;
  background: #8d2b3d;
  color: #fff7d8;
  font-size: 17px;
  box-shadow: 0 4px 0 #3f1420;
}

.primary-button:hover,
.primary-button:focus-visible,
.panel button:hover,
.panel button:focus-visible,
.utility-bar button:hover,
.utility-bar button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  background: #40351f;
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.utility-bar,
.buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.utility-bar {
  margin-top: 9px;
}

.panel {
  margin-top: 9px;
  padding: 9px 12px;
  border: 1px solid #5c4825;
  background: var(--panel);
  line-height: 1.65;
}

.instructions {
  margin: 0;
  font-size: 14px;
}

.buttons {
  margin-top: 7px;
}

.touch-controls {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
  padding: 0 max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

.direction-controls {
  display: flex;
  gap: 12px;
}

.touch-button {
  display: grid;
  width: 72px;
  height: 66px;
  place-content: center;
  border: 2px solid #d2a443;
  border-radius: 12px;
  background: linear-gradient(#313947, #161b25);
  color: #fff5d2;
  font-size: 27px;
  font-weight: 900;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .28), 0 3px 0 #080a0e;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-button small {
  display: block;
  margin-top: -2px;
  color: #d9dfec;
  font-size: 10px;
  letter-spacing: .04em;
}

.touch-button.is-pressed {
  transform: translateY(3px);
  border-color: #fff0a1;
  background: #6b5323;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12);
}

.jump-button {
  width: 92px;
  border-color: #d95b75;
  background: linear-gradient(#8c3044, #451925);
}

.orientation-message {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(22px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  background: #080b13;
}

.orientation-card {
  width: min(340px, 92vw);
  padding: 24px 18px;
  border: 2px solid var(--gold);
  background: #131824;
}

.orientation-card p {
  margin: 8px 0 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.5;
}

.rotate-icon {
  display: block;
  color: #f3c457;
  font-size: 44px;
  line-height: 1;
}

@media (hover: none), (pointer: coarse), (max-width: 820px) {
  .touch-controls {
    display: flex;
  }

  .panel {
    padding-inline: 8px;
  }
}

@media (orientation: portrait) and (hover: none),
  (orientation: portrait) and (pointer: coarse) {
  body {
    overflow: hidden;
  }

  .orientation-message {
    display: flex;
  }
}

@media (orientation: landscape) and (hover: none),
  (orientation: landscape) and (pointer: coarse),
  (orientation: landscape) and (max-height: 600px) {
  body {
    overflow: hidden;
  }

  .site-shell {
    width: 100%;
    height: 100vh;
    height: 100svh;
    padding: 0;
  }

  .site-header,
  .panel {
    display: none;
  }

  .game-card {
    position: relative;
    display: flex;
    height: 100%;
    min-height: 0;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .canvas-wrap {
    width: min(100%, 177.778vh);
    width: min(100%, 177.778svh);
    height: min(100%, 56.25vw);
    max-width: none;
    min-height: 0;
    margin: 0;
    border-width: 2px;
    flex: 0 0 auto;
  }

  .touch-controls {
    position: absolute;
    z-index: 7;
    right: 0;
    bottom: max(6px, env(safe-area-inset-bottom));
    left: 0;
    height: auto;
    margin: 0;
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
    pointer-events: none;
  }

  .direction-controls {
    gap: 8px;
  }

  .touch-button {
    width: 58px;
    height: 54px;
    border-radius: 10px;
    opacity: .78;
    pointer-events: auto;
  }

  .jump-button {
    width: 72px;
    height: 58px;
  }

  .utility-bar {
    position: absolute;
    z-index: 8;
    top: max(3px, env(safe-area-inset-top));
    left: 50%;
    min-width: 0;
    margin: 0;
    transform: translateX(-50%);
    flex-wrap: nowrap;
    gap: 3px;
    opacity: .72;
  }

  .utility-bar button {
    min-width: 0;
    min-height: 24px;
    padding: 2px 7px;
    overflow: hidden;
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dialogue-next {
    right: 5px;
    bottom: 5px;
    min-width: 84px;
    min-height: 28px;
    padding: 3px 8px;
    font-size: 12px;
  }

  .start-card {
    padding: 10px 14px;
  }

  .start-card h2 {
    margin: 2px 0 7px;
    font-size: 21px;
  }

  .start-card p:last-child {
    display: none;
  }

  .primary-button {
    min-width: 160px;
    min-height: 34px;
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .touch-button {
    transition: none;
  }
}
