/* Roundup — warm toy-box UI */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --ink: #3d3229;
  --paper: #fdf6ec;
  --card: #fffdf8;
  --accent: #f4a83c;
  --accent-dark: #d98a1f;
  --green: #7fc06e;
  --shadow: 0 4px 14px rgba(61, 50, 41, .18);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #bfe3f2;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 0;
  pointer-events: none;
  z-index: 10;
}
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; }

.chip {
  background: var(--card);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  border: none;
  color: var(--ink);
  pointer-events: auto;
  white-space: nowrap;
}
.chip.clickable { cursor: pointer; }
.chip.clickable:active { transform: scale(.96); }
.star-chip { color: var(--accent-dark); }
#title-chip { font-weight: 900; letter-spacing: .3px; }
#title-chip .ver { font-size: 10px; font-weight: 700; opacity: .55; margin-left: 2px; }

/* ---------- Bottom panels ---------- */
.bottom-panel {
  position: absolute; left: 0; right: 0;
  bottom: calc(58px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px;
  z-index: 10;
  pointer-events: none;
}
.bottom-panel > * { pointer-events: auto; }

#puzzle-status { display: flex; gap: 8px; justify-content: center; align-items: center; }
#animal-chip { font-size: 14px; }
#proj-stars { letter-spacing: 2px; color: var(--accent-dark); }

#queue-strip {
  display: flex; gap: 6px; justify-content: flex-start;
  overflow-x: auto; scrollbar-width: none;
  padding: 4px 2px; min-height: 44px;
  mask-image: linear-gradient(90deg, #000 92%, transparent);
}
#queue-strip::-webkit-scrollbar { display: none; }
#queue-strip:empty::before {
  content: "tap a glowing tile to plan your route";
  font-size: 12.5px; opacity: .75; margin: auto;
  background: rgba(255,253,248,.75); padding: 6px 12px; border-radius: 999px;
}
.qmove {
  flex: 0 0 auto;
  width: 36px; height: 36px; border-radius: 10px;
  border: none; font-size: 17px; font-weight: 800;
  color: #fff; box-shadow: 0 2px 6px rgba(61,50,41,.25);
  cursor: pointer;
  display: grid; place-items: center;
}
.qmove:active { transform: scale(.92); }
.qmove { position: relative; }
.qmove .qbadge { position: absolute; right: -4px; top: -6px; font-size: 12px; font-style: normal; }
.qmove.deep  { background: #2a6ba8; }
.qmove.mud   { background: #8a6a4a; }
.qmove.mound { background: #b08a5e; }
.qmove.ledge { background: #8d8478; }
.qmove.bramble { background: #4d6c48; }
.qmove.open  { background: #8bc34a; }
.qmove.water { background: #4fa8d8; }
.qmove.gap   { background: #8d7aa5; }
.qmove.rubble{ background: #a08a6e; }
.qmove.starred { outline: 3px solid var(--accent); outline-offset: -1px; }

#puzzle-buttons { display: flex; gap: 8px; justify-content: center; }

.btn {
  border: none; border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 15px; font-weight: 800;
  cursor: pointer; box-shadow: var(--shadow);
  color: var(--ink); background: var(--card);
  min-height: 46px;
}
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn.subtle { background: var(--card); }
.btn.danger { background: #e2695d; color: #fff; }

/* ---------- Pen panel ---------- */
#pen-panel { align-items: center; }
#pen-title-row { display: flex; align-items: center; gap: 14px; }
.pen-name {
  font-size: 18px; font-weight: 900;
  background: var(--card); border-radius: 999px; padding: 8px 22px;
  box-shadow: var(--shadow); min-width: 120px; text-align: center;
}
.pen-arrow { min-height: 40px; padding: 8px 14px; border-radius: 999px; font-size: 20px; line-height: 1; }
#pen-dots { display: flex; gap: 6px; }
#pen-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(61,50,41,.3); }
#pen-dots .dot.active { background: var(--ink); }

/* ---------- Tab bar ---------- */
#tabbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: calc(58px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--card);
  box-shadow: 0 -4px 16px rgba(61,50,41,.12);
  z-index: 20;
}
.tab {
  flex: 1; border: none; background: none;
  font-size: 19px; font-weight: 700; color: var(--ink);
  opacity: .45; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.tab span { font-size: 11px; font-weight: 800; }
.tab.active { opacity: 1; }

/* ---------- Pen overlays (ⓘ, price tags) ---------- */
#pen-overlays { position: absolute; inset: 0; pointer-events: none; z-index: 8; overflow: hidden; }
.pen-tag {
  position: absolute; transform: translate(-50%, -100%);
  pointer-events: auto; cursor: pointer; border: none;
  background: var(--card); border-radius: 999px;
  box-shadow: var(--shadow); font-weight: 800; color: var(--ink);
}
.pen-tag.info {
  width: 26px; height: 26px; font-size: 14px; font-style: italic;
  font-family: Georgia, serif; opacity: .92;
}
.pen-tag.price { padding: 6px 12px; font-size: 13px; color: var(--accent-dark); }
.pen-tag.price.cant { color: #a09383; }

/* ---------- Speech bubble ---------- */
#bubble-root { position: absolute; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.bubble {
  position: absolute; transform: translate(-50%, -100%);
  max-width: 230px;
  background: var(--card); color: var(--ink);
  border-radius: 14px; padding: 10px 14px;
  font-size: 14px; font-weight: 700; line-height: 1.3;
  box-shadow: var(--shadow);
  animation: bubble-pop .25s ease-out;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -7px;
  width: 14px; height: 14px; background: var(--card);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 3px;
}
@keyframes bubble-pop { from { transform: translate(-50%,-90%) scale(.6); opacity: 0; } }

/* ---------- Modals ---------- */
#modal-root {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(45, 36, 28, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--paper);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
  padding: 22px 20px;
  width: min(400px, 100%);
  max-height: 82vh; overflow-y: auto;
  animation: modal-pop .22s ease-out;
}
@keyframes modal-pop { from { transform: scale(.85); opacity: 0; } }
.modal h2 { font-size: 20px; margin-bottom: 8px; }
.modal p { font-size: 14.5px; line-height: 1.45; margin-bottom: 14px; }
.modal .modal-buttons { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal .modal-buttons .btn { flex: 1; }

/* Results overlay content */
.result-stars { font-size: 44px; text-align: center; letter-spacing: 6px; margin: 6px 0 2px; }
.result-sub { text-align: center; font-size: 15px; font-weight: 700; opacity: .85; margin-bottom: 12px; }
.share-box {
  background: var(--card); border-radius: 12px; padding: 12px;
  font-family: ui-monospace, Consolas, monospace; font-size: 13.5px;
  white-space: pre-wrap; margin-bottom: 14px; box-shadow: inset 0 0 0 1.5px rgba(61,50,41,.12);
}

/* Roster picker */
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; margin-bottom: 6px; }
.roster-biome { font-size: 13px; font-weight: 900; opacity: .75; margin: 10px 2px 6px; }
.roster-card {
  border: none; background: var(--card); border-radius: 14px;
  box-shadow: var(--shadow); padding: 12px 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer; color: var(--ink);
}
.roster-card:active:not(:disabled) { transform: scale(.95); }
.roster-card .re { font-size: 30px; }
.roster-card .rn { font-size: 13px; font-weight: 800; }
.roster-card .rt { font-size: 11px; opacity: .7; font-weight: 700; }
.roster-card.selected { outline: 3px solid var(--accent); }
.roster-card:disabled { opacity: .45; }
.roster-card .mastery { font-size: 11px; color: var(--accent-dark); font-weight: 800; }

/* Stats overlay rows */
.stat-row { display: flex; justify-content: space-between; font-size: 15px; font-weight: 700; padding: 7px 2px; border-bottom: 1.5px dashed rgba(61,50,41,.15); }
.stat-row:last-of-type { border-bottom: none; }

/* ---------- Start tooltip (first day only) ---------- */
#start-tip {
  position: absolute; transform: translate(-50%, -100%);
  background: var(--ink); color: #fff;
  padding: 8px 14px; border-radius: 12px;
  font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow); z-index: 9;
  pointer-events: none; white-space: nowrap;
  animation: bubble-pop .3s ease-out;
}
#start-tip::after {
  content: ""; position: absolute; left: 50%; bottom: -6px;
  width: 12px; height: 12px; background: var(--ink);
  transform: translateX(-50%) rotate(45deg); border-radius: 2px;
}

/* ---------- Calendar ---------- */
.cal-row {
  display: grid; grid-template-columns: 46px 1fr 52px auto;
  align-items: center; gap: 6px;
  width: 100%; border: none; background: var(--card);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 7px;
  font: inherit; font-weight: 700; color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer; text-align: left;
}
.cal-row:active { transform: scale(.98); }
.cal-row.current { outline: 3px solid var(--accent); }
.cal-day { font-weight: 900; }
.cal-diff { font-size: 9px; letter-spacing: 1px; opacity: .55; }
.cal-res { color: var(--accent-dark); font-size: 13px; }

/* ---------- Floating stat card (collection) ---------- */
.stat-card {
  position: absolute; transform: translate(-50%, -100%);
  width: 195px; background: var(--card);
  border-radius: 16px; padding: 12px 14px 10px;
  box-shadow: 0 8px 24px rgba(61,50,41,.3);
  pointer-events: auto;
  animation: bubble-pop .22s ease-out;
  z-index: 9;
}
.stat-card::after {
  content: ""; position: absolute; left: 50%; bottom: -7px;
  width: 14px; height: 14px; background: var(--card);
  transform: translateX(-50%) rotate(45deg); border-radius: 3px;
}
.stat-card .sc-head { font-size: 16px; }
.stat-card .sc-sub { font-size: 12px; font-weight: 700; opacity: .75; margin: 2px 0; }
.stat-card .sc-ability { font-size: 12px; font-weight: 700; color: var(--accent-dark); margin-bottom: 6px; }
.stat-card .sc-stats { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 800; margin-bottom: 8px; }
.stat-card .sc-play { width: 100%; min-height: 38px; padding: 8px; font-size: 13.5px; }

/* ---------- Shop ---------- */
#shop-screen {
  position: absolute; inset: 0;
  top: calc(52px + env(safe-area-inset-top, 0px));
  bottom: calc(58px + var(--safe-bottom));
  overflow-y: auto; z-index: 5;
  background: linear-gradient(160deg, #f7ead3, #f2dfc2);
  padding: 14px 14px 24px;
}
.shop-head { text-align: center; margin-bottom: 14px; }
.shop-head h2 { font-size: 24px; }
.shop-head p { font-size: 13.5px; font-weight: 700; opacity: .75; }
.shop-cards {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  max-width: 640px; margin: 0 auto;
}
.shop-card {
  background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); padding: 18px 12px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-align: center;
}
.shop-emoji { font-size: 46px; line-height: 1.1; filter: drop-shadow(0 3px 4px rgba(61,50,41,.25)); }
.shop-view { width: 150px; height: 140px; border-radius: 12px; background: linear-gradient(180deg, rgba(191,227,242,.55), rgba(216,238,205,.55)); }
.shop-card.owned { opacity: .72; }
.shop-name { font-size: 16px; font-weight: 900; }
.shop-cat { font-size: 12.5px; font-weight: 800; color: var(--accent-dark); }
.shop-bio { font-size: 12px; font-weight: 700; opacity: .7; }
.shop-ability { font-size: 11.5px; font-weight: 700; opacity: .75; min-height: 28px; margin: 3px 0; }
.shop-buy { width: 100%; }
.shop-need { font-size: 11px; font-weight: 800; opacity: .6; margin-top: 4px; }
.shop-foot { text-align: center; font-size: 12.5px; font-weight: 700; opacity: .65; margin-top: 16px; }

/* ---------- Toasts ---------- */
#toast-root {
  position: absolute; left: 0; right: 0; top: calc(64px + env(safe-area-inset-top, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 50; pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 700;
  box-shadow: var(--shadow);
  animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { transform: translateY(-14px); opacity: 0; } }
.toast.out { transition: opacity .3s, transform .3s; opacity: 0; transform: translateY(-10px); }

/* ---------- Loading ---------- */
#loading {
  position: absolute; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #bfe3f2, #d8eecd);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .4s;
}
#loading.out { opacity: 0; pointer-events: none; }
.load-card { text-align: center; }
.load-title { font-size: 42px; font-weight: 900; letter-spacing: 1px; color: var(--ink); }
.load-sub { font-size: 14px; font-weight: 700; opacity: .7; margin: 6px 0 18px; }
.load-bar { width: 210px; height: 12px; border-radius: 999px; background: rgba(255,255,255,.6); overflow: hidden; margin: 0 auto; box-shadow: inset 0 1px 3px rgba(0,0,0,.12); }
#load-fill { width: 0%; height: 100%; border-radius: 999px; background: var(--accent); transition: width .2s; }

@media (max-width: 400px) {
  .chip { font-size: 13px; padding: 7px 11px; }
  .btn { padding: 11px 13px; font-size: 14px; }
  .pen-name { font-size: 16px; min-width: 100px; }
}
