* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0f172a;
  overflow: hidden;
  font-family: Fredoka, "Trebuchet MS", "Segoe UI", sans-serif;
  color: #1f2937;
  user-select: none;
}

#wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: none;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

#game { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; }
button { touch-action: manipulation; }

/* Shop / Pause / Full screen, top right; fit() sets `top` below the scaled HUD panel */
#hudBtns {
  position: absolute;
  right: 1.2%;
  top: 12.5%;
  display: flex;
  gap: 6px;
}
.hudbtn {
  padding: 6px 14px;
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid #334155;
  border-radius: 999px;
  box-shadow: 0 3px 0 #334155;
}
.hudbtn:hover { background: #fff; }
.hudbtn.shop { color: #422006; background: #fde047; border-color: #ca8a04; box-shadow: 0 3px 0 #a16207; }
.hudbtn.shop:hover { background: #fef08a; }
#fsBtn { display: none; }
body.touch #fsBtn:not(.hidden) { display: block; }

.touch-only { display: none; }
body.touch .touch-only { display: table; }
body.touch .desktop-only { display: none; }

#rotate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px;
  text-align: center;
  font-size: 18px;
  color: #f8fafc;
  background: #0f172a;
}
#rotate.hidden { display: none; }
#rotate .phone {
  width: 54px;
  height: 92px;
  border: 5px solid #fde047;
  border-radius: 12px;
  animation: tip 2.4s ease-in-out infinite;
}
@keyframes tip { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (prefers-reduced-motion: reduce) { #rotate .phone { animation: none; transform: rotate(-90deg); } }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  cursor: default;
}

.box {
  background: #fffbeb;
  border: 4px solid #1f2937;
  border-radius: 24px;
  box-shadow: 0 8px 0 #1f2937;
  padding: 24px 32px;
  max-width: 560px;
  max-height: 94%;
  overflow: auto;
  text-align: center;
}
.box h1 {
  margin: 0 0 8px;
  font-size: 44px;
  color: #ef4444;
  text-shadow: 3px 3px 0 #1f2937;
  letter-spacing: 1px;
}
.box p { margin: 8px 0; line-height: 1.35; }
.box .small { font-size: 14px; color: #57534e; }
.box button {
  margin: 12px 6px 0;
  padding: 10px 28px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: #22c55e;
  border: 3px solid #1f2937;
  border-radius: 14px;
  box-shadow: 0 4px 0 #1f2937;
}
.box button:hover { background: #16a34a; }
.box button:active { transform: translateY(3px); box-shadow: 0 1px 0 #1f2937; }
.box button.danger { background: #ef4444; font-size: 16px; }
.box button.warn { background: #f97316; font-size: 16px; }
.box button.danger:hover { background: #dc2626; }

.box.wide { max-width: 860px; width: 92%; }
/* the pause menu: its buttons wrap into rows, so the whole menu fits a short viewport (an artifact panel) */
#pause .box { max-width: 640px; }
#pause .row { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 6px; }
#pause .row button { margin: 0; }
/* the upgrade panel: the list scrolls on its own, so the note and the buttons under it stay in view */
#picker .box { display: flex; flex-direction: column; overflow: hidden; }
#pickerList { overflow: auto; flex: 0 1 auto; min-height: 0; }
.box h3 { margin: 6px 0 8px; font-size: 20px; }
.box button.secondary {
  font-size: 16px;
  padding: 8px 18px;
  color: #1f2937;
  background: #fde68a;
}
.box button.secondary:hover { background: #fcd34d; }

.continue {
  margin: 10px 0 4px;
  padding: 8px 12px;
  background: #dcfce7;
  border: 2px solid #22c55e;
  border-radius: 14px;
}
.continue button { margin: 0 12px 0 0; padding: 6px 22px; font-size: 18px; }
.continue .small { color: #166534 !important; }

.cols { display: flex; gap: 24px; text-align: left; margin-top: 10px; }
.cols .setup { flex: 1.6; }
.cols .help { flex: 1; border-left: 2px dashed #e7e5e4; padding-left: 20px; }
.cols .setup > button { margin-left: 0; }
.label { font-size: 13px; font-weight: 700; color: #78716c; text-transform: uppercase; margin: 8px 0 4px; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.box .choice {
  margin: 0;
  padding: 6px 10px;
  text-align: left;
  font-size: 15px;
  font-weight: 400;
  color: #1f2937;
  background: #fff;
  border: 2px solid #d6d3d1;
  border-radius: 12px;
  box-shadow: none;
}
.box .choice:hover { background: #fefce8; }
.box .choice.on { background: #fef9c3; border-color: #ca8a04; box-shadow: 0 0 0 2px #facc15; }
.choice b { font-size: 17px; }
.choice .mult { float: right; font-size: 13px; font-weight: 700; color: #15803d; }
.choice small { display: block; font-size: 12.5px; color: #57534e; line-height: 1.3; }
.choice small.stats { font-size: 11px; color: #a8a29e; }

.rank { font-size: 20px; font-weight: 600; color: #b45309; }
#playerName {
  font: inherit;
  font-size: 18px;
  padding: 4px 10px;
  width: 100%;
  max-width: 260px;
  border: 2px solid #1f2937;
  border-radius: 10px;
  background: #fff;
  user-select: text;
}
.box .career { margin: 8px 0 0; font-weight: 600; color: #7c2d12; }

#scores { z-index: 5; }
/* the review: one card per level; the list scrolls on its own, so the Close button stays in view */
#review { z-index: 5; }
#review .box { display: flex; flex-direction: column; overflow: hidden; }
#review .box > button { align-self: center; }
#reviewList { overflow: auto; flex: 0 1 auto; min-height: 0; margin-top: 8px; text-align: left; }
.rv-level { background: #fff; border: 2px solid #e7e5e4; border-radius: 14px; padding: 10px 14px; margin-bottom: 8px; }
.rv-level h3 { margin: 0 0 4px; }
.rv-level h3 span { font-size: 14px; font-weight: 400; color: #57534e; }
.rv-money { display: flex; gap: 18px; font-size: 16px; margin-bottom: 4px; }
.rv-money .in b { color: #15803d; }
.rv-money .out b { color: #b91c1c; }
.rv-row { display: flex; gap: 10px; align-items: baseline; font-size: 14px; margin-top: 4px; }
.rv-label { flex: 0 0 110px; font-weight: 700; color: #78716c; }
.rv-label b { color: #1f2937; }
.rv-items { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.rv-item { background: #fef9c3; border-radius: 8px; padding: 1px 8px; }
.rv-level .small { margin: 4px 0 0; }
@media (max-width: 560px) { .rv-row { flex-direction: column; gap: 2px; } .rv-label { flex: none; } }
#picker { z-index: 6; }
#speedRow { background: none; padding: 0; }
#hsViews { padding-top: 0; }
#pause .small { margin-bottom: 2px; }
.box button:disabled { background: #d6d3d1; color: #78716c; cursor: not-allowed; box-shadow: none; }
#pickerNote { margin: 6px 0 0; min-height: 1em; }
#pickerList { margin-top: 10px; text-align: left; }
#pickerList .card .act button { margin: 0; font-size: 16px; padding: 8px 18px; }
.cols .help > #pickBtn { margin: 6px 0 0; }
.practice { margin: 10px 0 0; font-size: 14px; color: #44403c; }
.practice input { font: inherit; width: 54px; padding: 2px 6px; border: 2px solid #1f2937; border-radius: 8px; text-align: center; }
.practice button { margin: 4px 0 0; font-size: 15px; padding: 6px 14px; display: block; }
.practice .small { display: block; margin-top: 2px; }
.cols .help > .controls-head { margin-top: 16px; }
#scores .tabs { justify-content: center; background: none; padding: 6px 0 0; }
#scores .tabs { border-bottom: 3px solid #1f2937; gap: 6px; }
.box .tab {
  margin: 0;
  padding: 6px 18px;
  font-size: 17px;
  color: #57534e;
  background: #fde68a;
  border: 3px solid #1f2937;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  box-shadow: none;
}
.box .tab:hover { background: #fcd34d; }
.box .tab.on { background: #fff; color: #1f2937; position: relative; top: 3px; }
.box .tab:active { transform: none; box-shadow: none; }
#scores .tab small { font-weight: 400; color: #78716c; }
.pills { display: flex; justify-content: center; gap: 6px; padding: 10px 0 8px; background: #fff; }
.box .pill {
  margin: 0;
  padding: 4px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #57534e;
  background: #f5f5f4;
  border: 2px solid #d6d3d1;
  border-radius: 999px;
  box-shadow: none;
}
.box .pill:hover { background: #fef9c3; }
.box .pill.on { color: #1f2937; background: #fde047; border-color: #ca8a04; }
.box .pill:active { transform: none; box-shadow: none; }
table.hs { width: 100%; border-collapse: collapse; font-size: 16px; background: #fff; }
table.hs th { font-size: 13px; color: #78716c; text-align: left; padding: 6px 10px; border-bottom: 2px solid #e7e5e4; }
table.hs td { padding: 5px 10px; text-align: left; border-bottom: 1px solid #f5f5f4; }
table.hs tr.me td { background: #fef9c3; }
.hswrap { max-height: 300px; overflow: auto; }
table.hs th.num, table.hs td.num { text-align: right; font-variant-numeric: tabular-nums; }
.hs-status { margin: 6px 0; min-height: 1.2em; font-size: 13px; color: #64748b; } /* 4.6:1 on the cream box */
.hs-status.bad { color: #b91c1c; } /* 6.3:1 */
.box button.mini {
  margin: 0;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #1f2937;
  background: #fde68a;
  border: 2px solid #1f2937;
  border-radius: 8px;
  box-shadow: none;
}
.box button.mini:hover { background: #fcd34d; }
.box button.mini:active { transform: translateY(1px); box-shadow: none; }
input:focus-visible, button:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }
table.hs td.empty { text-align: center; color: #78716c; padding: 24px; }

.keys {
  margin: 12px auto;
  border-collapse: collapse;
  font-size: 15px;
  text-align: left;
}
.keys td { padding: 3px 10px; }
.keys td:first-child { font-weight: 700; text-align: right; color: #7c2d12; }

/* ---------- shop ---------- */
.shop-panel {
  width: 88%;
  height: 90%;
  display: flex;
  flex-direction: column;
  background: #fffbeb;
  border: 4px solid #1f2937;
  border-radius: 22px;
  box-shadow: 0 8px 0 #1f2937;
  overflow: hidden;
}
.shop-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: #fde047;
  border-bottom: 3px solid #1f2937;
}
.shop-head h2 { margin: 0; font-size: 28px; }
.shop-head .money {
  font-size: 24px;
  font-weight: 700;
  color: #166534;
  background: #fff;
  border: 2px solid #1f2937;
  border-radius: 999px;
  padding: 2px 14px;
}
.shop-head .close {
  margin-left: auto;
  width: 38px;
  height: 38px;
  font-size: 20px;
  border: 3px solid #1f2937;
  border-radius: 50%;
  background: #fff;
}
.shop-head .close:hover { background: #fecaca; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 18px 0;
  border-bottom: 3px solid #1f2937;
  background: #fef3c7;
}
.tab {
  padding: 6px 18px;
  font-size: 17px;
  font-weight: 700;
  background: #fde68a;
  border: 3px solid #1f2937;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  color: #57534e;
}
.tab.on { background: #fffbeb; color: #1f2937; position: relative; top: 3px; }

.shop-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
}
.shop-foot {
  padding: 6px 18px;
  font-size: 13px;
  color: #57534e;
  border-top: 2px solid #e7e5e4;
}

.note { margin: 2px 0 10px; font-size: 14px; color: #57534e; }

.shop-body h4 {
  margin: 16px 0 6px;
  font-size: 18px;
}
.shop-body h4 span { font-size: 13px; font-weight: 400; color: #78716c; }
.shop-body h4.dim { color: #a8a29e; }

.card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 2px solid #d6d3d1;
  border-radius: 14px;
}
.card.cur { border-color: #ca8a04; background: #fefce8; }
.card.next { border-color: #3b82f6; background: #eff6ff; }
.card.dim { opacity: 0.5; }
.card .icon {
  flex: none;
  background: #e0f2fe;
  border-radius: 10px;
}
.card .info { flex: 1; min-width: 0; }
.card h3 { margin: 0; font-size: 18px; }
.card h3 em {
  font-style: normal;
  font-size: 12px;
  color: #fff;
  background: #ca8a04;
  border-radius: 6px;
  padding: 1px 6px;
  vertical-align: middle;
}
.card p { margin: 2px 0 0; font-size: 14px; color: #44403c; }
.card p.small { font-size: 12.5px; color: #78716c; }
.card .act { flex: none; }

.buy {
  min-width: 130px;
  padding: 7px 12px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #22c55e;
  border: 2px solid #1f2937;
  border-radius: 10px;
  box-shadow: 0 3px 0 #1f2937;
}
.buy b { font-weight: 700; }
.buy:hover { background: #16a34a; }
.buy:active { transform: translateY(2px); box-shadow: 0 1px 0 #1f2937; }
.buy.no { background: #a8a29e; }
.buy.on { background: #ca8a04; cursor: default; }
.buy:disabled { background: #d6d3d1; color: #78716c; cursor: not-allowed; box-shadow: none; }
.free { display: inline-block; min-width: 130px; text-align: center; font-weight: 700; color: #15803d; }

.bars { flex: none; width: 200px; }
.bar { display: flex; align-items: center; gap: 6px; font-size: 11px; line-height: 13px; color: #57534e; }
.bar span { width: 80px; text-align: right; }
.bar i { flex: 1; height: 7px; background: #e7e5e4; border-radius: 4px; overflow: hidden; }
.bar b { display: block; height: 100%; background: linear-gradient(90deg, #f97316, #22c55e); border-radius: 4px; }

.pips { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; }
.pips i { width: 14px; height: 14px; border: 2px solid #1f2937; border-radius: 50%; background: #fff; }
.pips i.on { background: #facc15; }
.pips i.locked { border-style: dashed; border-color: #a8a29e; background: #e7e5e4; }
.free.locked { color: #78716c; font-size: 13px; line-height: 1.25; }
.card.locked { opacity: 0.6; }
.card h3 em.lock { background: #78716c; }

.guide { display: flex; flex-wrap: wrap; gap: 8px; }
.gb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 6px;
  font-size: 12.5px;
  line-height: 1.3;
  background: #fff;
  border: 2px solid #e7e5e4;
  border-radius: 12px;
}
.gb .icon { background: transparent !important; }
.gb.dim { opacity: 0.45; }

/* ---------- compact layout for short screens (phones in landscape) ---------- */
@media (max-height: 540px) {
  .box { padding: 10px 16px; border-radius: 16px; border-width: 3px; box-shadow: 0 4px 0 #1f2937; }
  .box h1 { font-size: 26px; margin-bottom: 2px; text-shadow: 2px 2px 0 #1f2937; }
  .box h3 { font-size: 16px; margin: 2px 0 4px; }
  .box p { font-size: 13px; margin: 4px 0; }
  .box button { font-size: 16px; padding: 6px 16px; margin-top: 8px; }
  .box button.secondary { font-size: 14px; padding: 5px 12px; }
  .cols { gap: 12px; margin-top: 4px; }
  .cols .help { padding-left: 12px; }
  .label { margin: 4px 0 3px; font-size: 11px; }
  .choices { gap: 4px; }
  .box .choice { padding: 4px 8px; }
  .choice b { font-size: 14px; }
  .choice small { font-size: 11px; }
  .choice small.stats { display: none; }
  .keys { font-size: 12px; margin: 4px auto; }
  .keys td { padding: 1px 6px; }
  .continue { margin: 6px 0 2px; padding: 4px 8px; }
  .continue button { font-size: 15px; padding: 4px 14px; }
  .rank { font-size: 15px; }
  #playerName { font-size: 15px; padding: 2px 8px; }
  .box .career { margin-top: 4px; }
  #pickerList { margin-top: 4px; }
  #pickerList .card { margin-bottom: 4px; }
  #pickerList .card .act button { font-size: 14px; padding: 5px 12px; }
  .cols .help > .controls-head { margin-top: 8px; }

  .shop-panel { width: 96%; height: 96%; border-width: 3px; border-radius: 14px; }
  .shop-head { padding: 4px 12px; gap: 10px; }
  .shop-head h2 { font-size: 20px; }
  .shop-head .money { font-size: 16px; padding: 1px 10px; }
  .shop-head .close { width: 32px; height: 32px; font-size: 16px; }
  .tabs { padding: 6px 10px 0; }
  .tab, .box .tab { font-size: 14px; padding: 4px 10px; }
  .shop-body { padding: 8px 10px; }
  .shop-foot { display: none; }
  .card { flex-wrap: wrap; gap: 8px; padding: 6px 8px; }
  .card h3 { font-size: 15px; }
  .card p { font-size: 12px; }
  .bars { width: 150px; }
  .bar span { width: 64px; }
  .buy, .free { min-width: 96px; font-size: 13px; }
  .hswrap { max-height: 150px; }
  table.hs { font-size: 13px; }
  .hudbtn { font-size: 13px; padding: 4px 10px; border-width: 2px; }
}
