:root {
  --stone: none;          /* set from the generated textures in main.js */
  --dirt: none;
  --text: #ffffff;
  --muted: #b8b8b8;
  --gold: #ffd83a;
  --yellow: #ffff55;
  --red: #ff5555;
  --green: #55ff55;
  --font: 'VT323', ui-monospace, monospace;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #86b8ff;
  color: var(--text);
  font-family: var(--font);
  font-size: 22px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 18px; }
.center { text-align: center; }

/* ------------------------------------------------------------ screens & panels */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.screen.dim { background: rgba(0, 0, 0, 0.55); }
.screen.dead { background: rgba(140, 0, 0, 0.45); animation: fade-in 0.5s ease-out; }

#screen-menu { justify-content: flex-end; padding-right: max(16px, 7vw); }

.menu-panel {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 22px;
  background-color: #2a2018;
  background-image: linear-gradient(rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.62)), var(--dirt);
  background-size: auto, 64px 64px;
  image-rendering: pixelated;
  border: 3px solid #000;
  box-shadow: inset 3px 3px 0 rgba(255, 255, 255, 0.18), inset -3px -3px 0 rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel.narrow { width: min(420px, 100%); }
.panel.wide { width: min(640px, 100%); }
.panel.side { margin-left: auto; }
.panel-plain { display: flex; flex-direction: column; gap: 10px; align-items: center; width: min(420px, 100%); }

h2 {
  font-family: var(--pixel);
  font-size: 20px;
  margin: 0;
  text-align: center;
  text-shadow: 3px 3px 0 #3f3f3f;
  line-height: 1.4;
}

.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { text-align: left; }

/* ------------------------------------------------------------ logo */

.logo {
  position: relative;
  margin: 0 0 6px;
  text-align: center;
  line-height: 1;
}
.logo-main {
  display: block;
  font-family: var(--pixel);
  font-size: clamp(30px, 7.2vw, 46px);
  letter-spacing: 2px;
  color: #c6c6c6;
  background-image: var(--stone);
  background-size: 32px 32px;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(3px 3px 0 #1d1d1d) drop-shadow(0 4px 0 #3a3a3a);
}
.logo-sub {
  display: block;
  margin-top: 10px;
  font-family: var(--pixel);
  font-size: clamp(18px, 4vw, 24px);
  letter-spacing: 12px;
  color: #8b5a33;
  text-shadow: 3px 3px 0 #2b1a0c;
}
.splash {
  position: absolute;
  right: -6px;
  bottom: -14px;
  font-family: var(--font);
  font-size: 24px;
  color: var(--yellow);
  text-shadow: 2px 2px 0 #3f3f00;
  transform: rotate(-16deg);
  animation: splash 0.5s ease-in-out infinite alternate;
  white-space: nowrap;
  pointer-events: none;
}
@keyframes splash { from { transform: rotate(-16deg) scale(1); } to { transform: rotate(-16deg) scale(1.08); } }

/* ------------------------------------------------------------ Minecraft-style buttons & inputs */

.btn-stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.narrow-stack { width: min(360px, 100%); margin-top: 8px; }

.mc-btn {
  width: 100%;
  min-height: 46px;
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 26px;
  color: #e0e0e0;
  text-shadow: 2px 2px 0 #383838;
  background-color: #6f6f6f;
  background-image: linear-gradient(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.12)), var(--stone);
  background-size: auto, 64px 64px;
  image-rendering: pixelated;
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.35), inset -2px -4px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.mc-btn:hover, .mc-btn:focus-visible {
  outline: none;
  color: #ffffa0;
  background-color: #7b86c8;
  background-image: linear-gradient(rgba(70, 90, 200, 0.45), rgba(70, 90, 200, 0.45)), var(--stone);
  border-color: #fff;
}
.mc-btn:active { transform: translateY(1px); }
.mc-btn:disabled {
  color: #9a9a9a;
  background: #2b2b2b;
  border-color: #000;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}
.mc-btn.big { min-height: 54px; font-size: 30px; }
.mc-btn.small-btn { min-height: 34px; font-size: 20px; padding: 2px 8px; }
.mc-btn.green { background-image: linear-gradient(rgba(40, 160, 40, 0.45), rgba(40, 160, 40, 0.45)), var(--stone); }

.icon-btn {
  width: 46px; height: 46px;
  font-family: var(--pixel);
  font-size: 14px;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.6);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.65); }
.icon-btn.mute { position: fixed; left: 16px; top: 16px; font-family: var(--font); font-size: 26px; }
body.in-game .icon-btn.mute { display: none; }
.icon-btn.mute.off { color: #777; text-decoration: line-through; }

label { display: flex; flex-direction: column; gap: 4px; color: #a0a0a0; font-size: 20px; }
input {
  font-family: var(--font);
  font-size: 24px;
  padding: 6px 10px;
  color: #fff;
  background: #000;
  border: 2px solid #a0a0a0;
  outline: none;
  user-select: text;
}
input:focus { border-color: #fff; }
form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--red); margin: 0; min-height: 1em; font-size: 20px; }

.tabs { display: flex; gap: 6px; }
.tab {
  flex: 1;
  padding: 6px;
  font-family: var(--font);
  font-size: 22px;
  color: #aaa;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #333;
  cursor: pointer;
}
.tab.active { color: #fff; border-color: #fff; background: rgba(255, 255, 255, 0.1); }

/* ------------------------------------------------------------ account bar & hints */

.account-bar {
  min-height: 30px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 14px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 21px;
}
.account-bar b { color: var(--yellow); font-weight: normal; }
.account-bar .guest { color: #ddd; }

.controls-hint {
  margin: 4px 0 0;
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1.3;
  text-align: center;
  color: #eee;
  background: rgba(0, 0, 0, 0.4);
}
.controls-hint b { color: var(--yellow); font-weight: normal; }
.touch-only { display: none; }

/* ------------------------------------------------------------ coins */

.coin-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  vertical-align: -2px;
  background: var(--gold);
  box-shadow: inset -3px -3px 0 #c98f12, inset 3px 3px 0 #fff3a0;
  clip-path: polygon(25% 0, 75% 0, 75% 12%, 88% 12%, 88% 25%, 100% 25%, 100% 75%, 88% 75%, 88% 88%, 75% 88%, 75% 100%, 25% 100%, 25% 88%, 12% 88%, 12% 75%, 0 75%, 0 25%, 12% 25%, 12% 12%, 25% 12%);
}
.balance { font-size: 26px; color: var(--gold); text-shadow: 2px 2px 0 #3f2f00; }

/* ------------------------------------------------------------ skins */

.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding: 2px;
}
.skin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #3a3a3a;
  cursor: pointer;
  text-align: center;
}
.skin-card:hover { border-color: #888; }
.skin-card.previewing { border-color: #fff; background: rgba(255, 255, 255, 0.08); }
.skin-card.equipped { border-color: var(--green); }
.skin-card canvas { width: 72px; height: 84px; image-rendering: pixelated; }
.skin-card.locked canvas { filter: grayscale(0.8) brightness(0.55); }
.skin-name { font-size: 22px; color: #fff; }
.skin-desc { font-size: 16px; color: var(--muted); line-height: 1.1; min-height: 2.2em; }
.skin-status { font-size: 18px; color: var(--muted); }
.skin-status.ok { color: var(--green); }

/* ------------------------------------------------------------ leaderboard */

.leaderboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.leaderboard li {
  display: grid;
  grid-template-columns: 40px 32px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 22px;
}
.leaderboard li.me { outline: 2px solid var(--yellow); }
.leaderboard .rank { color: var(--muted); }
.leaderboard li:nth-child(1) .rank { color: var(--gold); }
.leaderboard li:nth-child(2) .rank { color: #d8d8d8; }
.leaderboard li:nth-child(3) .rank { color: #d08a4a; }
.leaderboard canvas { width: 28px; height: 33px; image-rendering: pixelated; }
.leaderboard .score { color: var(--yellow); }
.leaderboard .empty { display: block; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------ HUD */

#hud {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  padding: 14px 18px;
  pointer-events: none;
  text-shadow: 3px 3px 0 #3f3f3f;
}
#hud button { pointer-events: auto; }
#hud-score { font-family: var(--pixel); font-size: 28px; }
.hud-small { font-size: 22px; color: #eee; margin-top: 6px; }
.hud-right { display: flex; align-items: flex-start; gap: 14px; }
.hud-coins { font-family: var(--pixel); font-size: 20px; color: var(--gold); padding-top: 12px; }

#hit-flash {
  position: fixed; inset: 0;
  background: rgba(255, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease-out;
}
#hit-flash.on { opacity: 1; transition: none; }

/* ------------------------------------------------------------ death screen */

.died {
  font-size: clamp(28px, 7vw, 44px);
  color: #fff;
  text-shadow: 4px 4px 0 #3f3f3f;
  margin-bottom: 18px;
}
.score-line { margin: 0; font-size: 28px; text-shadow: 2px 2px 0 #3f3f3f; }
.score-line.small { font-size: 22px; }
.score-line b { color: var(--yellow); font-weight: normal; }
.newbest { margin: 4px 0; color: var(--yellow); font-size: 26px; animation: splash 0.4s ease-in-out infinite alternate; }

/* ------------------------------------------------------------ toasts (advancement style) */

#toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: calc(100vw - 32px);
  padding: 8px 12px;
  background: #212121;
  border: 2px solid #555;
  box-shadow: inset 0 0 0 2px #000;
  animation: toast-in 0.3s ease-out, fade-out 0.5s ease-in 3.5s forwards;
}
.toast canvas { width: 36px; height: 42px; image-rendering: pixelated; }
.toast .t-title { color: var(--yellow); font-size: 20px; }
.toast .t-body { font-size: 20px; }
.toast.error .t-title { color: var(--red); }

@keyframes toast-in { from { transform: translateX(120%); } to { transform: none; } }
@keyframes fade-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ------------------------------------------------------------ small screens */

@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  #screen-menu { justify-content: center; align-items: flex-end; padding: 16px; }
  .menu-panel { gap: 10px; }
  .controls-hint { display: none; }
  .panel.side { margin: 0 auto; }
  #screen-skins { align-items: flex-end; }
  #screen-skins .panel { max-height: 62vh; }
  .splash { font-size: 20px; right: 0; }
}
@media (hover: none) and (pointer: coarse) {
  .controls-hint { display: block; }
  .keys-only { display: none; }
  .touch-only { display: inline; }
}
