* { box-sizing: border-box; margin: 0; padding: 0; }
/* Sketchbook Runner's look: pencil lead on cream paper, hand-drawn corners, a yellow highlighter */
:root {
  --hand: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --hand2: 22px 8px 26px 6px / 8px 24px 6px 20px;
  --pencil2: 1.5px 2px 0 -0.5px rgba(56, 56, 61, 0.45);
  --hi: #f6dc8c;
}
html, body { height: 100%; background: #5b4a3b; overflow: hidden; } /* the desk under the sketchbook */
body {
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  font-family: 'Patrick Hand', 'Comic Sans MS', 'Chalkboard SE', cursive;
  color: #38383d;
}
#app {
  position: relative; height: 100vh; height: 100dvh; max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column; background: #fbf7ea; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  padding-bottom: env(safe-area-inset-bottom); overflow: hidden;
}
#stage { flex: 1; position: relative; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* buttons floating over the course */
#hud { position: absolute; inset: 0 0 64px 0; pointer-events: none; padding-top: env(safe-area-inset-top); }
#hud .btn, #hud .slot { pointer-events: auto; }
.row { position: absolute; left: 10px; right: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.top { top: calc(10px + env(safe-area-inset-top)); }
.row.bottom { bottom: 10px; align-items: flex-end; }
.side { position: absolute; top: calc(78px + env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 10px; }
.side.left { left: 10px; }
.side.right { right: 10px; }
.btn {
  font: inherit; color: #38383d; background: rgba(255, 255, 255, 0.7); cursor: pointer;
  border: 2.2px solid #38383d; border-radius: var(--hand); box-shadow: var(--pencil2);
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.sq { width: 52px; height: 52px; font-size: 24px; }
.btn.round { width: 52px; height: 52px; font-size: 24px; border-radius: 50%; }
.btn.wide { flex: 1; max-width: 200px; height: 52px; font-size: 26px; background: var(--hi); }
.btn.soon { opacity: 0.55; }
.slot { width: 52px; height: 52px; border: 2px dashed rgba(56, 56, 61, 0.35); border-radius: var(--hand); background: rgba(255, 255, 255, 0.35); }
.wallet { background: rgba(251, 247, 234, 0.92); border: 2.2px solid #38383d; border-radius: var(--hand); box-shadow: var(--pencil2); padding: 4px 14px; pointer-events: auto; }
.gems { font-size: 20px; color: #3b78d0; }
.money { font-size: 30px; line-height: 1; color: #2f8a3c; }
.abilities { display: flex; gap: 8px; }

/* bottom tabs (8 UP, 11 treasures, 10 cosmetics, 9 stage) */
#tabs { flex: none; height: 64px; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 2.2px solid #38383d; background: #efe8d4; position: relative; z-index: 3; }
.tab { font: inherit; border: 0; border-left: 1.5px solid rgba(56, 56, 61, 0.3); background: none; color: #38383d; font-size: 20px; cursor: pointer; }
.tab:first-child { border-left: 0; }
.tab .ti { display: block; font-size: 22px; }
.tab.on { background: #fbf7ea; box-shadow: inset 0 -3px 0 #d9473b; }
.tab.soon { color: rgba(56, 56, 61, 0.45); }

/* the panel that slides up when a tab is open */
#sheet {
  position: absolute; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 2;
  background: #fbf7ea repeating-linear-gradient(#fbf7ea 0 27px, rgba(96, 140, 205, 0.22) 27px 28px);
  border-top: 2.2px solid #38383d; padding: 10px 12px 14px; box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
}
#sheet[hidden] { display: none; }
.sheet-title { font-size: 26px; text-align: center; margin-bottom: 8px; text-decoration: underline wavy #d9473b; text-underline-offset: 6px; }
#panel[hidden], #stagepanel[hidden], #skinpanel[hidden], #treasurepanel[hidden], #reveal[hidden], #settings[hidden] { display: none; }
#panel { display: flex; flex-direction: column; gap: 8px; max-height: 42vh; overflow-y: auto; padding: 2px 4px 4px 2px; -webkit-overflow-scrolling: touch; }
.card {
  display: flex; align-items: center; gap: 12px; padding: 6px 12px; flex: none; background: rgba(255, 255, 255, 0.7);
  border: 2.2px solid #38383d; border-radius: var(--hand2); box-shadow: var(--pencil2);
}
.card .icon { font-size: 30px; width: 40px; text-align: center; }
.card .info { flex: 1; }
.card .name { font-size: 22px; line-height: 1.1; }
.card .what { font-size: 18px; line-height: 1.1; color: rgba(56, 56, 61, 0.65); }
.buy {
  min-width: 96px; padding: 6px 12px; font: inherit; font-size: 22px;
  border: 2.2px solid #38383d; border-radius: var(--hand); background: var(--hi); color: #38383d; cursor: pointer; box-shadow: var(--pencil2);
}
.buy:active { transform: translateY(2px); }
.buy:disabled { background: rgba(255, 255, 255, 0.5); color: rgba(56, 56, 61, 0.4); border-color: rgba(56, 56, 61, 0.35); box-shadow: none; cursor: default; transform: none; }

#toast {
  position: absolute; left: 50%; top: 28%; transform: translateX(-50%); z-index: 12; pointer-events: none;
  max-width: 88%; width: max-content; text-align: center; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  background: #38383d; color: #fbf7ea; padding: 8px 18px; border-radius: var(--hand); font-size: 22px;
  opacity: 0; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

/* level goal under the 2x button */
.goal {
  position: absolute; top: calc(72px + env(safe-area-inset-top)); left: 74px; right: 74px; pointer-events: auto;
  font: inherit; color: #38383d; background: rgba(251, 247, 234, 0.92); text-align: center; cursor: default;
  border: 2.2px solid #38383d; border-radius: var(--hand2); box-shadow: var(--pencil2); padding: 4px 10px; display: flex; flex-direction: column; gap: 3px;
}
.goal-label { font-size: 21px; line-height: 1.1; }
.goal-bar { display: block; height: 10px; background: rgba(56, 56, 61, 0.08); border: 1.5px solid #38383d; border-radius: var(--hand); overflow: hidden; }
.goal-bar span { display: block; height: 100%; width: 0; background: repeating-linear-gradient(-45deg, #3b78d0 0 4px, #6d9ae0 4px 7px); }
.goal-text { font-size: 18px; color: rgba(56, 56, 61, 0.7); }
.goal.ready { background: var(--hi); cursor: pointer; animation: glow 1s ease-in-out infinite alternate; }
.goal.ready .goal-label { font-size: 26px; }
.goal.ready .goal-bar { display: none; }
.goal.ready .goal-text { color: #38383d; }
.goal.ready:active { transform: translateY(2px); box-shadow: none; }
@keyframes glow { from { box-shadow: var(--pencil2), 0 0 0 rgba(241, 191, 44, 0); } to { box-shadow: var(--pencil2), 0 0 18px rgba(241, 191, 44, 0.9); } }

/* Stage tab panel */
.st-name { text-align: center; font-size: 22px; margin-bottom: 8px; }
.dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.dot { width: 36px; height: 36px; border-radius: 50% 45% 52% 48%; border: 2.2px solid #38383d; display: flex; align-items: center; justify-content: center; font-size: 19px; background: rgba(255, 255, 255, 0.7); }
.dot.done { background: rgba(63, 163, 77, 0.4); }
.dot.now { background: var(--hi); }
.dot.hard { border-color: #d9473b; color: #d9473b; }
.dot.locked { opacity: 0.4; }
.st-goal { text-align: center; font-size: 19px; color: rgba(56, 56, 61, 0.7); }

/* Skins tab */
#skinpanel { max-height: 46vh; overflow-y: auto; padding: 2px; }
.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 6px; }
.boxbtn { font: inherit; border: 2.2px solid #38383d; border-radius: var(--hand2); background: rgba(255, 255, 255, 0.7); padding: 4px 2px; cursor: pointer; box-shadow: var(--pencil2); color: #38383d; }
.boxbtn .bi { display: block; font-size: 24px; }
.boxbtn .bn { display: block; font-size: 15px; line-height: 1; }
.boxbtn .bp { display: block; font-size: 16px; color: #3b78d0; }
.boxbtn.bronze { background: rgba(205, 127, 50, 0.3); } .boxbtn.silver { background: rgba(160, 170, 185, 0.3); } .boxbtn.gold { background: rgba(241, 191, 44, 0.4); }
.boxbtn.chest { background: rgba(142, 68, 173, 0.25); } .boxbtn.case { background: rgba(239, 148, 171, 0.4); }
.boxbtn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.oddsbtn { font: inherit; font-size: 18px; background: none; border: 0; color: #3b78d0; text-decoration: underline; cursor: pointer; display: block; margin: 0 auto 6px; }
.odds { font-size: 16px; color: rgba(56, 56, 61, 0.8); margin-bottom: 8px; line-height: 1.3; }
.skingrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tile { border: 3px solid #ccc; border-radius: var(--hand2); background: rgba(255, 255, 255, 0.7); text-align: center; padding: 2px 2px 4px; cursor: pointer; position: relative; }
.tile canvas { width: 100%; height: auto; display: block; }
.tile .tn { font-size: 14px; line-height: 1; min-height: 28px; }
.tile.locked { cursor: default; background: rgba(56, 56, 61, 0.05); }
.tile.locked .q { font-size: 34px; color: rgba(56, 56, 61, 0.3); height: 56px; line-height: 56px; }
.tile.worn::after { content: '✓'; position: absolute; top: 0; right: 6px; color: #2f8a3c; font-size: 24px; }

/* the reveal pop-up */
#settings { position: absolute; inset: 0; z-index: 11; background: rgba(40, 30, 20, 0.45); display: flex; align-items: center; justify-content: center; }
.switch { display: block; width: 100%; margin: 10px 0; padding: 8px; font-size: 24px; background: rgba(63, 163, 77, 0.25); }
.switch.off { background: rgba(255, 255, 255, 0.6); color: rgba(56, 56, 61, 0.5); }
#reveal { position: absolute; inset: 0; z-index: 10; background: rgba(40, 30, 20, 0.45); display: flex; align-items: center; justify-content: center; }
.reveal-card { width: 280px; background: #fbf7ea; border: 2.5px solid #38383d; border-radius: var(--hand2); box-shadow: var(--pencil2), 0 8px 30px rgba(0, 0, 0, 0.35); padding: 14px; text-align: center; animation: pop 0.35s ease-out; }
.reveal-card.secret { background: linear-gradient(135deg, #ffb3b3, #ffe9a8, #b8f5c4, #b3d9ff, #e0b8ff); animation: pop 0.35s ease-out, wobble 1.2s ease-in-out infinite; }
#reveal-canvas { width: 150px; height: 150px; }
.reveal-from { font-size: 22px; color: rgba(56, 56, 61, 0.7); }
.reveal-rarity { font-size: 34px; line-height: 1.1; }
.reveal-name { font-size: 26px; }
.reveal-note { font-size: 20px; margin: 6px 0 10px; color: rgba(56, 56, 61, 0.8); }
.reveal-ok { padding: 4px 32px; font-size: 26px; background: var(--hi); }
@keyframes pop { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes wobble { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }

/* 2x button states */
#x2.on { background: rgba(240, 138, 36, 0.55); animation: glow 0.8s ease-in-out infinite alternate; }
#x2.wait { background: rgba(255, 255, 255, 0.5); color: rgba(56, 56, 61, 0.5); font-size: 20px; }

/* Treasure tab */
#treasurepanel { max-height: 46vh; overflow-y: auto; padding: 2px; display: flex; flex-direction: column; gap: 8px; }
.findbtn { font: inherit; font-size: 24px; padding: 6px; border: 2.2px solid #38383d; border-radius: var(--hand); background: var(--hi); box-shadow: var(--pencil2); cursor: pointer; color: #38383d; flex: none; }
.findbtn:disabled { background: rgba(255, 255, 255, 0.5); color: rgba(56, 56, 61, 0.4); box-shadow: none; cursor: default; }
.card.unfound { background: rgba(56, 56, 61, 0.05); color: rgba(56, 56, 61, 0.45); }

/* 🏆 Tournament panel */
#tourney { position: absolute; inset: 0; z-index: 9; background: rgba(40, 30, 20, 0.45); display: flex; align-items: center; justify-content: center; }
#tourney[hidden], #racebar[hidden] { display: none; }
.tcard { width: min(360px, 94%); max-height: 92%; overflow-y: auto; }
.t-league { font-size: 26px; line-height: 1.1; }
.t-name { font-size: 20px; color: rgba(56, 56, 61, 0.8); }
.t-reroll { font: inherit; font-size: 18px; background: none; border: 0; cursor: pointer; }
.t-status { font-size: 18px; margin: 4px 0 6px; }
.t-race { width: 100%; }
.t-best { font-size: 19px; margin: 6px 0 4px; }
.t-board { text-align: left; font-size: 18px; }
.t-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 6px; padding: 1px 6px; }
.t-row.me { background: var(--hi); border-radius: var(--hand2); }
.t-zone { font-size: 14px; text-align: center; border-top: 1.5px dashed; margin: 2px 0; }
.t-zone.up { color: #2f8a3c; } .t-zone.down { color: #d9473b; }
.t-rules { font-size: 15px; color: rgba(56, 56, 61, 0.7); margin: 8px 0; }

/* during a race: the main game's buttons and tabs go away, the race bar comes */
#app.racing #hud, #app.racing #tabs, #app.racing #sheet { display: none; }
#racebar { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.race-top { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; pointer-events: auto;
  background: rgba(251, 247, 234, 0.92); border: 2.2px solid #38383d; border-radius: var(--hand2); box-shadow: var(--pencil2); padding: 6px 12px; text-align: center; }
.race-time { font-size: 30px; line-height: 1; }
.race-money { font-size: 17px; color: rgba(56, 56, 61, 0.75); margin-top: 3px; }
.race-top .goal-bar { margin-top: 4px; }
#race-fill { background: repeating-linear-gradient(-45deg, #2f8a3c 0 4px, #52b062 4px 7px); }
.race-bottom { position: absolute; left: 10px; right: 10px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 6px; pointer-events: auto; }
.race-buy { flex: 1; min-width: 0; font-size: 20px; padding: 8px 4px; }
.race-quit { width: 48px; font-size: 20px; }
