:root {
  --paper: #f7f2e7;
  --ink: #2b2a28;
  --ink-soft: #5d5a54;
  --accent: #e5484d;
  --accent-2: #2f6fd6;
  --card: rgba(255, 252, 244, 0.94);
  --hand: "Segoe Print", "Chalkboard SE", "Comic Sans MS", "Comic Neue", cursive, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper) url("assets/tiles/tile-ivory-flecks.webp") 0 0 / 420px auto repeat;
  color: var(--ink);
  font-family: var(--hand);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { display: grid; place-items: center; }

#stage {
  position: relative;
  width: min(100vw, 75vh);
  width: min(100vw, 75dvh);
  aspect-ratio: 3 / 4;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 4px 28px rgba(60, 50, 30, 0.22);
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: none;
  background: #e7eedc;
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4% 6%;
  text-align: center;
  overflow-y: auto;
}

#overlay:empty { display: none; }

.card {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 18px 14px 20px 12px;
  box-shadow: 3px 4px 0 rgba(43, 42, 40, 0.25);
  padding: 18px 22px;
  max-width: 100%;
}

.card.wide { width: 100%; }

.logo { width: min(80%, 420px); height: auto; display: block; margin: 0 auto; }

h1, h2 { margin: 0.2em 0 0.3em; font-weight: 700; line-height: 1.1; }
h1 { font-size: clamp(26px, 6.5vmin, 46px); color: var(--accent); transform: rotate(-2deg); }
h2 { font-size: clamp(22px, 5vmin, 36px); }

p { margin: 0.4em 0; font-size: clamp(13px, 2.4vmin, 17px); line-height: 1.35; }
.help { color: var(--ink-soft); }
.about-link { margin-top: 0.8em; }
.about-link a { color: var(--ink-soft); }
.about-link a:hover { color: var(--ink); }
.loading { font-size: clamp(18px, 4vmin, 28px); }

.bar { width: min(70%, 320px); height: 14px; border: 2px solid var(--ink); border-radius: 8px; margin: 10px auto; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent-2); transition: width 0.15s; }

button {
  font-family: var(--hand);
  color: var(--ink);
  cursor: pointer;
}

.btn {
  font-size: clamp(17px, 3.6vmin, 24px);
  font-weight: 700;
  background: #ffd84a;
  border: 2px solid var(--ink);
  border-radius: 14px 10px 16px 9px;
  padding: 8px 22px;
  margin: 8px 6px 2px;
  box-shadow: 2px 3px 0 rgba(43, 42, 40, 0.35);
}
.btn:hover { background: #ffe57d; }
.btn:active { transform: translate(1px, 2px); box-shadow: 1px 1px 0 rgba(43, 42, 40, 0.35); }
.btn.secondary { background: #fff; }
.btn:focus-visible, .pick:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.top5 { list-style: none; padding: 0; margin: 8px auto 0; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.top5 li { display: flex; flex-direction: column; align-items: center; font-size: clamp(12px, 2.2vmin, 15px); }
.top5 img { height: clamp(30px, 6vmin, 44px); width: auto; }
.top5 .mine { color: var(--accent); font-weight: 700; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(58px, 13vmin, 92px), 1fr));
  gap: 8px;
  width: 100%;
  max-height: 64vmin;
  overflow-y: auto;
  padding: 6px;
}

.pick {
  background: #fff;
  border: 2px solid rgba(43, 42, 40, 0.35);
  border-radius: 12px 9px 14px 8px;
  padding: 6px 2px;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pick img { max-width: 92%; max-height: 92%; }
.pick:hover { border-color: var(--ink); transform: rotate(-2deg); }
.pick[aria-pressed="true"] { border-color: var(--accent); border-width: 3px; background: #fff6e0; }

#hud-buttons {
  position: absolute;
  right: 1.2%;
  bottom: 1.2%;
  display: flex;
  gap: 6px;
}
#hud-buttons button, #btn-bomb {
  width: clamp(34px, 7vmin, 46px);
  height: clamp(34px, 7vmin, 46px);
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(255, 252, 244, 0.85);
  font-size: clamp(14px, 3vmin, 20px);
  line-height: 1;
  padding: 0;
}
#btn-mute[aria-pressed="true"] { text-decoration: line-through; opacity: 0.6; }

#btn-bomb {
  position: absolute;
  left: 2%;
  bottom: 2%;
  width: clamp(58px, 15vmin, 84px);
  height: clamp(58px, 15vmin, 84px);
  font-size: clamp(26px, 7vmin, 40px);
  touch-action: none;
}

[hidden] { display: none !important; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 22px; }

@media (prefers-reduced-motion: reduce) {
  h1, .pick:hover { transform: none; }
}
