:root {
  color-scheme: dark;
  --page: #1d2b32;
  --control: #293d45;
  --line: #546c75;
  --ink: #f5e9cb;
  --muted: #b8cbc6;
  --gold: #efc681;
  --cow: #efc681;
  --tux: #a8d1c5;
  font-family: 'Avenir Next', 'Trebuchet MS', system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
}

::selection { color: var(--page); background: var(--gold); }

button {
  color: inherit;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, canvas:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.game {
  width: min(1056px, calc(100% - 48px));
  margin-inline: auto;
  padding-block: 26px 30px;
}

.masthead, .header-actions, .toolbar, .mode, .levels, .attempt {
  display: flex;
  align-items: center;
}

.masthead, .toolbar { justify-content: space-between; }
.masthead { gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.header-actions { gap: 8px; }
.music-toggle {
  min-height: 39px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
  font-size: 0.84rem;
  white-space: nowrap;
}
.music-toggle[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
}
.music-toggle:hover { background: #344c55; }
.btn-icon {
  width: 13px;
  height: 13px;
  margin-right: 6px;
  vertical-align: -2px;
  object-fit: contain;
  pointer-events: none;
}
.fast-forward.is-held .btn-icon,
.result-actions .primary .btn-icon {
  filter: brightness(0.2);
}

h1 {
  margin: 0;
  font-size: clamp(1.85rem, 4vw, 2.65rem);
  font-weight: 740;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.mode {
  border: 1px solid var(--line);
  background: var(--control);
}

.mode button {
  min-height: 39px;
  border: 0;
  padding: 8px 14px;
  background: transparent;
  font-size: 0.87rem;
  white-space: nowrap;
}

.mode button[aria-pressed="true"], .primary, .touch-actions .jump {
  color: #282e2b;
  background: var(--gold);
}

.mode button[aria-pressed="false"]:hover,
.levels button:hover, .restart:hover, .result-actions button:not(.primary):hover {
  background: #344c55;
}

.toolbar { flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.levels { flex-wrap: wrap; gap: 3px; }

.levels button, .restart {
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.86rem;
  white-space: nowrap;
}

.levels button span {
  margin-right: 5px;
  color: var(--muted);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
}

.levels button[aria-pressed="true"] {
  border-color: var(--line);
  background: var(--control);
  color: var(--gold);
}

.levels button[aria-pressed="true"] { border-bottom: 2px solid var(--gold); }
.levels button[aria-pressed="true"] span { color: var(--gold); }
.levels button .map-progress {
  margin-left: 6px;
  margin-right: 0;
  padding: 1px 5px;
  border: 1px solid var(--line);
  font-size: 0.7rem;
  color: var(--muted);
}
.levels button .map-progress.is-complete {
  border-color: var(--gold);
  color: var(--gold);
}
.medal-pip {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  vertical-align: 1px;
  display: none;
}
.medal-pip[data-medal="gold"] { display: inline-block; background: #efc681; box-shadow: 0 0 0 1px #755b2a; }
.medal-pip[data-medal="silver"] { display: inline-block; background: #d6e0dd; box-shadow: 0 0 0 1px #5c6f6b; }
.medal-pip[data-medal="bronze"] { display: inline-block; background: #cd8858; box-shadow: 0 0 0 1px #6a4124; }
.restart { color: var(--muted); }
.fast-forward {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
  font-size: 0.8rem;
  font-family: ui-monospace, Menlo, monospace;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.fast-forward:hover { background: #344c55; }
.fast-forward.is-held {
  background: var(--gold);
  border-color: var(--gold);
  color: #282e2b;
  font-weight: 700;
}
.attempt { gap: 7px; margin-left: auto; }

#run-time {
  min-width: 8ch;
  color: var(--gold);
  font: 650 0.92rem ui-monospace, Menlo, monospace;
  text-align: right;
}

.playfield { line-height: 0; }

#kitchen {
  display: block;
  width: 100%;
  aspect-ratio: 320 / 174;
  image-rendering: pixelated;
  touch-action: none;
}

.game-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  min-height: 54px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.game-status p { margin: 0; font-size: 0.95rem; font-weight: 625; }

.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.result-actions button {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--control);
  font-size: 0.86rem;
}

.result-actions .primary { background: var(--gold); border-color: var(--gold); }
.result-actions .primary:hover, .touch-actions .jump:hover { background: #f4d6a0; }

.key-guide { margin-top: 13px; }
.jump-guide { margin: 10px 0 0; color: var(--muted); font-size: 0.81rem; }

.leaderboard { margin-top: 15px; border-top: 1px solid var(--line); }

.leaderboard summary {
  padding: 11px 0;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 700;
}

.leaderboard summary::marker { color: var(--gold); }

.scope-badge {
  margin-left: 6px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

#best-time {
  margin-left: 8px;
  color: var(--gold);
  font: 600 0.79rem ui-monospace, Menlo, monospace;
}

.leaderboard-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 9px 20px;
  margin-bottom: 8px;
}

.leaderboard-heading p { margin: 0; font-weight: 680; font-size: 0.85rem; }
.leaderboard-heading .par-target {
  margin-top: 2px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  font-family: ui-monospace, Menlo, monospace;
}

.cosmetics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin: 6px 0 10px;
}

.cosmetic-card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--control);
}

.cosmetic-card h3 {
  margin: 0 0 8px;
  font-size: 0.84rem;
  color: var(--gold);
}

.cosmetic-card[data-cat="1"] h3 { color: var(--tux); }

.cosmetic-row-label {
  margin: 7px 0 4px;
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cosmetic-options {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.cosmetic-chip {
  min-height: 30px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--page);
  color: var(--ink);
  font-size: 0.77rem;
  font-weight: 600;
}

.cosmetic-chip[aria-pressed="true"] {
  border-color: var(--gold);
  background: var(--gold);
  color: #282e2b;
}

.cosmetic-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.leaderboard-heading label {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 9px;
  color: var(--muted);
  font-size: 0.82rem;
}

.leaderboard-heading input {
  width: 15ch;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
  font: inherit;
}

.ranked-times { margin: 5px 0 10px; padding-left: 1.65rem; font-size: 0.87rem; }
.ranked-times li::marker { color: var(--gold); font: 600 0.8rem ui-monospace, Menlo, monospace; }
.ranked-times li + li { border-top: 1px solid var(--line); }

.ranked-times li > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0 8px 5px;
}

.ranked-times li span:first-child { overflow-wrap: anywhere; }
.ranked-times li span:last-child { color: var(--gold); font-family: ui-monospace, Menlo, monospace; }
.scores-note { margin: 7px 0 0; color: var(--muted); font-size: 0.81rem; }
#credits-list { padding-left: 1.25rem; line-height: 1.5; }

.key-row, .duo-keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 17px;
  color: var(--muted);
  font-size: 0.84rem;
}

.duo-keys { gap: 11px 32px; }
.key-row > span { white-space: nowrap; }

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--cow);
  font-size: 0.84rem;
  font-weight: 720;
  white-space: nowrap;
}

.cat-chip[data-cat="1"] { color: var(--tux); }

.cat-chip::before {
  width: 8px;
  height: 8px;
  background: currentColor;
  content: '';
}

kbd {
  display: inline-block;
  margin-right: 3px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--ink);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.74rem;
}

.touch-controls { display: none; }
.touch-pad { display: grid; justify-items: start; gap: 8px; }
.touch-buttons { display: flex; align-items: center; gap: 12px; }

.direction-pad {
  display: grid;
  grid-template-areas: '. up .' 'left down right';
  grid-template-columns: repeat(3, 44px);
  gap: 4px;
}

.direction-pad button, .touch-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--control);
}

.direction-pad button {
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
}

.direction-pad button:active, .direction-pad button.is-held { background: #46616a; }
.direction-pad [data-direction="up"], .direction-pad [data-hole-dir="up"] { grid-area: up; }
.direction-pad [data-direction="down"], .direction-pad [data-hole-dir="down"] { grid-area: down; }
.direction-pad [data-direction="left"], .direction-pad [data-hole-dir="left"] { grid-area: left; }
.direction-pad [data-direction="right"], .direction-pad [data-hole-dir="right"] { grid-area: right; }

.direction-pad i {
  width: 9px;
  height: 9px;
  border: solid var(--ink);
  border-width: 2px 0 0 2px;
  transform: translateY(2px) rotate(45deg);
}

[data-direction="down"] i, [data-hole-dir="down"] i { transform: translateY(-2px) rotate(225deg); }
[data-direction="left"] i, [data-hole-dir="left"] i { transform: translateX(2px) rotate(-45deg); }
[data-direction="right"] i, [data-hole-dir="right"] i { transform: translateX(-2px) rotate(135deg); }

.touch-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.touch-actions button { padding-inline: 10px; font-size: 0.84rem; touch-action: manipulation; }
.touch-actions .switch { grid-column: 1 / -1; }
.touch-actions .jump {
  border-color: var(--gold);
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hole-popup {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(18, 28, 33, 0.78);
}

.hole-dialog {
  width: min(500px, 100%);
  max-height: 94vh;
  overflow: auto;
  padding: 14px;
  border: 2px solid var(--line);
  background: var(--page);
  display: grid;
  gap: 10px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.hole-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hole-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 720;
  color: var(--gold);
}

.hole-header p {
  margin: 3px 0 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.hole-close, .hole-hook {
  min-height: 40px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  background: var(--control);
  font-size: 0.84rem;
  white-space: nowrap;
}

.hole-close:hover, .hole-hook:hover:not(:disabled) { background: #344c55; }
.hole-hook:disabled { opacity: 0.48; cursor: not-allowed; }
.hole-hook:not(:disabled) { border-color: var(--gold); color: #282e2b; background: var(--gold); }

#hole-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  image-rendering: pixelated;
  touch-action: none;
  border: 1px solid var(--line);
  background: #2c241c;
}

.hole-footer { display: grid; gap: 8px; }
.hole-touch-pad { display: none; }
.hole-controls-note { margin: 0; color: var(--muted); font-size: 0.8rem; }

@media (pointer: coarse), (max-width: 620px) {
  .touch-controls { display: grid; margin-top: 13px; }
  .hole-touch-pad { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  [data-mode="duo"] .touch-controls { grid-template-columns: 1fr 1fr; gap: 12px; }
  [data-mode="duo"] .touch-pad:nth-child(2) { justify-items: end; }
  [data-mode="duo"] .touch-pad:nth-child(2) .touch-actions { order: -1; }
}

@media (pointer: coarse) {
  .key-guide, .hole-controls-note { display: none; }
  .mode button, .levels button, .restart, .result-actions button, .hole-close, .hole-hook { min-height: 44px; }
}

@media (max-width: 620px) {
  .game { width: calc(100% - 22px); padding-top: 14px; }
  .masthead { flex-wrap: wrap; margin-bottom: 5px; }
  .mode button { padding-inline: 10px; }
  .levels { gap: 1px; }
  .levels button, .restart { padding-inline: 6px; font-size: 0.79rem; }
  .levels button span { margin-right: 2px; }
  .game-status p { font-size: 0.87rem; }
  .hole-dialog { padding: 10px; gap: 8px; }
  .hole-header h2 { font-size: 0.96rem; }
  .hole-header p { font-size: 0.8rem; }
  [data-mode="duo"] .touch-buttons { display: grid; justify-items: start; gap: 6px; }
  [data-mode="duo"] .touch-pad:nth-child(2) .touch-buttons { justify-items: end; }
  [data-mode="duo"] .touch-actions { grid-template-columns: 1fr 1fr; }
  [data-mode="duo"] .touch-pad:nth-child(2) .touch-actions { order: 0; }
}

@media (max-width: 345px) {
  .toolbar { flex-wrap: wrap; }
  .direction-pad { grid-template-columns: repeat(3, clamp(36px, 13.2vw, 42px)); }
}
