:root {
  --ink: #273432;
  --muted: #687773;
  --line: #dce9e4;
  --mint: #7ad0b3;
  --mint-dark: #2f8f70;
  --mint-soft: #eef9f5;
  --paper: #fffefb;
  --off-white: #fafbf7;
  --coral: #ff9f8f;
  --blue: #4f8fc9;
  --red: #d95f57;
  --shadow: 0 18px 48px rgba(48, 91, 78, 0.12);
}

* { box-sizing: border-box; }

html { background: #fff; }

body {
  margin: 0;
  color: var(--ink);
  background: #fbfdfb;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.75;
}

button { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.site-header,
.site-footer,
.game-page {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.site-header { min-height: 70px; }

.site-logo {
  color: var(--mint-dark);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 0.86rem;
}

.site-nav a,
.site-footer a { text-decoration: none; }

.site-nav a:hover,
.site-footer a:hover { color: var(--mint-dark); }

.game-page { margin-bottom: 64px; }

.game-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  align-items: center;
  gap: clamp(28px, 5vw, 72px);
  min-height: 400px;
  padding: 34px 0 44px;
}

.series-label {
  margin: 0 0 12px;
  color: var(--mint-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.hero-copy h1 {
  margin: 0;
  font-size: 48px;
  line-height: 1.15;
  letter-spacing: 0;
}

.hero-title-line { display: block; }

.hero-copy > p {
  max-width: 620px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.8vw, 1.12rem);
}

.hero-copy > .view-note {
  margin-top: 10px;
  font-size: 0.9rem;
}

.hero-preview {
  position: relative;
  min-height: 260px;
  border: 1px solid #e3eee9;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #f9fcfa 0 36%, #f1f8f4 36% 100%);
  box-shadow: 0 16px 38px rgba(48, 91, 78, 0.09);
  overflow: hidden;
}

.preview-horizon {
  position: absolute;
  top: 46%;
  right: 0;
  left: 0;
  border-top: 1px solid #d7e8e0;
}

.preview-orb {
  position: absolute;
  left: 51%;
  top: 29%;
  width: 22px;
  aspect-ratio: 1;
  border: 1px solid #c36858;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 27%, #fff7ee 0 10%, #ffc0a8 20%, #e87965 72%);
  box-shadow: 0 4px 18px rgba(185, 89, 72, 0.22);
  animation: preview-approach 2.6s ease-in infinite;
}

.preview-caption {
  position: absolute;
  top: 12px;
  right: 14px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

@keyframes preview-approach {
  0% { transform: translate(-2px, 0) scale(0.72); opacity: 0.55; }
  82% { transform: translate(6px, 96px) scale(2.4); opacity: 1; }
  100% { transform: translate(8px, 120px) scale(2.8); opacity: 0; }
}

.game-shell {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 32px);
}

.fullscreen-open,
.fullscreen-close {
  min-width: 48px;
  min-height: 48px;
  border: 1px solid #cddfd8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--mint-dark);
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.fullscreen-open:hover,
.fullscreen-close:hover { background: var(--mint-soft); }

.mobile-play-note {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.level-picker {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 16px;
}

.level-picker-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.level-picker-heading h2 { margin: 0; font-size: 1.08rem; }
.level-picker-heading p,
.level-picker-message { margin: 0; color: var(--muted); font-size: 0.86rem; }

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

.level-option {
  display: flex;
  min-width: 0;
  min-height: 120px;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.level-option:hover:not(:disabled) { border-color: var(--mint-dark); background: var(--mint-soft); }
.level-option[aria-pressed="true"] {
  border: 2px solid var(--mint-dark);
  background: #eff9f4;
  padding: 11px;
  box-shadow: inset 0 0 0 1px rgba(47, 143, 112, 0.08);
}
.level-option:disabled { cursor: not-allowed; }
.level-number { color: var(--mint-dark); font-size: 0.68rem; font-weight: 900; letter-spacing: 0.08em; }
.level-name { font-size: 1rem; }
.level-speed { font-size: 0.84rem; font-weight: 800; }
.level-aim { color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.level-picker-message { margin-top: 10px; }

.status-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.status-panel div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--mint-soft);
  padding: 12px;
}

.status-panel span {
  display: block;
  color: var(--mint-dark);
  font-size: 0.7rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.status-panel strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.05rem, 2.4vw, 1.5rem);
  line-height: 1.2;
}

.game-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px;
  overflow: hidden;
}

.stage-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.stage-cue { margin: 0; color: var(--mint-dark); font-weight: 800; }
.stage-details { text-align: right; }
.stage-level { margin: 0; color: var(--mint-dark); font-size: 0.78rem; font-weight: 900; letter-spacing: 0.04em; }
.stage-difficulty { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; font-weight: 800; }

.canvas-wrap {
  position: relative;
  min-height: 300px;
  aspect-ratio: 1.9;
  border: 1px solid #dfebe5;
  border-radius: 8px;
  background: #f8fcfa;
  overflow: hidden;
}

.canvas-top-controls,
.canvas-bottom-controls {
  position: absolute;
  z-index: 2;
  right: 10px;
  left: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.canvas-top-controls {
  top: 10px;
}

.canvas-top-actions {
  display: flex;
  gap: 8px;
}

.canvas-top-controls button { pointer-events: auto; }

.canvas-reset {
  min-width: 78px;
  min-height: 48px;
  border: 1px solid #cddfd8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.canvas-bottom-controls {
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  align-items: stretch;
  flex-direction: column;
}

.canvas-start {
  align-self: center;
  min-width: min(100%, 240px);
  min-height: 48px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 900;
  cursor: pointer;
  pointer-events: auto;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.stage-announcement {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: calc(100% - 28px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  background: rgba(39, 52, 50, 0.85);
  color: #fff;
  padding: 12px 18px;
  font-size: clamp(1.1rem, 4vw, 1.7rem);
  font-weight: 900;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.final-score {
  position: absolute;
  z-index: 4;
  top: 40%;
  left: 50%;
  display: grid;
  gap: 3px;
  min-width: 240px;
  max-width: calc(100% - 28px);
  border: 2px solid #b9ddcf;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 28px rgba(34, 68, 54, 0.2);
  color: var(--ink);
  padding: 10px 16px;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.final-score[hidden] { display: none; }
.final-score strong { color: var(--mint-dark); font-size: clamp(2rem, 8vw, 3.5rem); line-height: 1.05; white-space: nowrap; }
.final-score span { font-size: clamp(1.15rem, 4.5vw, 1.7rem); font-weight: 900; }
.final-score[data-result="game-over"] { border-color: #e8c6bc; }
.final-score[data-result="game-over"] strong { color: #a74735; }

.stage-message {
  min-height: 2.8em;
  margin: 12px 0 8px;
  color: var(--muted);
  text-align: center;
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  pointer-events: auto;
}

.touch-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-height: 68px;
  border: 1px solid #bdd9ce;
  border-radius: 10px;
  background: var(--mint-soft);
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-button span { font-size: 1.5rem; font-weight: 900; line-height: 1; }
.touch-button small { margin-top: 4px; color: var(--muted); font-size: 0.76rem; font-weight: 800; }
.touch-button:active,
.touch-button[aria-pressed="true"] { border-color: var(--mint-dark); background: #dff4eb; }
.touch-button:disabled { opacity: 0.52; cursor: not-allowed; }
.touch-button-duck { border-color: #e8dcae; background: #fff9e7; }
.touch-button-duck:active,
.touch-button-duck[aria-pressed="true"] { border-color: #ad8a2c; background: #fbf0c7; }

.canvas-start {
  border: 1px solid #278b6e;
  background: var(--mint-dark);
  color: #fff;
}

.canvas-start:hover { background: #267c62; }

.canvas-reset:hover { background: var(--mint-soft); }

.primary-button:focus-visible,
.ghost-button:focus-visible,
.fullscreen-open:focus-visible,
.fullscreen-close:focus-visible,
.touch-button:focus-visible,
.level-option:focus-visible { outline: 3px solid rgba(47, 143, 112, 0.35); outline-offset: 2px; }

.result-panel {
  border-top: 1px dashed #cfe0da;
  padding-top: 20px;
}

.result-panel h2,
.result-panel h3,
.result-panel p { margin-top: 0; }
.result-panel h2 { margin-bottom: 6px; font-size: 1.35rem; }
.result-panel p { color: var(--muted); }
.log-title { margin: 20px 0 10px; font-size: 1.05rem; }

.log-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.info-section {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 28px;
}

.info-section article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 20px;
}

.info-section h2 { margin: 0 0 8px; font-size: 1.08rem; }
.info-section p { margin: 0; color: var(--muted); }
.info-section a { color: var(--mint-dark); font-weight: 800; }

.comments-stub {
  margin-top: 30px;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

.comments-stub h2 { margin: 0 0 8px; font-size: 1.15rem; }
.comments-stub p { margin: 0; color: var(--muted); }

.site-footer {
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding: 36px 0 42px;
  color: var(--muted);
}

.game-shell:fullscreen {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: #fbfdfb;
}

.game-shell:fullscreen .status-panel,
.game-shell:fullscreen .game-stage {
  width: min(100%, 1200px);
  margin-inline: auto;
}

.game-shell:fullscreen .canvas-wrap {
  width: 100%;
  height: min(64vh, calc(100vh - 370px));
  min-height: 280px;
  max-height: none;
  margin-inline: auto;
}

.game-shell.pseudo-fullscreen {
  position: fixed;
  z-index: 10000;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: #fbfdfb;
  padding: 12px;
}

html.pseudo-fullscreen { overflow: hidden; }

.game-shell.pseudo-fullscreen .status-panel,
.game-shell.pseudo-fullscreen .game-stage {
  width: min(100%, 1200px);
  margin-inline: auto;
}

.game-shell.pseudo-fullscreen .canvas-wrap {
  width: 100%;
  height: max(260px, min(64dvh, calc(100dvh - 410px)));
  min-height: 260px;
  max-height: none;
  margin-inline: auto;
}

@media (max-width: 820px) {
  .game-hero {
    grid-template-columns: 1fr;
    min-height: 0;
    gap: 26px;
    padding-top: 28px;
  }
  .hero-preview { min-height: 210px; }
  .status-panel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .level-picker-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .info-section { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .site-header,
  .site-footer,
  .game-page { width: min(100% - 24px, 1120px); }
  .site-header,
  .site-footer { align-items: flex-start; flex-direction: column; }
  .hero-copy h1 { font-size: 28px; }
  .hero-copy > p { margin-top: 16px; }
  .hero-copy > .view-note { margin-top: 8px; }
  .hero-preview { min-height: 180px; }
  .game-shell { padding: 15px; }
  .status-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .status-panel div:last-child { grid-column: 1 / -1; }
  .level-options { grid-template-columns: 1fr; gap: 8px; }
  .level-option {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: start;
    min-height: 0;
    column-gap: 8px;
  }
  .level-option[aria-pressed="true"] { padding: 11px; }
  .level-number { grid-row: 1 / span 3; padding-top: 3px; }
  .stage-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .stage-details { text-align: left; }
  .stage-difficulty { max-width: 100%; }
  .game-stage { padding: 10px; }
  .canvas-wrap { min-height: 300px; aspect-ratio: 1.2; }
  .touch-controls { gap: 7px; }
  .touch-button { min-height: 68px; }
  .canvas-wrap { width: 100%; height: 360px; min-height: 0; aspect-ratio: auto; }
  .canvas-bottom-controls { right: max(8px, env(safe-area-inset-right)); left: max(8px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); }
  .canvas-top-controls { right: 8px; left: 8px; top: 8px; }
  .canvas-top-actions { gap: 6px; }
  .fullscreen-open,
  .fullscreen-close,
  .canvas-reset { min-height: 48px; padding-inline: 10px; }
  .canvas-reset { min-width: 70px; }
  .log-list { grid-template-columns: 1fr; }
  .mobile-play-note { font-size: 0.84rem; }
  .game-shell:fullscreen .canvas-wrap,
  .game-shell.pseudo-fullscreen .canvas-wrap { height: max(260px, calc(100dvh - 500px)); min-height: 260px; }
  .final-score { top: 39%; min-width: 190px; padding: 8px 12px; gap: 2px; }
  .final-score strong { font-size: clamp(1.4rem, 6vw, 2.4rem); }
  .final-score span { font-size: clamp(0.9rem, 4vw, 1.2rem); }
  .game-shell:fullscreen .final-score,
  .game-shell.pseudo-fullscreen .final-score {
    top: 36%;
    padding: 6px 12px;
    gap: 2px;
  }
  .game-shell:fullscreen .final-score strong,
  .game-shell.pseudo-fullscreen .final-score strong { font-size: clamp(1.2rem, 5vw, 1.6rem); }
  .game-shell:fullscreen .final-score span,
  .game-shell.pseudo-fullscreen .final-score span {
    font-size: clamp(0.8rem, 3.8vw, 1rem);
    line-height: 1.2;
  }
}

@media (max-width: 360px) {
  .hero-copy h1 { font-size: 27px; }
  .site-nav { gap: 8px 12px; }
  .status-panel span { font-size: 0.66rem; }
  .game-stage { padding: 8px; }
  .touch-button { min-height: 64px; }
  .canvas-wrap { height: 350px; min-height: 0; }
  .canvas-reset { min-width: 64px; padding-inline: 8px; }
  .fullscreen-open,
  .fullscreen-close { padding-inline: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .preview-orb { animation: none; left: 54%; top: 46%; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
