:root {
  color-scheme: light;
  --tile: #7cbcbf;
  --tile-dark: #5a9599;
  --grout: #4a7f83;
  --wood: #8a5a36;
  --wood-dark: #5a3a22;
  --chip-bg: #3a6ca8;
  --chip-bg-dark: #23476f;
  --chip-border: #1a3252;
  --cream: #f2e2c4;
  --ink: #1a0e08;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #3d2418;
  font-family: "Nunito", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a0e08;
}

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

/* ---------------- Title badge (top-left) ---------------- */

.title-badge {
  position: absolute;
  top: 20px;
  left: 24px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  pointer-events: none;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.4));
}

.title-text {
  display: flex;
  flex-direction: column;
  font-family: "Nunito", "Avenir Next", sans-serif;
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 0.95;
  color: #f0c255;
  text-shadow:
    -2px 0 0 #1a3252, 2px 0 0 #1a3252,
    0 -2px 0 #1a3252, 0 2px 0 #1a3252,
    -2px -2px 0 #1a3252, 2px -2px 0 #1a3252,
    -2px 2px 0 #1a3252, 2px 2px 0 #1a3252,
    0 6px 0 #1a3252,
    0 10px 14px rgba(0, 0, 0, 0.45);
  transform: rotate(-4deg);
  padding: 6px 4px;
}

.title-text span { font-size: 54px; }
.title-text .sm {
  font-size: 40px;
  align-self: center;
  margin-top: -4px;
}

.title-stache {
  width: 120px;
  height: 44px;
  margin-top: 6px;
  margin-left: 14px;
  transform: rotate(-3deg);
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.25));
}

/* ---------------- HUD chips (top-right) ---------------- */

.chips {
  position: absolute;
  top: 24px;
  right: 22px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 14px;
  pointer-events: none;
}

.chip {
  min-width: 180px;
  background: linear-gradient(180deg, var(--chip-bg) 0%, var(--chip-bg-dark) 100%);
  border: 3px solid var(--chip-border);
  border-radius: 14px;
  padding: 10px 16px 12px;
  color: #fff;
  box-shadow:
    0 6px 0 var(--chip-border),
    0 10px 20px rgba(0, 0, 0, 0.3);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.chip-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  opacity: 0.95;
}

.chip-head .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.chip-value {
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
  margin-top: 4px;
  text-shadow: 0 2px 0 var(--chip-border);
}

/* ---------------- Level HUD (top-center) ---------------- */

.level-hud {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45));
}

.level-badge {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 22px 10px;
  background: linear-gradient(180deg, #f0c255 0%, #d69a28 100%);
  border: 3px solid #5a3a11;
  border-radius: 18px;
  box-shadow:
    inset 0 -5px 0 rgba(90, 58, 17, 0.25),
    0 5px 0 #5a3a11,
    0 10px 22px rgba(0, 0, 0, 0.35);
  color: #3a210f;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.level-label {
  font-size: 16px;
  opacity: 0.85;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.level-number {
  font-size: 38px;
  line-height: 1;
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 rgba(90, 58, 17, 0.25);
  min-width: 1.2em;
  text-align: center;
}

.level-bar {
  position: relative;
  width: 260px;
  height: 18px;
  background: #23150a;
  border: 3px solid #5a3a11;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.6),
    0 3px 0 #3a210f;
}

.level-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(180deg, #ffe7a6 0%, #f0c255 40%, #c08a2a 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    inset 0 -3px 0 rgba(90, 58, 17, 0.3);
  transition: width 0.18s cubic-bezier(.2, .8, .3, 1);
}

.level-bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.8),
    -1px 0 0 #1a0e08, 1px 0 0 #1a0e08,
    0 -1px 0 #1a0e08, 0 1px 0 #1a0e08;
}

/* Brief celebratory pop when the bar fills. */
.level-bar.full .level-bar-fill {
  animation: bar-pulse 0.6s ease-out;
}
@keyframes bar-pulse {
  0%   { filter: brightness(1); }
  40%  { filter: brightness(1.6); }
  100% { filter: brightness(1); }
}

/* ---------------- Toast ---------------- */

.toast {
  position: absolute;
  left: 50%;
  top: 32%;
  transform: translate(-50%, -50%) scale(0.7);
  font-weight: 900;
  font-size: 58px;
  color: #f0c255;
  -webkit-text-stroke: 2px #1a3252;
  text-shadow: 0 6px 0 #1a3252, 0 14px 30px rgba(0, 0, 0, 0.55);
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transition: opacity 0.18s ease, transform 0.3s cubic-bezier(.2, 1.8, .4, 1);
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1) rotate(-3deg);
}

.toast.miss {
  color: #ff8a3d;
}

.toast.levelup {
  color: #ffe7a6;
  -webkit-text-stroke: 3px #5a3a11;
  text-shadow:
    0 6px 0 #5a3a11,
    0 0 24px rgba(240, 194, 85, 0.6),
    0 14px 30px rgba(0, 0, 0, 0.55);
}

.result-banner {
  position: absolute;
  left: 50%;
  top: 132px;
  transform: translate(-50%, -12px) scale(0.92);
  z-index: 6;
  min-width: 220px;
  padding: 10px 24px 12px;
  border-radius: 16px;
  border: 3px solid #5a3a11;
  background: linear-gradient(180deg, #f0c255 0%, #d69a28 100%);
  color: #3a210f;
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 0.08em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  box-shadow:
    inset 0 -5px 0 rgba(90, 58, 17, 0.25),
    0 5px 0 #5a3a11,
    0 12px 22px rgba(0, 0, 0, 0.3);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35),
    0 2px 0 rgba(90, 58, 17, 0.18);
  transition: opacity 0.16s ease, transform 0.25s cubic-bezier(.2, 1.2, .3, 1);
}

.result-banner.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.result-banner.clean {
  background: linear-gradient(180deg, #f3d37e 0%, #cb962f 100%);
}

.result-banner.master {
  background: linear-gradient(180deg, #ffe8a8 0%, #f0c255 40%, #c48e2f 100%);
  box-shadow:
    inset 0 -5px 0 rgba(90, 58, 17, 0.25),
    0 5px 0 #5a3a11,
    0 0 18px rgba(240, 194, 85, 0.35),
    0 12px 22px rgba(0, 0, 0, 0.3);
}

/* ---------------- Reset button ---------------- */

.reset-btn {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 5;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.08em;
  padding: 10px 18px;
  border-radius: 12px;
  border: 3px solid var(--chip-border);
  background: linear-gradient(180deg, var(--chip-bg), var(--chip-bg-dark));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--chip-border), 0 8px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.reset-btn:hover { filter: brightness(1.08); }
.reset-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--chip-border), 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ---------------- Oiled mustache meter ---------------- */

.oiled-hud {
  position: absolute;
  right: 18px;
  bottom: 18px;
  padding: 10px 14px 12px;
  background: linear-gradient(180deg, #2a4a75 0%, #1a3252 100%);
  border: 3px solid var(--chip-border);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--chip-border), 0 6px 14px rgba(0, 0, 0, 0.35);
  color: var(--cream);
  min-width: 190px;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.3), box-shadow 0.25s ease, background 0.25s ease;
}
.oiled-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 1.5px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.oiled-drop {
  font-size: 16px;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.4));
}
.oiled-bar {
  position: relative;
  width: 100%;
  height: 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--chip-border);
  border-radius: 10px;
  overflow: hidden;
}
.oiled-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, #ffd76a 0%, #ffb133 55%, #e67a18 100%);
  box-shadow: 0 0 8px rgba(255, 190, 70, 0.6) inset;
  transition: width 0.25s ease;
}
.oiled-pips {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 2px;
  pointer-events: none;
}
.oiled-pips .pip {
  flex: 1;
  border-right: 2px solid rgba(0, 0, 0, 0.25);
}
.oiled-pips .pip:last-child { border-right: 0; }
.oiled-sub {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.85;
}
.oiled-hud.active {
  background: linear-gradient(180deg, #f0a531 0%, #b8671a 100%);
  border-color: #6a3710;
  box-shadow: 0 4px 0 #6a3710, 0 6px 16px rgba(255, 160, 60, 0.4);
  animation: oiledPulse 1s ease-in-out infinite;
}
.oiled-hud.active .oiled-label,
.oiled-hud.active .oiled-sub { color: #fff; }
.oiled-hud.active .oiled-bar-fill {
  background: linear-gradient(90deg, #fff6c8 0%, #ffd76a 100%);
}
@keyframes oiledPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-2px) scale(1.02); }
}

/* ---------------- Small screens ---------------- */

@media (max-width: 760px) {
  .title-text span { font-size: 36px; }
  .title-text .sm { font-size: 28px; }
  .title-stache { width: 84px; height: 32px; }
  .chip { min-width: 140px; padding: 8px 12px 10px; }
  .chip-value { font-size: 24px; }
  .chip-head { font-size: 11px; }
  .toast { font-size: 40px; }
  .reset-btn { font-size: 12px; padding: 8px 14px; }
  .level-hud { top: 14px; gap: 6px; }
  .level-badge { padding: 6px 14px 8px; border-radius: 14px; }
  .level-label { font-size: 12px; }
  .level-number { font-size: 26px; }
  .level-bar { width: 180px; height: 14px; }
  .level-bar-text { font-size: 10px; }
  .result-banner { top: 104px; min-width: 180px; font-size: 20px; padding: 8px 18px 10px; }
}
