:root {
  --poo: #6b3d1a;
  --poo-dark: #3b2412;
  --cream: #fff6e3;
  --gold: #ffc61a;
  --red: #d7262b;
  --green: #2f8a3a;
  --font: "Luckiest Guy", Impact, "Arial Black", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #241508;
  background-image: radial-gradient(circle at 20% 20%, #4a2c14 0, transparent 40%),
                    radial-gradient(circle at 80% 70%, #3d2410 0, transparent 45%);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #7ec8f0;
  box-shadow: 0 0 60px rgba(0, 0, 0, .6);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* HUD */
#hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 14px;
  pointer-events: none;
  font-family: var(--font);
  text-shadow: 0 3px 0 var(--poo-dark), 0 0 8px rgba(0,0,0,.4);
}
.hud-score { font-size: 42px; line-height: 1; color: #fff; letter-spacing: 1px; }
.hud-sub { font-size: 18px; color: var(--gold); margin-top: 2px; }
.shroomicon { width: 16px; height: 18px; margin-right: 4px; vertical-align: -2px; }

.corner-btns {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 20;
}
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 3px solid var(--poo-dark);
  background: rgba(255, 246, 227, .9);
  color: var(--poo-dark);
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  padding: 0;
}

/* Landmark / hazard caption */
.caption {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  padding: 8px 14px 7px;
  border-radius: 14px;
  border: 3px solid #fff;
  background: #6b3a1f;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .35);
  text-align: center;
  pointer-events: none;
  z-index: 5;
}
.caption.show { animation: capIn .3s cubic-bezier(.2, 1.5, .5, 1); }
@keyframes capIn { from { transform: translate(-50%, 120%); } to { transform: translate(-50%, 0); } }
.caption .cap-title { font-family: var(--font); font-size: 24px; line-height: 1.1; color: #fff; }
.caption .cap-fact { font-size: 14px; font-weight: 700; color: #ffe9c9; margin-top: 2px; }
.caption.warn { background: var(--red); border-color: var(--gold); }
.caption.warn .cap-title { color: var(--gold); font-size: 26px; }
.caption.warn .cap-fact { color: #fff; }

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 60px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: radial-gradient(ellipse at center, rgba(59,36,18,.55), rgba(36,21,8,.85));
  z-index: 10;
  overflow-y: auto;
}
.panel {
  width: 100%;
  max-width: 420px;
  text-align: center;
  animation: pop .35s cubic-bezier(.2, 1.6, .5, 1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.kicker {
  font-family: var(--font);
  color: var(--gold);
  font-size: 15px;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 var(--poo-dark);
}
h1 {
  font-family: var(--font);
  font-weight: normal;
  margin: 6px 0 14px;
  line-height: .9;
  transform: rotate(-3deg);
}
h1 .t1 { display: block; font-size: 34px; color: #fff; text-shadow: 0 4px 0 var(--poo-dark); }
h1 .t2 {
  display: block;
  font-size: 64px;
  color: #a8652c;
  -webkit-text-stroke: 3px var(--poo-dark);
  text-shadow: 0 6px 0 var(--poo-dark), 0 0 30px rgba(255, 198, 26, .6);
  animation: wobble 1.6s ease-in-out infinite;
}
@keyframes wobble { 0%,100% { transform: rotate(-2deg) scale(1); } 50% { transform: rotate(2deg) scale(1.06); } }

h2 {
  font-family: var(--font);
  font-weight: normal;
  font-size: 56px;
  margin: 0 0 6px;
  color: #a8652c;
  -webkit-text-stroke: 2px var(--poo-dark);
  text-shadow: 0 5px 0 var(--poo-dark);
}
.board-title { font-size: 46px; line-height: .95; color: var(--gold); }
.board-title small { font-size: 26px; color: #fff; }

.howto {
  background: rgba(255, 246, 227, .95);
  color: var(--poo-dark);
  border-radius: 16px;
  border: 4px solid var(--poo-dark);
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.45;
  margin: 0 auto 16px;
  box-shadow: 0 6px 0 var(--poo-dark);
}
.howto .warn { color: var(--red); font-weight: 800; margin: 4px 0; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Title: name at the top, buttons at the bottom, demo run visible in between */
.title-screen {
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding-top: calc(env(safe-area-inset-top, 0px) + 50px);
  background: linear-gradient(to bottom,
    rgba(36, 21, 8, .72) 0%, rgba(36, 21, 8, 0) 30%,
    rgba(36, 21, 8, 0) 60%, rgba(36, 21, 8, .88) 100%);
}
.title-top h1 { margin-bottom: 0; }
.title-top .t1 { font-size: 30px; }
.title-top .t2 { font-size: 56px; }
.title-bottom .howto { margin-bottom: 8px; padding: 8px 12px; }
.title-bottom .big-btn { margin: 4px 0 12px; }
.title-bottom .best { margin-top: 8px; }
@media (max-height: 640px) {
  .title-top .t2 { font-size: 46px; }
  .title-bottom .keys { display: none; }
}

/* How to play */
.screen-top { align-items: flex-start; }
.help-panel { padding-bottom: 8px; }
.help-title { font-size: 46px; color: var(--gold); }
.help-controls {
  display: grid;
  gap: 6px;
  margin: 4px 0 14px;
  text-align: left;
  font-weight: 700;
  font-size: 15px;
}
.help-controls .key {
  display: inline-block;
  min-width: 52px;
  margin-right: 10px;
  padding: 4px 6px 2px;
  border-radius: 8px;
  border: 2px solid var(--poo-dark);
  background: var(--gold);
  color: var(--poo-dark);
  font-family: var(--font);
  font-size: 18px;
  text-align: center;
}
.help-sec {
  margin: 0 0 14px;
  padding: 10px 10px 4px;
  border-radius: 16px;
  border: 4px solid var(--poo-dark);
  background: rgba(255, 246, 227, .96);
  box-shadow: 0 5px 0 var(--poo-dark);
  color: var(--poo-dark);
  text-align: left;
}
.help-sec h3 {
  margin: 0 0 6px;
  font-family: var(--font);
  font-weight: normal;
  font-size: 22px;
  letter-spacing: .5px;
}
.help-sec.bad h3 { color: var(--red); }
.help-sec.good h3 { color: #2f8a3a; }
.help-item { display: flex; align-items: center; gap: 10px; padding: 4px 0 6px; border-top: 2px dashed rgba(59, 36, 18, .18); }
.help-sec h3 + .help-item { border-top: 0; }
.help-item canvas { flex: 0 0 72px; width: 72px; height: 72px; border-radius: 12px; background: #c9c4ba; }
.help-item b { display: block; font-family: var(--font); font-weight: normal; font-size: 19px; line-height: 1.1; }
.help-item span { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }

.big-btn {
  display: block;
  width: 100%;
  font-family: var(--font);
  font-size: 40px;
  padding: 12px 10px 6px;
  border-radius: 18px;
  border: 4px solid var(--poo-dark);
  background: linear-gradient(#ffd84d, #ffb400);
  color: var(--poo-dark);
  box-shadow: 0 7px 0 var(--poo-dark);
  cursor: pointer;
  margin: 8px 0 14px;
  animation: pulse 1.2s ease-in-out infinite;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--poo-dark); }
@keyframes pulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.12); } }

.small-btn, .save-btn {
  font-family: var(--font);
  font-size: 20px;
  padding: 8px 18px 4px;
  border-radius: 12px;
  border: 3px solid var(--poo-dark);
  background: var(--cream);
  color: var(--poo-dark);
  box-shadow: 0 4px 0 var(--poo-dark);
  cursor: pointer;
}
.small-btn:active, .save-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--poo-dark); }
.save-btn { background: linear-gradient(#5fd35f, #2f9a35); color: #fff; text-shadow: 0 2px 0 var(--poo-dark); }
.save-btn:disabled { filter: grayscale(1) opacity(.6); }

.best, .keys { margin-top: 12px; font-family: var(--font); color: var(--gold); font-size: 18px; text-shadow: 0 2px 0 var(--poo-dark); }
.keys { font-family: inherit; font-size: 12px; color: rgba(255, 246, 227, .7); text-shadow: none; }
@media (hover: none) { .keys { display: none; } }
.credit {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: 0;
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  color: rgba(255, 246, 227, .75);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.about {
  margin: 4px 0 16px;
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  border-radius: 16px;
  border: 4px solid var(--poo-dark);
  background: rgba(255, 246, 227, .96);
  box-shadow: 0 5px 0 var(--poo-dark);
  color: var(--poo-dark);
}
.about h3 { margin: 0 0 6px; font-family: var(--font); font-weight: normal; color: #a65f00; font-size: 22px; }
.about p { margin: 0 0 8px; }
.about p:last-child { margin-bottom: 0; }

.msg { font-size: 17px; margin: 0 0 12px; font-weight: 700; }
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.stats div {
  background: rgba(255, 246, 227, .95);
  color: var(--poo-dark);
  border: 3px solid var(--poo-dark);
  border-radius: 12px;
  padding: 6px 4px 4px;
}
.stats span { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.stats b { font-family: var(--font); font-weight: normal; font-size: 28px; }

#saveForm label { display: block; font-family: var(--font); font-size: 20px; color: var(--gold); text-shadow: 0 2px 0 var(--poo-dark); margin-bottom: 6px; }
.save-row { display: flex; gap: 10px; justify-content: center; align-items: stretch; }
#initials {
  width: 150px;
  font-family: var(--font);
  font-size: 40px;
  letter-spacing: 10px;
  text-align: center;
  text-transform: uppercase;
  padding: 8px 0 2px 10px;
  border-radius: 12px;
  border: 4px solid var(--poo-dark);
  background: #fff;
  color: var(--poo-dark);
  outline: none;
}
#initials:focus { box-shadow: 0 0 0 4px var(--gold); }
.err { min-height: 20px; color: #ffb3b3; font-weight: 700; font-size: 14px; margin-top: 6px; }

.board-list {
  list-style: none;
  margin: 10px 0 6px;
  padding: 0;
  counter-reset: rank;
  background: rgba(255, 246, 227, .96);
  border: 4px solid var(--poo-dark);
  border-radius: 16px;
  box-shadow: 0 6px 0 var(--poo-dark);
  overflow: hidden;
  color: var(--poo-dark);
}
.board-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  padding: 6px 14px 3px;
  font-family: var(--font);
  font-size: 24px;
  border-bottom: 2px dashed rgba(59, 36, 18, .25);
}
.board-list li:last-child { border-bottom: 0; }
.board-list li::before { content: counter(rank); width: 36px; text-align: left; color: #a8652c; }
.board-list li:nth-child(1)::before { content: "👑"; }
.board-list li .ini { flex: 1; text-align: left; letter-spacing: 4px; }
.board-list li.me { background: var(--gold); animation: flash .5s ease-in-out 4; }
.board-list li.empty { justify-content: center; font-size: 18px; color: #a8652c; }
.board-list li.empty::before { content: none; }
@keyframes flash { 50% { background: #fff; } }
.board-mode { font-size: 12px; color: rgba(255, 246, 227, .75); margin-bottom: 8px; }
