* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #1a2f1a;
  --panel: #24402a;
  --text: #e8f5e0;
  --gold: #ffd75e;
  --orange: #ff8c42;
  --orange-dark: #c9641f;
}
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
#wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 8px 8px;
}
.tb-side #wrap { padding: 8px 60px 8px 8px; }
canvas {
  display: block;
  background: #7cb95c;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}

/* Værktøjslinje: info, lyd, fuld skærm og pause */
#toolbar {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 20;
}
.tb-side #toolbar { flex-direction: column; }
.tool {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.tool:hover { background: rgba(255,255,255,.26); }
.tool:active { transform: scale(.92); }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
#pauseBtn { display: none; }
[data-state=playing] #pauseBtn, [data-state=paused] #pauseBtn { display: block; }

/* Prutteknap og joystick på touchskærme */
#fartBtn {
  display: none;
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border: none;
  border-radius: 50%;
  background: rgba(255,140,66,.85);
  box-shadow: 0 4px 0 var(--orange-dark), 0 6px 20px rgba(0,0,0,.4);
  font-size: 2.4rem;
  z-index: 15;
  touch-action: none;
  transition: opacity .15s;
}
#fartBtn.cd { opacity: .4; }
#fartBtn.mega { background: rgba(120,220,70,.95); box-shadow: 0 4px 0 #4f9a2a, 0 0 28px rgba(150,255,90,.8); animation: pulse .6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
@media (pointer: coarse) {
  [data-state=playing] #fartBtn { display: block; }
}
#stick {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.08);
  pointer-events: none;
  z-index: 14;
}
#stick.on { display: block; }
#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* Skærme oven på spillet */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #fff;
  background: rgba(20, 35, 20, .62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 64px 16px 16px;
  z-index: 10;
  overflow-y: auto;
  touch-action: pan-y;
  animation: fadein .2s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.overlay.hidden { display: none; }
.card {
  margin: auto;
  width: min(560px, 100%);
  padding: clamp(18px, 4vh, 32px) clamp(16px, 4vw, 32px);
  border-radius: 20px;
  background: rgba(30, 52, 34, .88);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  animation: popin .25s ease-out;
}
@keyframes popin { from { transform: scale(.94); opacity: 0; } }
.overlay h1 { font-size: clamp(1.8rem, min(7vw, 8vh), 3.2rem); line-height: 1.15; margin-bottom: .3em; }
.overlay h1 .fox { display: inline-block; animation: bounce 1.2s infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.overlay p { font-size: clamp(.95rem, 2.6vw, 1.15rem); line-height: 1.45; margin: 0 auto .7em; max-width: 480px; color: var(--text); }
.overlay .tagline { font-size: clamp(1rem, 3vw, 1.25rem); }
.overlay .score-big { font-size: clamp(1.5rem, 5vw, 2.2rem); margin-bottom: .2em; color: #fff; }
.overlay .rank { font-weight: 600; }
.overlay .stats { font-size: .95rem; opacity: .85; margin-top: .6em; }
.overlay .record { color: var(--gold); font-weight: bold; }
.overlay .record:empty, .overlay .hint:empty { display: none; }
.overlay .record.new { font-size: 1.3em; animation: glow 1s ease-in-out infinite alternate; }
@keyframes glow { from { text-shadow: 0 0 4px rgba(255,215,94,.4); transform: scale(1); } to { text-shadow: 0 0 18px rgba(255,215,94,.9); transform: scale(1.06); } }
.hint { font-size: .85rem !important; opacity: .75; }
.brand { margin: 1.2em 0 0; font-size: .8rem; color: rgba(255,255,255,.5); }

button.big {
  font-size: clamp(1.1rem, 3.5vw, 1.4rem);
  font-weight: bold;
  padding: 14px 44px;
  border: none;
  border-radius: 50px;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--orange-dark);
  transition: transform .08s, filter .15s;
  margin: 6px 0 4px;
}
button.big:hover { filter: brightness(1.08); }
button.big:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--orange-dark); }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }
button.ghost {
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 18px;
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 50px;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
button.ghost:hover { background: rgba(255,255,255,.1); }
button.link {
  margin-top: 14px;
  border: none;
  background: none;
  color: var(--gold);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
button.link.inline { margin: 0 0 0 4px; font-size: inherit; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 16px; }
.chip { font-size: .85rem; padding: 5px 10px; border-radius: 50px; background: rgba(255,255,255,.1); color: var(--text); }
kbd { background: rgba(255,255,255,.15); border-radius: 4px; padding: 0 5px; font-family: inherit; }
.touch-only, .rotate-hint { display: none !important; }
@media (pointer: coarse) {
  .kbd-only { display: none !important; }
  .touch-only { display: flex !important; }
}
@media (pointer: coarse) and (orientation: portrait) {
  .rotate-hint { display: block !important; margin-top: 12px; color: var(--gold); }
}

.progress { width: min(320px, 100%); height: 10px; margin: 4px auto 6px; border-radius: 5px; background: rgba(0,0,0,.35); overflow: hidden; }
.progress .fill { height: 100%; width: 0; border-radius: 5px; background: linear-gradient(90deg, var(--orange), var(--gold)); transition: width .8s ease-out; }

/* Info-boks med regler */
#info {
  margin: auto;
  width: min(600px, calc(100% - 32px));
  max-height: min(86vh, 760px);
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  overflow: hidden;
  -webkit-user-select: text;
  user-select: text;
  touch-action: pan-y;
}
#info[open] { display: flex; animation: popin .2s ease-out; }
#info::backdrop { background: rgba(10, 20, 10, .7); }
.info-inner {
  flex: 1;
  overflow-y: auto;
  padding: 0 22px 22px;
  line-height: 1.5;
  overscroll-behavior: contain;
}
.info-inner header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 12px;
  background: var(--panel);
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.info-inner h2 { font-size: 1.4rem; color: #fff; }
.info-inner h3 { font-size: 1.05rem; color: var(--gold); margin: 1.1em 0 .3em; }
.info-inner p, .info-inner li, .info-inner td, .info-inner th { font-size: .98rem; }
.info-inner ul { padding-left: 1.2em; }
.info-inner li { margin-bottom: .25em; }
.info-inner table { border-collapse: collapse; width: 100%; }
.info-inner th { text-align: left; padding: 4px 12px 4px 0; vertical-align: top; color: #fff; white-space: nowrap; }
.info-inner td { padding: 4px 0; }
.info-inner .ranks { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 12px; }
.info-inner .ranks b { display: inline-block; min-width: 2.4em; color: var(--gold); }
.info-inner .small { margin-top: 1.2em; font-size: .85rem; opacity: .8; }
.close {
  flex: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}
.close:hover { background: rgba(255,255,255,.25); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
