:root {
  --bg: #f7efe1;
  --bg-accent: #fff8ef;
  --bg-deep: #efe5d3;
  --panel: rgba(255, 251, 245, 0.84);
  --panel-strong: rgba(255, 251, 245, 0.95);
  --text: #18222e;
  --muted: #5f6b74;
  --line: rgba(24, 34, 46, 0.1);
  --brand: #a63832;
  --brand-dark: #7d221d;
  --accent: #f2b35a;
  --accent-soft: rgba(242, 179, 90, 0.22);
  --focus: rgba(166, 56, 50, 0.24);
  --shadow: 0 22px 70px rgba(42, 38, 29, 0.12);
  --shadow-strong: 0 26px 72px rgba(42, 38, 29, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(166, 56, 50, 0.12), transparent 30%),
    radial-gradient(circle at 82% 8%, rgba(26, 91, 124, 0.1), transparent 24%),
    linear-gradient(180deg, var(--bg-accent) 0%, var(--bg) 50%, var(--bg-deep) 100%);
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8em;
  padding: 0.15em 0.45em;
  border-radius: 8px;
  border: 1px solid rgba(24, 34, 46, 0.12);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: inset 0 -1px 0 rgba(24, 34, 46, 0.08);
  font-size: 0.92em;
}

.site-shell {
  width: min(1320px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 42px;
}

.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 12px 16px;
  border-radius: 28px;
  background: rgba(255, 251, 245, 0.72);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.site-brand {
  display: inline-flex;
  gap: 14px;
  align-items: center;
  text-decoration: none;
}

.site-brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(242, 179, 90, 0.9), rgba(166, 56, 50, 0.92));
  box-shadow: 0 14px 30px rgba(166, 56, 50, 0.2);
  position: relative;
}

.site-brand-mark::before,
.site-brand-mark::after {
  content: "";
  position: absolute;
  border-radius: 8px;
}

.site-brand-mark::before {
  inset: 9px 20px 18px 9px;
  background: rgba(255, 255, 255, 0.92);
}

.site-brand-mark::after {
  inset: 18px 9px 9px 20px;
  background: rgba(24, 34, 46, 0.88);
}

.site-brand-label,
.eyebrow,
.panel-label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
}

.site-brand-label,
.eyebrow {
  color: var(--brand);
}

.site-brand-name {
  display: block;
  font-size: 18px;
  font-weight: 850;
}

.site-links,
.hero-actions-row,
.hero-metrics,
.game-footer-links,
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.site-links {
  align-items: center;
  justify-content: flex-end;
}

.site-links a,
.mini-link,
.btn,
.chip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  text-decoration: none;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

.site-links a,
.mini-link {
  padding: 11px 14px;
  color: var(--muted);
  background: rgba(24, 34, 46, 0.04);
  border: 1px solid transparent;
}

.site-links a:hover,
.site-links a:focus-visible,
.mini-link:hover,
.mini-link:focus-visible,
.btn:hover,
.btn:focus-visible,
.chip-btn:hover,
.chip-btn:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.mini-link {
  cursor: pointer;
}

.wrap {
  display: grid;
  gap: 16px;
  margin-top: 16px;
  padding-bottom: 16px;
}

.hero,
.guide-card,
.note-card,
.stage,
.game-footer {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.95fr);
  gap: 16px;
  padding: 16px;
  border-radius: 34px;
}

.hero-copy,
.hero-panel,
.guide-card,
.note-card,
.stage,
.game-footer {
  border-radius: 28px;
}

.hero-copy {
  padding: clamp(20px, 3vw, 34px);
  background:
    radial-gradient(circle at 10% 15%, rgba(242, 179, 90, 0.22), transparent 28%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.88), rgba(255, 249, 241, 0.74));
}

.hero-panel {
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 247, 238, 0.8));
  border: 1px solid rgba(24, 34, 46, 0.08);
}

.game-name {
  margin: 10px 0 0;
  font-size: clamp(2.4rem, 4.3vw, 4.7rem);
  line-height: 0.92;
  letter-spacing: -0.05em;
}

.intro-help,
.guide-copy,
.game-footer-copy {
  color: var(--muted);
  line-height: 1.7;
}

.hero-copy .intro-help {
  max-width: 58ch;
}

.hud-item {
  flex: 1 1 130px;
  min-width: 0;
  padding: 14px;
  border-radius: 20px;
  background: rgba(24, 34, 46, 0.04);
}

.hud-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 800;
}

.hud-value {
  display: block;
  margin-top: 7px;
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.btn,
.chip-btn {
  padding: 12px 16px;
  border: 1px solid rgba(24, 34, 46, 0.1);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.btn-strong,
.chip-btn.is-active {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 16px 30px rgba(166, 56, 50, 0.2);
}

.status-text {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: var(--brand-dark);
  font-weight: 700;
}

.stage-grid,
.notes-grid,
.touch-toolbar-actions {
  display: grid;
  gap: 16px;
}

.stage-grid {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  align-items: start;
}

.stage {
  padding: 14px;
  background:
    radial-gradient(circle at top right, rgba(26, 91, 124, 0.12), transparent 26%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 248, 239, 0.84));
}

canvas {
  display: block;
  width: min(100%, 900px);
  max-width: 100%;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 24px;
  outline: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.guide-card,
.note-card,
.game-footer {
  padding: 22px;
}

.touch-toolbar {
  display: none;
  position: sticky;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 12;
  padding: 14px;
  border-radius: 24px;
  border: 1px solid rgba(24, 34, 46, 0.1);
  background: rgba(255, 251, 245, 0.94);
  box-shadow: var(--shadow-strong);
  backdrop-filter: blur(18px);
}

.touch-toolbar-copy {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.5;
}

.touch-toolbar-copy strong {
  color: var(--text);
}

.touch-toolbar-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.touch-btn {
  min-height: 48px;
}

.control-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.legend {
  margin-top: 14px;
  flex-direction: column;
  align-items: start;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.legend-swatch {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(24, 34, 46, 0.12);
  background: rgba(255, 255, 255, 0.92);
  position: relative;
}

.legend-filled {
  background: #21354a;
}

.legend-marked::before,
.legend-marked::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: var(--brand);
}

.legend-marked::before {
  transform: rotate(45deg);
}

.legend-marked::after {
  transform: rotate(-45deg);
}

.legend-line {
  background: linear-gradient(135deg, rgba(38, 143, 84, 0.2), rgba(91, 171, 120, 0.5));
}

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

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

.game-footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.game-footer-links a:hover,
.game-footer-links a:focus-visible {
  color: var(--text);
  outline: none;
}

@media (max-width: 1040px) {
  .hero,
  .stage-grid,
  .notes-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .site-shell {
    width: min(100%, calc(100% - 12px));
    padding-top: 10px;
  }

  .wrap {
    padding-bottom: calc(116px + env(safe-area-inset-bottom));
  }

  .hero {
    order: 2;
  }

  .stage-grid {
    order: 1;
  }

  .touch-toolbar {
    order: 3;
  }

  .notes-grid {
    order: 4;
  }

  .game-footer {
    order: 5;
  }

  .site-nav {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .site-links {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    scrollbar-width: none;
  }

  .site-links::-webkit-scrollbar {
    display: none;
  }

  .site-links a,
  .mini-link {
    width: auto;
    min-width: max-content;
    flex: 0 0 auto;
  }

  .hero-actions-row .btn,
  .hero-actions-row .chip-btn {
    width: 100%;
  }

  .hero-actions-row-mobile-redundant {
    display: none;
  }

  .hero,
  .guide-card,
  .note-card,
  .game-footer,
  .stage,
  .touch-toolbar {
    border-radius: 24px;
  }

  .hero,
  .guide-card,
  .note-card,
  .game-footer {
    padding: 16px;
  }

  .hero-panel {
    padding: 18px;
  }

  .touch-toolbar {
    display: block;
  }

  .hero-copy .intro-help,
  .guide-card,
  .notes-grid,
  .touch-toolbar-copy {
    display: none;
  }

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

  .game-footer {
    align-items: start;
    flex-direction: column;
  }
}

@media (hover: none) and (pointer: coarse) and (max-height: 540px) {
  .wrap {
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
  }

  .hero {
    order: 2;
  }

  .stage-grid {
    order: 1;
  }

  .touch-toolbar {
    display: block;
    order: 3;
    padding: 10px 12px;
  }

  .notes-grid {
    order: 4;
  }

  .game-footer {
    order: 5;
  }

  .hero-actions-row-mobile-redundant {
    display: none;
  }

  .touch-toolbar-copy {
    display: none;
  }

  .touch-toolbar-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 0;
  }

  .touch-btn {
    min-height: 42px;
    padding-inline: 10px;
  }
}

html[data-display-mode="standalone"] body {
  padding-right: max(8px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(8px, env(safe-area-inset-left));
}

html[data-display-mode="standalone"] .site-shell {
  width: min(100%, calc(100% - 10px));
  padding-top: max(8px, env(safe-area-inset-top));
}

html[data-display-mode="standalone"] .wrap {
  padding-bottom: calc(116px + env(safe-area-inset-bottom));
}

html[data-display-mode="standalone"] .site-nav {
  border-radius: 24px;
  padding: 10px 12px;
}

html[data-display-mode="standalone"] .site-links {
  overflow-x: auto;
  flex-wrap: nowrap;
  justify-content: flex-start;
  scrollbar-width: none;
}

html[data-display-mode="standalone"] .site-links::-webkit-scrollbar {
  display: none;
}

html[data-display-mode="standalone"] .site-links a,
html[data-display-mode="standalone"] .mini-link {
  width: auto;
  min-width: max-content;
}

html[data-display-mode="standalone"] .hero {
  order: 2;
}

html[data-display-mode="standalone"] .stage-grid {
  order: 1;
}

html[data-display-mode="standalone"] .touch-toolbar {
  order: 3;
}

html[data-display-mode="standalone"] .notes-grid {
  order: 4;
}

html[data-display-mode="standalone"] .game-footer {
  order: 5;
}

html[data-display-mode="standalone"] .game-footer {
  display: none;
}

html[data-display-mode="standalone"] .touch-toolbar {
  display: block;
}

html[data-display-mode="standalone"] .hero-copy .intro-help,
html[data-display-mode="standalone"] .guide-card,
html[data-display-mode="standalone"] .notes-grid,
html[data-display-mode="standalone"] .touch-toolbar-copy {
  display: none;
}
