:root {
  --outline: #2b2118;
  --stone-body: #b8b59c;
  --stone-light: #f4e6cc;
  --stone-cream: #fbf2df;
  --stone-dark: #4e4236;
  --moss-bright: #8ac926;
  --moss-dark: #558b1f;
  --wood: #b86f34;
  --wood-dark: #7d4519;
  --text-dark: #2b2118;
  --text-muted: #5c4d3c;
  --font-display: 'Luckiest Guy', cursive, sans-serif;
  --font-ui: 'Fredoka', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #9ad9f2 0%, #d8f0f2 45%, #fde9c9 100%);
  color: var(--text-dark);
  font-family: var(--font-ui);
  overflow-x: hidden;
}

/* Sunlit Cartoon Adventure Backdrop */
.sky-backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  filter: drop-shadow(0 6px 0 rgba(43, 33, 24, 0.08));
}

.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud.c1 {
  width: 190px;
  height: 54px;
  top: 7%;
  left: 8%;
}
.cloud.c1::before { width: 85px; height: 85px; top: -38px; left: 26px; }
.cloud.c1::after { width: 65px; height: 65px; top: -24px; right: 26px; }

.cloud.c2 {
  width: 230px;
  height: 62px;
  top: 13%;
  right: 7%;
}
.cloud.c2::before { width: 96px; height: 96px; top: -44px; left: 36px; }
.cloud.c2::after { width: 74px; height: 74px; top: -28px; right: 32px; }

.cliff {
  position: absolute;
  bottom: -20px;
  width: 260px;
  height: 300px;
  background: linear-gradient(180deg, #d7b88c 0%, #b58d5d 100%);
  border: 4px solid var(--outline);
  border-radius: 26px 26px 0 0;
  opacity: 0.45;
}
.cliff::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -4px;
  right: -4px;
  height: 28px;
  background: var(--moss-bright);
  border: 4px solid var(--outline);
  border-radius: 18px;
}
.cliff-left { left: -90px; transform: rotate(4deg); }
.cliff-right { right: -90px; transform: rotate(-4deg); height: 250px; }

/* Views */
.view {
  display: none;
  position: relative;
  z-index: 1;
  max-width: 1220px;
  margin: 0 auto;
  padding: 20px 20px 44px;
}

.view.active {
  display: block;
  animation: popIn 0.25s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.98) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Hero Header (Caveboy-style Chunky Carved Title) */
.hero-header {
  text-align: center;
  margin-bottom: 24px;
}

.brand-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--stone-cream);
  border: 3px solid var(--outline);
  box-shadow: 0 4px 0 var(--outline);
  color: var(--moss-dark);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 5.5vw, 4rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title-top {
  color: #f6d365;
  -webkit-text-stroke: 3px var(--outline);
  text-shadow: 0 6px 0 var(--outline);
}

.title-bottom {
  color: #e6ebe0;
  -webkit-text-stroke: 3px var(--outline);
  text-shadow: 0 6px 0 var(--outline);
  font-size: 0.78em;
}

.brand-sub {
  margin: 12px auto 0;
  max-width: 560px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 1rem;
}

/* Stone Panel & Mossy Ribbon */
.stone-panel {
  background: var(--stone-body);
  border: 4px solid var(--outline);
  border-radius: 22px;
  box-shadow:
    inset 0 6px 0 rgba(255, 255, 255, 0.25),
    0 9px 0 var(--outline);
  overflow: visible;
}

.moss-ribbon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--stone-light);
  border-bottom: 4px solid var(--outline);
  border-radius: 18px 18px 10px 10px;
  padding: 16px 20px 14px;
  box-shadow: inset 0 6px 0 #fff7e6;
}

/* Lush mossy vine cap on top of panels */
.moss-ribbon::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 14px;
  right: 14px;
  height: 14px;
  background: linear-gradient(180deg, var(--moss-bright), var(--moss-dark));
  border: 3px solid var(--outline);
  border-radius: 999px;
}

.moss-ribbon.small {
  padding: 11px 16px 10px;
}

.moss-ribbon.center {
  justify-content: center;
}

.moss-ribbon h2, .moss-ribbon h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  color: #9ae638;
  -webkit-text-stroke: 1.6px var(--outline);
  text-shadow: 0 3px 0 var(--outline);
}

.moss-ribbon.small h3 {
  font-size: 1.1rem;
}

.pause-title {
  font-size: 2rem !important;
  color: #fde047 !important;
}

.panel-body {
  padding: 20px;
}

.panel-body.compact {
  padding: 14px;
}

.center-text {
  text-align: center;
}

/* Lobby Layout */
.lobby-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 24px;
  align-items: start;
}

.lobby-side {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Forms */
.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-dark);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 3px solid var(--outline);
  background: var(--stone-cream);
  color: var(--text-dark);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.98rem;
  outline: none;
  box-shadow: inset 0 3px 0 rgba(43, 33, 24, 0.12);
}

input[type="text"]:focus {
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(138, 201, 38, 0.45);
}

/* Color Picker */
.color-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.color-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 6px;
  border-radius: 12px;
  border: 3px solid var(--outline);
  background: var(--stone-light);
  color: var(--text-dark);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--outline);
  transition: transform 0.1s;
}

.color-chip .chip-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--chip);
  border: 2px solid var(--outline);
}

.color-chip.selected {
  background: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--outline);
}

/* Mode Cards */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  padding: 11px;
  border-radius: 14px;
  border: 3px solid var(--outline);
  background: var(--stone-light);
  color: var(--text-dark);
  font-family: var(--font-ui);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--outline);
}

.mode-card .mode-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.mode-card strong {
  display: block;
  font-size: 0.9rem;
}

.mode-card small {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}

.mode-card.selected {
  background: #fef9c3;
  box-shadow: 0 5px 0 var(--outline);
}

/* Chunky 3D Stone & Wood Buttons */
button {
  font-family: var(--font-ui);
}

.action-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.btn-slab, .btn-wood, .btn-tile, .btn-tile-lg {
  border: 3px solid var(--outline);
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.45), 0 5px 0 var(--outline);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn-slab:active, .btn-wood:active, .btn-tile:active, .btn-tile-lg:active {
  transform: translateY(4px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 1px 0 var(--outline);
}

.btn-slab {
  padding: 12px 18px;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.btn-lg {
  padding: 15px 28px;
  font-size: 1.15rem;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
  border-radius: 10px;
}

.btn-sand { background: #f4c874; }
.btn-crimson { background: #c83e2b; color: #fde68a; }
.btn-lime { background: #c2da4e; }
.btn-mint { background: #9df7cb; }
.btn-pink { background: #fab9b9; }
.btn-cream { background: #fcf1c7; }
.btn-stone { background: #e2dac3; }
.btn-wood { background: #e8b87d; padding: 7px 12px; font-size: 0.82rem; border-radius: 10px; }

.btn-tile {
  width: 42px;
  height: 42px;
  font-size: 1.15rem;
  border-radius: 12px;
}

.btn-tile-lg {
  width: 72px;
  height: 72px;
  font-size: 1.9rem;
  border-radius: 16px;
}

/* Quick Join & Rooms List */
.quick-join {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.quick-join input {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: 220px;
  overflow-y: auto;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 13px;
  background: var(--stone-cream);
  border: 3px solid var(--outline);
}

.room-item-info strong {
  display: block;
  font-size: 0.96rem;
}

.room-item-meta {
  display: flex;
  gap: 8px;
  font-size: 0.76rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Leaderboard */
.badge-stone {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 800;
  background: var(--stone-cream);
  border: 2px solid var(--outline);
  padding: 3px 10px;
  border-radius: 999px;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 11px;
  background: var(--stone-cream);
  border: 2px solid var(--outline);
  font-size: 0.88rem;
  font-weight: 600;
}

.lb-rank {
  font-family: var(--font-mono);
  font-weight: 800;
  color: #b45309;
}

.lb-lvl {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--moss-dark);
}

.lb-score {
  font-family: var(--font-mono);
  font-weight: 800;
}

/* Waiting Room */
.waiting-shell {
  max-width: 780px;
  margin: 30px auto;
}

.wait-code-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  background: var(--stone-cream);
  border: 3px solid var(--outline);
  border-radius: 15px;
  padding: 12px 18px;
}

.code-label {
  display: block;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--text-muted);
}

.wait-code-banner strong {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  letter-spacing: 0.14em;
  color: #b45309;
}

.waiting-hint {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  margin: 14px 0 18px;
}

.wait-players-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.wait-slot {
  padding: 16px 10px;
  border-radius: 15px;
  border: 3px dashed rgba(43, 33, 24, 0.35);
  background: rgba(251, 242, 223, 0.55);
  text-align: center;
}

.wait-slot.filled {
  border-style: solid;
  border-color: var(--outline);
  background: var(--stone-cream);
  box-shadow: 0 5px 0 var(--outline);
}

.wait-avatar {
  width: 46px;
  height: 46px;
  margin: 0 auto 10px;
  border-radius: 13px;
  border: 3px solid var(--outline);
  background: var(--slot-color, #cbd5e1);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
}

.wait-slot strong { display: block; font-size: 0.94rem; }
.wait-slot small { display: block; color: var(--text-muted); font-size: 0.76rem; font-weight: 600; }

.waiting-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* ================= GAME ARENA ================= */
.arcade-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 18px;
  background: var(--stone-light);
  border: 4px solid var(--outline);
  border-radius: 18px;
  box-shadow: inset 0 4px 0 #fff7e6, 0 6px 0 var(--outline);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
}

.hud-lbl {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--text-muted);
}

.hud-val {
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1;
  margin-top: 2px;
  color: var(--text-dark);
}

.accent-gold { color: #d97706; }
.accent-red { color: #dc2626; }

.hud-center {
  display: flex;
  align-items: center;
  gap: 10px;
}

.level-banner {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--moss-dark);
  letter-spacing: 0.04em;
}

.hud-room-pill {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--stone-cream);
  border: 2px solid var(--outline);
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.arena-layout {
  display: grid;
  grid-template-columns: 1fr 270px;
  gap: 18px;
  align-items: start;
}

.canvas-frame {
  position: relative;
  background: var(--wood-dark);
  border: 4px solid var(--outline);
  border-radius: 20px;
  padding: 10px;
  box-shadow: 0 9px 0 var(--outline);
  display: flex;
  justify-content: center;
}

#game-canvas {
  width: 100%;
  max-width: 720px;
  height: auto;
  aspect-ratio: 15 / 13;
  display: block;
  border-radius: 12px;
  border: 3px solid var(--outline);
}

.canvas-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(43, 33, 24, 0.55);
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 3rem);
  color: #fde047;
  -webkit-text-stroke: 2px var(--outline);
  text-shadow: 0 5px 0 var(--outline);
  border-radius: 16px;
  pointer-events: none;
}

.canvas-banner.hidden {
  display: none;
}

.arena-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-players-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gp-card {
  padding: 9px 11px;
  border-radius: 12px;
  background: var(--stone-cream);
  border: 3px solid var(--outline);
  border-left-width: 7px;
  border-left-color: var(--p-color, #38bdf8);
}

.gp-card.dead {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.gp-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 700;
}

.gp-stats {
  display: flex;
  gap: 7px;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
}

.mini-legend {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dark);
}

kbd {
  background: var(--stone-cream);
  border: 2px solid var(--outline);
  border-radius: 6px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

/* Touch Controls */
.touch-controls {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--stone-light);
  border: 4px solid var(--outline);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--outline);
}

.touch-controls.hidden { display: none; }

.dpad {
  display: grid;
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: 6px;
}

.dpad-btn {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 3px solid var(--outline);
  background: var(--stone-cream);
  color: var(--text-dark);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--outline);
}

.dpad-btn.up { grid-area: up; }
.dpad-btn.left { grid-area: left; }
.dpad-btn.right { grid-area: right; }
.dpad-btn.down { grid-area: down; }

.touch-bomb-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 4px solid var(--outline);
  background: #fab9b9;
  color: var(--text-dark);
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--outline);
}

/* ================= CARTOON DIALOGS & PAUSE SLIDERS ================= */
.cartoon-dialog {
  border: none;
  background: transparent;
  padding: 22px 10px 10px;
  max-width: 440px;
  width: 94%;
  overflow: visible;
}

.cartoon-dialog::backdrop {
  background: rgba(43, 33, 24, 0.55);
  backdrop-filter: blur(4px);
}

.modal-stone {
  position: relative;
}

.octagon-close {
  position: absolute;
  top: 2px;
  right: 16px;
  z-index: 5;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 3px solid var(--outline);
  background: #ef4444;
  color: var(--outline);
  font-size: 1.3rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.4), 0 4px 0 var(--outline);
}

.octagon-close:active {
  transform: translateY(3px);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 16px 0;
}

.slider-icon {
  font-size: 1.8rem;
  width: 36px;
  text-align: center;
}

/* Chunky Stone Volume Slider */
.stone-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 22px;
  background: var(--stone-dark);
  border: 3px solid var(--outline);
  border-radius: 8px;
  outline: none;
}

.stone-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--stone-light);
  border: 3px solid var(--outline);
  box-shadow: inset 0 3px 0 #fff, 0 3px 0 var(--outline);
  cursor: pointer;
}

.stone-slider::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--stone-light);
  border: 3px solid var(--outline);
  box-shadow: 0 3px 0 var(--outline);
  cursor: pointer;
}

.pause-btn-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
}

.dialog-emoji {
  font-size: 3rem;
  margin-bottom: 6px;
}

.end-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 20px;
  text-align: left;
}

.end-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--stone-cream);
  border: 2px solid var(--outline);
  font-weight: 700;
}

.howto-list {
  text-align: left;
  padding-left: 18px;
  line-height: 1.5;
  font-size: 0.92rem;
  font-weight: 500;
  margin: 0 0 18px;
}

.howto-list li { margin-bottom: 8px; }

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: var(--stone-cream);
  border: 3px solid var(--outline);
  color: var(--text-dark);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 5px 0 var(--outline);
  animation: popIn 0.2s ease-out;
}

.toast.error {
  background: #fecdd3;
}

@media (max-width: 960px) {
  .lobby-grid, .arena-layout { grid-template-columns: 1fr; }
  .wait-players-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .color-picker { grid-template-columns: repeat(2, 1fr); }
  .mode-cards, .action-row { grid-template-columns: 1fr; }
  .hud-left { gap: 12px; }
}
