/* LilyCatch — layout and theming.
   Built for iPhone and iPad in either orientation (spec §10). */

:root {
  --ink: #3a3340;
  --bg: #f7f3fb;
  --panel: #ffffff;
  --line: #e3dced;
  --shadow: 0 2px 0 #d9d1e6;
  --gold: #f5c542;
  --pink: #ff6b9d;
  --purple: #b07ce8;
  --green: #8fd0a8;
  --red: #e05c5c;
  --tap: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;                 /* no rubber-band scrolling of the page */
  overscroll-behavior: none;
  touch-action: manipulation;       /* no double-tap zoom */
  background: var(--bg);
  color: var(--ink);
  font: 700 18px/1.2 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

svg { display: block; width: 100%; height: 100%; }

/* ------------------------------------------------------------------- HUD */

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}

.chips { display: flex; gap: 6px; flex: 1 1 auto; min-width: 0; }

.chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1 1 0;
  min-width: 0;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 5px 8px 5px 6px;
}

.chip-ico { flex: 0 0 auto; width: 24px; height: 24px; }
/* Numerals are the one thing the player can actually read, so they must never
   be clipped — the type shrinks instead as the counts grow. */
.chip-num {
  font-size: clamp(13px, 3.7vw, 22px);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.icon-btn {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  padding: 8px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* -------------------------------------------------------------- Tab bar */

#tabbar {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 8px 10px 12px;
}

.tab {
  flex: 1 1 0;
  height: var(--tap);
  padding: 8px 6px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.tab svg { max-width: 40px; margin: 0 auto; }
.tab.active { background: #ffe9a8; transform: translateY(2px); box-shadow: none; }
/* Mute lives here rather than the HUD so the counters get the full width */
.tab-mute { flex: 0 0 var(--tap); }
.tab-mute svg { max-width: 30px; }

/* --------------------------------------------------------------- Stage */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 10px;
}

.panel {
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 10px;
  margin-bottom: 10px;
}

/* ------------------------------------------------------- Opening picker */

.setup-preview { max-width: 420px; margin: 0 auto 10px; }

.swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.swatch-row > .row-ico { flex: 0 0 34px; height: 34px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 auto; }

.swatch {
  width: 44px; height: 44px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.swatch.sel { outline: 4px solid var(--purple); outline-offset: 2px; }

.big-go {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 4px auto 16px;
  height: 72px;
  padding: 10px;
  background: var(--green);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.big-go svg { max-width: 48px; margin: 0 auto; }

/* ---------------------------------------------------------- House view */

.house-wrap { display: flex; flex-direction: column; gap: 10px; }

/* iPad and landscape phones get the room and character side by side */
@media (min-width: 720px) {
  .house-wrap { flex-direction: row; align-items: flex-start; }
  .house-wrap > .panel { flex: 1 1 0; margin-bottom: 0; }
  .house-wrap > .char-panel { flex: 0 0 38%; }
}

.room-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.room-head .spacer { flex: 1 1 auto; }
.room-dots { display: flex; gap: 6px; }
.room-dot { width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--ink); background: #fff; }
.room-dot.on { background: var(--purple); }

.room {
  position: relative;
  width: 100%;
  aspect-ratio: 320 / 200;
  border: 3px solid var(--ink);
  border-radius: 14px;
  overflow: hidden;
}
.room-bg { position: absolute; inset: 0; }

.slot {
  position: absolute;
  padding: 3px;
  background: transparent;
  border: 3px dashed rgba(58, 51, 64, 0.28);
  border-radius: 10px;
}
.slot.filled { border-style: solid; border-color: transparent; }
.slot > svg { pointer-events: none; }
.slot.empty > svg { opacity: 0.5; }

.slot-wall    { top: 11%; width: 16.2%; height: 26%; }
.slot-wall-0  { left: 28.1%; }
.slot-wall-1  { left: 50%; }
.slot-wall-2  { left: 71.9%; }

.slot-surface   { top: 44%; width: 12.5%; height: 20%; }
.slot-surface-0 { left: 32.5%; }
.slot-surface-1 { left: 61.2%; }

.slot-floor   { top: 67%; width: 19.4%; height: 31%; }
.slot-floor-0 { left: 4.4%; }
.slot-floor-1 { left: 28.1%; }
.slot-floor-2 { left: 51.9%; }
.slot-floor-3 { left: 75.6%; }

/* Keep the character from eating the screen so the outfit slots stay in view */
.char-stage { height: min(34vh, 260px); margin: 0 auto 10px; }
.char-svg { width: 100%; height: 100%; }
@media (min-width: 720px) { .char-stage { height: min(46vh, 340px); } }

.outfit-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.outfit-slot {
  aspect-ratio: 1;
  padding: 4px;
  background: #faf7fd;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.outfit-slot.empty { background: #f0ecf6; }
.outfit-slot svg { pointer-events: none; }

/* Buying another room */
.room-buy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: var(--tap);
  margin-top: 8px;
  padding: 8px 12px;
  background: #fff3d1;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 22px;
}
.room-buy .mini { width: 26px; height: 26px; flex: 0 0 auto; }

/* ----------------------------------------------------------- Shop view */

.shop-tabs { display: flex; gap: 10px; margin-bottom: 10px; }
.shop-tab {
  flex: 1 1 0;
  height: 54px;
  padding: 7px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.shop-tab svg { max-width: 34px; margin: 0 auto; }
.shop-tab.active { background: #ffe9a8; transform: translateY(2px); box-shadow: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
  padding-bottom: 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  font: inherit;
}
.tile:active { transform: translateY(2px); box-shadow: none; }
.tile-art { height: 84px; }
.tile-art svg { height: 100%; }

.tile-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.tile-row .mini { width: 20px; height: 20px; flex: 0 0 auto; }
.tile-row.cost-bad { color: var(--red); }
.tile.owned { background: #eefaf2; }
.tile.owned .tile-row .mini { width: 24px; height: 24px; }

/* -------------------------------------------------------------- Overlay */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(58, 51, 64, 0.55);
}
#overlay.hidden, #toast.hidden { display: none; }

.sheet {
  width: 100%;
  max-width: 460px;
  max-height: 84vh;
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: 24px;
}
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head .head-ico { width: 40px; height: 40px; flex: 0 0 auto; }
.sheet-head .spacer { flex: 1 1 auto; }

.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.pick {
  aspect-ratio: 1;
  padding: 6px;
  background: #faf7fd;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.pick:active { transform: translateY(2px); box-shadow: none; }
.pick.on { background: #ffe9a8; }
.pick.clear { background: #ffe3e3; }

/* Going broke, and milestone celebrations */
.broke-art { width: 110px; height: 110px; margin: 0 auto 6px; }
.big-number {
  text-align: center;
  font-size: clamp(40px, 13vw, 76px);
  font-variant-numeric: tabular-nums;
  margin: 4px 0 10px;
}
.celebrate { display: flex; align-items: center; justify-content: center; gap: 10px; }
.celebrate .mini { width: 52px; height: 52px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#toast .mini { width: 26px; height: 26px; }

#confetti { position: fixed; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; }
.confetto {
  position: absolute;
  width: 12px; height: 16px;
  border-radius: 3px;
  animation: fall 1.8s linear forwards;
}
@keyframes fall {
  from { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  to   { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}

/* A short pop whenever something is bought or placed */
.pop { animation: pop 0.32s ease-out; }
@keyframes pop {
  0%   { transform: scale(0.4); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

button { font: inherit; color: inherit; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .pop, .confetto { animation: none; }
}

/* ---- Icon capture (?bare=1) ----
   Everything but the character is stripped, and the character is centred large
   on a soft warm bloom so the icon reads as an object sitting on the home
   screen rather than a hole punched in it. Held to ~76% so it survives iOS
   corner-rounding and the maskable safe circle. Inert without the query. */
body.bare #hud,
body.bare #tabbar { display: none; }
body.bare #app {
  padding: 0;
  background: radial-gradient(circle at 50% 47%, #fff3d6 0%, #fbeede 42%, #f4e6f3 100%);
}
body.bare #stage { padding: 0; overflow: hidden; }
body.bare .house-wrap { height: 100%; margin: 0; flex-direction: row; }
body.bare .house-wrap > .panel:not(.char-panel) { display: none; }
body.bare .char-panel {
  flex: 1 1 auto;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.bare .outfit-grid { display: none; }
body.bare .char-stage { height: 76%; max-width: none; margin: 0; }
