* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #3c463f;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #1f2a22; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: none; overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.hidden { display: none !important; }

button {
  font: inherit; font-weight: 800; border: 0; cursor: pointer; border-radius: 12px;
  padding: 10px 16px; background: #e9ecef; color: #26302a; box-shadow: 0 4px 0 #b8bfc4;
  transition: transform .06s, box-shadow .06s; touch-action: manipulation;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8bfc4; }
button:disabled { opacity: .45; cursor: default; }
button.big { font-size: 22px; padding: 14px 28px; background: #ffb627; box-shadow: 0 5px 0 #c98400; color: #3a2500; }
button.big:active { box-shadow: 0 2px 0 #c98400; }

.coin { display: inline-block; width: .9em; height: .9em; border-radius: 50%; vertical-align: -0.1em; margin-right: .25em;
  background: radial-gradient(circle at 35% 35%, #fff4b0, #ffc93c 45%, #d68f00); box-shadow: inset 0 0 0 1.5px #b87900; }

/* overlays */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(30, 45, 35, .35); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  overflow-y: auto; touch-action: pan-y;
}
.panel {
  background: #fffdf6; border-radius: 22px; padding: 22px 24px; width: min(640px, 100%);
  box-shadow: 0 10px 0 rgba(0,0,0,.18), 0 20px 60px rgba(0,0,0,.25); margin: auto;
}
.panel.small { width: min(440px, 100%); text-align: center; }
h1 { margin: 0; font-size: 64px; line-height: 1; letter-spacing: -2px; color: #2f6b3a; text-align: center; }
h1 span { color: #ffb627; }
h2 { margin: 0 0 6px; font-size: 40px; color: #c0392b; }
.tag { text-align: center; margin: 6px 0 14px; color: #5d6b61; font-weight: 600; }
.hero { display: flex; gap: 18px; align-items: center; justify-content: center; }
#preview { width: 120px; height: 120px; flex: none; }
.col { display: flex; flex-direction: column; gap: 10px; flex: 1; max-width: 300px; }
input#name {
  font: inherit; font-size: 18px; font-weight: 700; padding: 12px 14px; border-radius: 12px; border: 3px solid #d9ddd6;
  outline: none; background: #fff; user-select: text; -webkit-user-select: text;
}
input#name:focus { border-color: #ffb627; }
.coins { font-weight: 800; font-size: 18px; }
.coins .best { color: #7a867d; font-size: 14px; margin-left: 8px; }

.tabs { display: flex; gap: 6px; margin: 18px 0 10px; flex-wrap: wrap; }
.tabs button { flex: 1; padding: 8px 6px; font-size: 15px; }
.tabs button.on { background: #2f6b3a; color: #fff; box-shadow: 0 4px 0 #1d4425; }

#shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.card { background: #f1f3ee; border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; }
.card .nm { font-weight: 800; font-size: 15px; }
.card .ds { font-size: 12px; color: #66736a; min-height: 2.4em; }
.card button { width: 100%; padding: 8px; font-size: 14px; }
.card button.eq { background: #2f6b3a; color: #fff; box-shadow: 0 4px 0 #1d4425; }
.card canvas { width: 64px; height: 64px; }
.pips { display: flex; gap: 4px; }
.pips i { width: 14px; height: 8px; border-radius: 4px; background: #d3d8cf; }
.pips i.on { background: #ffb627; }
.swatch { width: 48px; height: 48px; border-radius: 12px; }
.help { font-size: 13px; color: #66736a; margin: 16px 0 0; text-align: center; line-height: 1.5; }

#overStats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
#overStats div { background: #f1f3ee; border-radius: 12px; padding: 10px; }
#overStats b { display: block; font-size: 24px; }
#overStats span { font-size: 12px; color: #66736a; font-weight: 700; text-transform: uppercase; }
#overStats .wide { grid-column: span 2; background: #fff3d0; }
.joke { font-style: italic; color: #5d6b61; margin: 6px 0 16px; }
.btnrow { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#overReason { font-weight: 700; margin: 0; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#stats {
  position: absolute; left: max(12px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top));
  background: rgba(255,255,255,.88); border-radius: 14px; padding: 8px 14px; box-shadow: 0 4px 0 rgba(0,0,0,.15);
}
#pct { font-size: 30px; font-weight: 900; line-height: 1.1; }
#sub { font-size: 14px; font-weight: 700; color: #4d5a51; }
#sub .dot { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: #9aa59d; vertical-align: middle; margin: 0 4px; }
.shield { display: inline-block; background: #3aa0ff; color: #fff; border-radius: 8px; padding: 0 6px; margin-left: 6px; font-size: 12px; }
#board {
  position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top));
  margin: 0; padding: 8px 10px; list-style: none; background: rgba(255,255,255,.88); border-radius: 14px;
  min-width: 190px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 0 rgba(0,0,0,.15);
}
#board li { display: flex; align-items: center; gap: 6px; padding: 2px 0; white-space: nowrap; }
#board li i { width: 12px; height: 12px; border-radius: 4px; flex: none; }
#board li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
#board li .r { color: #8a958d; width: 1.6em; }
#board li.me { color: #c76f00; }
#feed {
  position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 14px;
}
#feed div { background: rgba(255,255,255,.85); padding: 4px 10px; border-radius: 10px; animation: feedIn .25s ease-out; }
@keyframes feedIn { from { transform: translateX(-20px); opacity: 0; } }
#minimap {
  position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
  width: 150px; height: 150px; border-radius: 12px; border: 3px solid rgba(255,255,255,.9); box-shadow: 0 4px 0 rgba(0,0,0,.15);
}
#stick {
  position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%;
  background: rgba(255,255,255,.18); border: 3px solid rgba(255,255,255,.45); display: none;
}
#stick.on { display: block; }
#knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255,255,255,.7); }

/* phones */
@media (max-width: 600px), (max-height: 500px) {
  h1 { font-size: 48px; }
  .panel { padding: 16px; border-radius: 18px; }
  .hero { gap: 12px; }
  #preview { width: 90px; height: 90px; }
  button.big { font-size: 19px; padding: 12px 20px; }
  #shop { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
  #pct { font-size: 22px; }
  #sub { font-size: 12px; }
  #stats { padding: 6px 10px; }
  #board { min-width: 0; font-size: 12px; padding: 6px 8px; }
  #board li .n { max-width: 90px; }
  #minimap { width: 96px; height: 96px; }
  #feed { font-size: 12px; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 0px); max-width: 55vw; }
  h2 { font-size: 32px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .tag, .help { display: none; }
  .tabs { margin: 10px 0 8px; }
}
@media (max-height: 500px) {
  #overStats { grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
  #overStats .wide { grid-column: span 4; }
  #overStats b { font-size: 18px; }
  #overStats div { padding: 6px; }
  .joke { margin: 4px 0 10px; font-size: 13px; }
  .panel.small { width: min(620px, 100%); }
}
button.mini { font-size: 12px; padding: 4px 9px; border-radius: 8px; box-shadow: 0 2px 0 #b8bfc4; margin-left: 6px; vertical-align: 2px; }
