:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --dim: #8b949e;
  --accent: #58a6ff;
  --gold: #ffd54a;
  --gold-dark: #b8860b;
  --green: #3fb950;
  --red: #f85149;
  --font: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* fixed desk background */
.bg {
  position: fixed;
  inset: 0;
  background: url("assets/img/bg.png") center / cover;
  image-rendering: pixelated;
  z-index: 0;
}
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, .72);
}

#app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* ---------- bars ---------- */
.bar {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.fill {
  height: 100%;
  width: 0%;
  transition: width .2s ease;
}
.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0,0,0,.7);
}

/* ---------- header ---------- */
.token-caption {
  font-size: 11px;
  color: var(--dim);
  display: block;
  margin-bottom: 3px;
}
.token-bar { height: 28px; }
.token-bar .fill { background: linear-gradient(90deg, #1f6feb, #58a6ff); }

body.danger .token-bar { animation: pulse-red 1s infinite; }
body.danger .token-bar .fill { background: linear-gradient(90deg, #da3633, #f85149); }
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, .5); }
  50% { box-shadow: 0 0 12px 3px rgba(248, 81, 73, .8); }
}

.week-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.day-label {
  min-width: 40px;
  font-size: 14px;
  font-weight: bold;
  color: var(--gold);
}
.week-bar { flex: 1; height: 10px; }
.week-bar .fill { background: linear-gradient(90deg, #6e40c9, #bc8cff); transition: width .1s linear; }
.time-label { min-width: 38px; text-align: right; font-size: 12px; color: var(--dim); }

.meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
}
.spacer { flex: 1; }

.tickets { display: flex; gap: 4px; }
.ticket-slot { position: relative; width: 32px; height: 36px; }
.ticket-slot img { width: 32px; height: 32px; image-rendering: pixelated; }
.ticket-slot.empty img { opacity: .15; filter: grayscale(1); }
.ticket-life {
  position: absolute;
  bottom: 0; left: 2px; right: 2px;
  height: 3px;
  border-radius: 2px;
  background: #21262d;
  overflow: hidden;
}
.ticket-life > i {
  display: block;
  height: 100%;
  background: var(--gold);
}
.ticket-slot.expiring img { animation: blink .4s infinite; }
.ticket-slot.expiring .ticket-life > i { background: var(--red); }
@keyframes blink { 50% { opacity: .25; } }

.chip {
  min-width: 40px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
}
.chip:active { background: var(--border); }

/* ---------- main ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

.score-wrap { text-align: center; }
.score-big {
  font-size: 44px;
  font-weight: bold;
  color: var(--text);
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
  line-height: 1.1;
}
.score-big small { font-size: 16px; color: var(--dim); }
.score-side {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
  color: var(--dim);
  min-height: 16px;
}
.streak { color: var(--gold); font-weight: bold; }

.progress-bar { height: 22px; }
.progress-bar .fill { background: linear-gradient(90deg, #238636, #3fb950); }

.fomo {
  min-height: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--red);
}
.fomo.on { animation: wobble .6s infinite; }
@keyframes wobble {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-2px) rotate(-1deg); }
  75% { transform: translateX(2px) rotate(1deg); }
}

.code-btn {
  position: relative;
  align-self: center;
  width: min(78%, 300px);
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  -webkit-user-select: none;
  user-select: none;
}

.tap-hint {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--gold);
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0,0,0,.7);
  transition: opacity .3s;
}
.code-btn.idle-hint .tap-hint {
  opacity: 1;
  animation: tap-pulse 1s ease-in-out infinite;
}
.code-btn.idle-hint .kb-img {
  animation: idle-bounce 1s ease-in-out infinite;
}
@keyframes tap-pulse {
  0%, 100% { opacity: .5; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.2); }
}
@keyframes idle-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.kb-img {
  width: 100%;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.6));
  transition: transform .06s;
}
.code-btn.pressed .kb-img {
  transform: translateY(4px) scale(.965) rotate(var(--tilt, 0deg));
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.7)) brightness(1.25);
}
.code-btn.nudge .kb-img { animation: shake .25s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  60% { transform: translateX(5px); }
}
.code-caption { font-size: 11px; color: var(--dim); letter-spacing: 1px; }

/* floating +N particles */
.pop {
  position: fixed;
  pointer-events: none;
  font-weight: bold;
  font-size: 18px;
  color: var(--green);
  animation: rise .9s ease-out forwards;
  z-index: 50;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}
.pop.cost { color: var(--red); font-size: 14px; }
@keyframes rise {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-70px) scale(1.3); }
}

/* ---------- footer ---------- */
footer { display: flex; flex-direction: column; gap: 8px; }

.action-row { display: flex; gap: 8px; }
.action-btn {
  flex: 1;
  min-height: 56px;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.action-btn:disabled { opacity: .35; }
.btn-icon { width: 22px; height: 22px; image-rendering: pixelated; }
.ticket-btn {
  border: 2px solid var(--gold-dark);
  background: linear-gradient(180deg, #3a2f10, #1f1a08);
  color: var(--gold);
  flex-direction: row;
  gap: 8px;
}
.ticket-btn:active:not(:disabled) { background: #4a3d15; }
.tweet-btn {
  border: 2px solid #1a8cd8;
  background: linear-gradient(180deg, #102a3d, #0a1926);
  color: #7cc4f8;
}
.tweet-btn:active:not(:disabled) { background: #163c57; }
.tweet-btn small { font-size: 10px; font-weight: normal; opacity: .75; }
.tweet-btn.active { border-color: #7cc4f8; animation: glow-blue 1s infinite; }
@keyframes glow-blue {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124, 196, 248, .3); }
  50% { box-shadow: 0 0 10px 2px rgba(124, 196, 248, .6); }
}
.code-btn.busy .kb-img { opacity: .4; filter: grayscale(.7); }

.predict-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--dim);
}
.predict-bar { flex: 1; height: 10px; }
.predict-bar .fill { background: linear-gradient(90deg, var(--gold-dark), var(--gold)); }
.predict-pct { min-width: 34px; text-align: right; color: var(--gold); }

.version { text-align: right; font-size: 9px; color: #444c56; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.hidden { display: none !important; }

/* start & results screens */
.screen {
  background: rgba(13, 17, 23, .88);
  text-align: center;
  padding: 24px;
  z-index: 90;
}
.screen h1 { font-size: 26px; color: var(--gold); text-shadow: 0 2px 8px rgba(0,0,0,.8); }
.start-tibo {
  width: 140px;
  height: 140px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 18px rgba(255, 213, 74, .4));
}
.tagline { font-size: 14px; color: var(--text); }
.rule { font-size: 12px; color: var(--dim); max-width: 320px; line-height: 1.6; }
.start-best { font-size: 13px; color: var(--gold); min-height: 16px; }
.modal-btn.big {
  width: min(80%, 300px);
  height: 56px;
  font-size: 17px;
  animation: glow 1.4s infinite;
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 213, 74, .25); }
  50% { box-shadow: 0 0 12px 3px rgba(255, 213, 74, .45); }
}
.score-final { font-size: 52px; font-weight: bold; }
.score-final small { font-size: 18px; color: var(--dim); }
.new-best {
  color: var(--gold);
  font-size: 16px;
  font-weight: bold;
  animation: blink-slow 1s infinite;
}
@keyframes blink-slow { 50% { opacity: .4; } }
.results-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--text);
  min-width: 220px;
}
.results-list .row { display: flex; justify-content: space-between; gap: 20px; }
.results-list .row b { color: var(--gold); }

/* Tibo descent */
#tiboOverlay {
  background: radial-gradient(circle at 50% 35%, rgba(255, 214, 74, .95), rgba(184, 134, 11, .92) 55%, rgba(60, 40, 5, .95));
  animation: gold-in .3s ease-out;
  text-align: center;
  padding: 20px;
}
@keyframes gold-in { from { opacity: 0; } to { opacity: 1; } }

.rays {
  position: absolute;
  inset: -50%;
  background: repeating-conic-gradient(rgba(255,255,255,.18) 0deg 12deg, transparent 12deg 24deg);
  animation: spin 14s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tibo-img {
  width: 170px;
  height: 170px;
  image-rendering: pixelated;
  position: relative;
  animation: descend .7s ease-out;
  filter: drop-shadow(0 0 24px rgba(255, 255, 220, .9));
}
@keyframes descend {
  from { transform: translateY(-45vh) scale(.6); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.tibo-descended {
  position: relative;
  font-size: 13px;
  letter-spacing: 2px;
  color: #5c3d00;
  font-weight: bold;
}
.tibo-reason {
  position: relative;
  font-size: 19px;
  font-weight: bold;
  color: #2d1e00;
  background: rgba(255,255,255,.35);
  padding: 5px 16px;
  border-radius: 999px;
}
.tibo-flow {
  position: relative;
  font-size: 24px;
  font-weight: bold;
  color: #fffbe8;
  text-shadow: 0 0 14px rgba(255, 240, 150, 1), 0 2px 0 rgba(90, 60, 0, .6);
  animation: flow-zoom .6s ease-out;
  letter-spacing: 1px;
}
@keyframes flow-zoom {
  from { transform: scale(.4); opacity: 0; }
  60% { transform: scale(1.15); }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- modal ---------- */
.modal { background: rgba(1, 4, 9, .8); padding: 20px; z-index: 110; }
.modal-box {
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.modal-box h2 { font-size: 18px; color: var(--gold); }
#modalBody { font-size: 14px; line-height: 1.7; }
.modal-btn {
  height: 48px;
  border: 2px solid var(--gold-dark);
  border-radius: 10px;
  background: linear-gradient(180deg, #3a2f10, #1f1a08);
  color: var(--gold);
  font-family: var(--font);
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.ach-list { text-align: left; display: flex; flex-direction: column; gap: 8px; }
.ach-item {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}
.ach-item.unlocked { border-color: var(--gold-dark); }
.ach-item.unlocked .ach-name { color: var(--gold); }
.ach-name { font-weight: bold; font-size: 13px; }
.ach-desc { color: var(--dim); }

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  top: max(108px, calc(env(safe-area-inset-top) + 100px));
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 440px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  text-align: center;
  animation: toast-in .25s ease-out;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
.toast.fade { opacity: 0; transition: opacity .4s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-height: 640px) {
  .score-big { font-size: 34px; }
  .code-btn { width: min(64%, 240px); }
  main { gap: 8px; }
}
