:root {
  --ink: #08151d;
  --paper: #f6f0e5;
  --paper-soft: #fffaf0;
  --line: rgba(8, 21, 29, 0.16);
  --green: #6f9f91;
  --green-dark: #1f4d45;
  --gold: #c9b487;
  --blue: #102a37;
  --risk: #b37a4c;
  --max: 1140px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  overflow-x: clip;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(246, 240, 229, 0.92), rgba(242, 235, 221, 0.96)),
    radial-gradient(circle at 20% 10%, rgba(111, 159, 145, 0.22), transparent 32%),
    linear-gradient(135deg, #f6f0e5 0%, #e9ddc9 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

#site-header {
  min-height: 126px;
}

.game-shell {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 32px 24px 28px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.hud div {
  min-height: 72px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.78);
  box-shadow: 0 16px 40px rgba(8, 21, 29, 0.08);
}

.hud span {
  display: block;
  margin-bottom: 4px;
  color: rgba(8, 21, 29, 0.62);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  font-size: clamp(1.3rem, 2vw, 1.8rem);
  line-height: 1;
}

.stage-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid rgba(8, 21, 29, 0.18);
  border-radius: 8px;
  background: #07131c;
  box-shadow: 0 28px 70px rgba(8, 21, 29, 0.20);
}

.background-copy {
  position: absolute;
  z-index: 1;
  top: 24px;
  left: 28px;
  max-width: 360px;
  color: rgba(246, 240, 229, 0.64);
  pointer-events: none;
}

.background-copy span {
  display: block;
  margin-bottom: 6px;
  color: rgba(213, 232, 226, 0.78);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.background-copy strong {
  display: block;
  font-size: clamp(1.4rem, 3vw, 2.75rem);
  line-height: 1.02;
}

canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  touch-action: none;
}

.learning-note {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 20px;
  width: min(680px, calc(100% - 32px));
  padding: 13px 16px;
  border: 1px solid rgba(213, 232, 226, 0.38);
  border-radius: 8px;
  color: #f6f0e5;
  background: rgba(7, 19, 28, 0.86);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  font-size: clamp(0.84rem, 1.7vw, 0.98rem);
  line-height: 1.45;
  opacity: 0;
  transform: translate(-50%, 14px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.learning-note.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 19, 28, 0.72);
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(560px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid rgba(213, 232, 226, 0.24);
  border-radius: 8px;
  color: #f6f0e5;
  background: rgba(8, 21, 29, 0.94);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
}

.kicker,
.result-label {
  display: block;
  margin-bottom: 10px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel h1 {
  margin: 0 0 12px;
  font-size: clamp(1.7rem, 4vw, 2.8rem);
  line-height: 1.02;
}

.panel p {
  margin: 0 0 20px;
  color: rgba(246, 240, 229, 0.82);
  line-height: 1.55;
}

button {
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  color: #07131c;
  background: var(--gold);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

button:hover,
button:focus-visible {
  background: #d6c394;
}

.quiet-link {
  color: var(--green-dark);
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.overlay-link {
  display: block;
  margin-top: 14px;
  color: rgba(213, 232, 226, 0.86);
  font-size: 0.88rem;
}

.result-card {
  margin: 18px 0 20px;
  padding: 18px;
  border: 1px solid rgba(201, 180, 135, 0.34);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(246, 240, 229, 0.10), rgba(213, 232, 226, 0.07));
}

.result-card dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.result-card div {
  padding: 10px;
  border: 1px solid rgba(213, 232, 226, 0.16);
  border-radius: 8px;
  background: rgba(7, 19, 28, 0.42);
}

.result-card dt {
  margin-bottom: 4px;
  color: rgba(246, 240, 229, 0.68);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.result-card dd {
  margin: 0;
  color: #f6f0e5;
  font-weight: 800;
}

.result-card p {
  margin-bottom: 0;
}

.controls,
.game-note {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.72);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: rgba(8, 21, 29, 0.72);
  font-size: 0.92rem;
  font-weight: 700;
}

.touch-controls {
  display: none;
  max-width: 100%;
  margin-top: 12px;
  gap: 10px;
  grid-template-columns: 1fr 1fr auto;
  align-items: stretch;
  touch-action: none;
}

.touch-move {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.touch-button {
  min-height: 58px;
  border: 1px solid rgba(8, 21, 29, 0.14);
  color: var(--ink);
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 0 10px 24px rgba(8, 21, 29, 0.10);
  font-size: 1.08rem;
}

.touch-button:active,
.touch-button.is-pressed {
  color: #f6f0e5;
  background: var(--green-dark);
}

.touch-jump {
  min-width: 132px;
  background: var(--gold);
}

.touch-restart {
  min-width: 72px;
  color: rgba(8, 21, 29, 0.76);
}

.game-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.game-note p {
  margin: 0;
  color: rgba(8, 21, 29, 0.74);
  line-height: 1.5;
}

footer {
  text-align: center;
  padding: 36px 24px 44px;
  color: rgba(244, 248, 246, 0.56);
  font-size: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: #07131c;
}

footer a {
  color: rgba(244, 248, 246, 0.76);
  text-decoration: none;
}

footer a:hover,
footer a:focus-visible {
  color: #ffffff;
  text-decoration: underline;
  outline: none;
}

@media (max-width: 760px) {
  #site-header {
    min-height: 70px;
  }

  .game-shell {
    padding: 14px 18px 28px;
  }

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

  .hud div {
    min-height: 58px;
  }

  .background-copy {
    top: 14px;
    left: 14px;
    max-width: 250px;
  }

  .panel {
    max-height: calc(100vh - 80px);
    overflow: auto;
  }

  .result-card dl,
  .game-note {
    grid-template-columns: 1fr;
    display: block;
  }

  .game-note a {
    display: flex;
    margin-top: 10px;
  }
}

@media (pointer: coarse) {
  .controls {
    display: none;
  }

  .touch-controls {
    display: grid;
  }

  .learning-note {
    position: static;
    display: none;
    width: auto;
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 0;
    background: rgba(7, 19, 28, 0.94);
    box-shadow: none;
    opacity: 1;
    transform: none;
    transition: none;
  }

  .learning-note.visible {
    display: block;
    transform: none;
  }
}

@media (max-width: 520px) {
  .touch-controls {
    grid-template-columns: 1fr 1fr;
  }

  .touch-move {
    grid-column: 1 / -1;
  }

  .touch-hint {
    grid-column: 1 / -1;
    margin: 0 0 2px;
    color: rgba(8, 21, 29, 0.66);
    font-size: 0.86rem;
    font-weight: 700;
    line-height: 1.35;
  }

  .touch-jump,
  .touch-restart {
    min-width: 0;
  }
}

@media (min-width: 521px) {
  .touch-hint {
    display: none;
  }
}
