/* ==========================================================================
   App shell — device frame, nav rail, top bar, and reusable UI atoms.
   Table-first, tactile: warm felt surfaces, capiz translucency, soft corners,
   generous touch targets (lolas-first, PRD §12–13).
   ========================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  color: var(--bone);
  background: var(--panel-warm);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; -webkit-tap-highlight-color: transparent; }
button:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 3px; box-shadow: var(--focus-ring); }
img { max-width: 100%; }

#app {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0px, 2vmin, 28px);
}

/* ---- The device / stage ---- */
.device {
  position: relative;
  width: min(100%, 1180px);
  height: min(100%, 620px);
  aspect-ratio: 1180 / 620;
  display: flex;
  border-radius: clamp(20px, 3vmin, 40px);
  overflow: hidden;
  background: var(--felt-app);
  box-shadow: var(--shadow-pop), 0 0 0 1px rgba(247,207,105,0.12);
  isolation: isolate;
}
.device::before { /* banig weave warmth */
  content: ''; position: absolute; inset: 0; z-index: 0;
  background-image: var(--banig); pointer-events: none;
}
.device::after { /* soft vignette for depth */
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  box-shadow: inset 0 0 100px rgba(0,0,0,0.32);
}

/* ---- Nav rail ---- */
.rail {
  position: relative; z-index: 25;
  width: var(--rail-w); flex: 0 0 var(--rail-w);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0 16px;
  background: linear-gradient(180deg, rgba(5,35,26,0.74), rgba(4,25,19,0.94));
  border-right: 1px solid var(--line-gold);
}
.rail[hidden] { display: none; }
.rail__brand { margin-bottom: 8px; display: flex; align-items: center; justify-content: center; padding: 0; background: none; border: 0; cursor: pointer; min-height: 44px; }
/* Live "people online" at the top of the rail (replaces the old logo mark).
   Hidden until the first presence heartbeat lands (.is-on). */
.rail__online { display: none; flex-direction: column; align-items: center; gap: 1px; width: 62px; padding: 7px 0;
  border-radius: 14px; border: 1px solid var(--line-gold); background: rgba(6,28,20,.55); }
.rail__online.is-on { display: flex; }
.rail__onlineDot { width: 7px; height: 7px; border-radius: 50%; background: #35C46A; animation: mpm-pulse 2.4s ease-out infinite; }
.rail__onlineN { font-size: 14px; font-weight: 800; color: var(--bone-bright); line-height: 1.1; font-variant-numeric: tabular-nums; }
.rail__onlineLbl { font-size: 8.5px; font-weight: 700; letter-spacing: .3px; color: var(--bone-dim); text-transform: uppercase; }
@media (prefers-reduced-motion: reduce) { .rail__onlineDot { animation: none; } }
.rail__nav { flex: 1; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.rail__item {
  position: relative;
  width: 62px; padding: 9px 0; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  color: var(--bone-dim); border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.rail__item::before { content:''; position:absolute; left:-12px; top:14px; bottom:14px; width:3px; border-radius:0 3px 3px 0; background:var(--grad-gold); opacity:0; transform:scaleY(.45); transition:opacity .15s, transform .15s; }
.rail__item:hover { color: var(--bone); background: rgba(255,255,255,0.045); transform:translateY(-1px); }
.rail__item.is-active { color: var(--gold-hi); background: rgba(224,164,44,0.13); border-color: var(--line-gold-2); }
.rail__item.is-active::before { opacity:1; transform:scaleY(1); }
.rail__ico { width: 34px; height: 28px; border-radius:9px; display: grid; place-items: center; transition:background .15s, box-shadow .15s; }
.rail__item.is-active .rail__ico { background:linear-gradient(180deg,rgba(247,207,105,.18),rgba(224,164,44,.08)); box-shadow:inset 0 1px 0 rgba(255,255,255,.08); }
.rail__label { font-size: 9.5px; font-weight: 700; letter-spacing: .2px; text-align: center; }
.rail__fs { margin-top: 6px; cursor: pointer; background: none; border: 1px solid transparent; }
.rail__fs .rail__ico svg { width: 19px; height: 19px; }

/* ---- Stage / screens ---- */
.stage { position: relative; z-index: 10; flex: 1; min-width: 0; display: flex; overflow: hidden; }
.screen { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }
.screen--pad { padding: 16px 22px 20px; overflow: auto; }

/* Top status bar (faux device chrome + contextual header) */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px 4px; color: var(--bone-dim);
  font-size: 12px; font-variant-numeric: tabular-nums; flex: 0 0 auto;
}
.topbar .clock { font-weight: 700; color: var(--bone); }
.topbar .spacer { flex: 1; }
.topbar .sysico { display: inline-flex; gap: 5px; align-items: center; opacity: .7; }

/* Live "people online" pill (Home topbar). Hidden until presence.js reports a
   real count, so it never flashes a placeholder. */
.home__online { display: none; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--bone); white-space: nowrap; font-variant-numeric: tabular-nums; }
.home__online.is-on { display: inline-flex; }
.home__onlineDot { width: 7px; height: 7px; border-radius: 50%; background: #35C46A; animation: mpm-pulse 2.4s ease-out infinite; }
@keyframes mpm-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(53,196,106,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(53,196,106,0); }
  100% { box-shadow: 0 0 0 0 rgba(53,196,106,0); }
}

/* ---- Currency counters (cosmetics/progression only — never a stake) ---- */
.wallet { display: flex; gap: 10px; align-items: center; }
.counter {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 10px; border-radius: var(--r-pill);
  background: rgba(5,26,19,0.72); border: 1px solid var(--line-gold);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
.counter b { font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .2px; color: var(--bone-bright); font-size: 14px; }
.counter .coin {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 9px; letter-spacing: -0.5px; font-weight: 800; color: #3a2a06;
  background: radial-gradient(circle at 38% 30%, #F7CF69, #E0A42C 70%);
  box-shadow: inset 0 0 0 1.5px rgba(120,80,10,.35);
}
.counter .gem {
  width: 20px; height: 20px;
  background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><defs><linearGradient id='g' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%23FBD97A'/><stop offset='1' stop-color='%23D89B22'/></linearGradient></defs><g stroke='%237E5A12' stroke-width='0.9' stroke-linejoin='round'><path d='M2.2 13.3 L10.8 13.3 L11.9 18.9 L1.1 18.9 Z' fill='url(%23g)'/><path d='M13.2 13.3 L21.8 13.3 L22.9 18.9 L12.1 18.9 Z' fill='url(%23g)'/><path d='M7.7 6.5 L16.3 6.5 L17.4 12.1 L6.6 12.1 Z' fill='url(%23g)'/></g><g stroke='%23FCE7A8' stroke-width='0.9' stroke-linecap='round' opacity='0.8' fill='none'><path d='M3.1 14.4 L10 14.4'/><path d='M14.1 14.4 L21 14.4'/><path d='M8.6 7.6 L15.4 7.6'/></g></svg>") center/contain no-repeat;
}
.counter .plus {
  width: 20px; height: 20px; border-radius: 50%; font-size: 15px; line-height: 1;
  display: grid; place-items: center; color: var(--gold-hi);
  background: rgba(224,164,44,0.14); border: 1px solid var(--line-gold-2);
}
.counter .plus:hover { background: rgba(224,164,44,0.26); }

/* ---- Buttons ---- */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 15px;
  letter-spacing: .2px; transition: transform .1s ease, filter .15s ease, box-shadow .15s;
  white-space: nowrap;
}
.btn::after { content:''; position:absolute; left:12px; right:12px; top:0; height:1px; background:linear-gradient(90deg,transparent,rgba(255,255,255,.42),transparent); pointer-events:none; }
.btn:active { transform: translateY(1px) scale(.995); }
.btn--gold { background: var(--grad-gold); color: #3a2a06; box-shadow: 0 10px 24px rgba(224,164,44,.25), inset 0 1px 0 rgba(255,255,255,.4); }
.btn--gold:hover { filter: brightness(1.06) saturate(1.03); box-shadow:0 12px 28px rgba(224,164,44,.32), inset 0 1px 0 rgba(255,255,255,.45); }
.btn--green { background: var(--grad-bamboo); color: #06281c; box-shadow: 0 10px 22px rgba(47,138,99,.3), inset 0 1px 0 rgba(255,255,255,.3); }
.btn--lacquer { background: var(--grad-lacquer); color: #fff6ef; box-shadow: 0 10px 26px rgba(190,58,43,.4), inset 0 1px 0 rgba(255,255,255,.25); }
.btn--ghost { background: rgba(255,255,255,0.05); color: var(--bone); border: 1px solid var(--line-gold); }
.btn--ghost:hover { background: rgba(255,255,255,0.09); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn__sub { font-size: 11px; font-weight: 600; opacity: .8; }
/* Sign-in provider marks (see components/provider_icons.js). .btn is already a
   flex row with a gap, so the mark just sits before the label. flex:0 0 auto
   keeps it from squashing when the label wraps on narrow screens. */
.btn__ico { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; line-height: 0; }
/* White chip for the multi-colour Google G — it is only legible/compliant on a
   neutral field, and our Google button is gold. */
.btn__ico--chip { width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.18); }
.btn .play-tri { width: 0; height: 0; border-left: 12px solid currentColor; border-top: 8px solid transparent; border-bottom: 8px solid transparent; }

/* ---- Cards ---- */
.card {
  position: relative; border-radius: var(--r-lg);
  background: var(--felt-card); border: 1px solid var(--line-gold);
  box-shadow: var(--shadow-card); overflow: hidden;
}
.card::before { content:''; position:absolute; inset:0; background-image: var(--banig); pointer-events:none; }
.card::after { content:''; position:absolute; z-index:1; left:18px; right:18px; top:0; height:1px; background:linear-gradient(90deg,transparent,rgba(247,207,105,.28),transparent); pointer-events:none; }
.card > * { position: relative; }

/* ---- Headings ---- */
.h-display { font-family: var(--font-display); font-weight: 800; color: var(--bone-bright); letter-spacing: -.4px; line-height: 1; }
.eyebrow { font-size: 10.5px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--bone-faint); font-weight: 700; }
.muted { color: var(--bone-dim); }
.nums { font-variant-numeric: tabular-nums; }

/* ---- Progress bar (Antas) ---- */
.progress { height: 9px; border-radius: 999px; background: rgba(0,0,0,0.38); overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--grad-gold-sheen); box-shadow: 0 0 12px rgba(224,164,44,.5); }

/* ---- Segmented control / tabs ---- */
.seg { display: inline-flex; gap: 4px; }
.seg button { padding: 6px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--bone-dim); }
.seg button.is-active { color: var(--gold-hi); background: rgba(224,164,44,0.14); box-shadow: inset 0 -2px 0 var(--marigold); border-radius: 10px 10px 4px 4px; }
.seg button:hover:not(.is-active) { color: var(--bone); }

/* ---- Toast ---- */
.toast-host { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: rgba(12,40,30,0.95); color: var(--bone-bright); border: 1px solid var(--line-gold-2);
  box-shadow: 0 12px 30px rgba(0,0,0,.5); animation: toastIn .25s ease;
}
.toast--gold { border-color: var(--marigold); box-shadow: 0 0 24px rgba(224,164,44,.4); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Portrait rotate gate (landscape-first seated table) ---- */
#rotate-gate { display: none; }
.rotate-gate__parol { position: relative; filter: drop-shadow(0 0 34px rgba(224,164,44,0.45)); }
.rotate-gate__logo { position: relative; width: min(80vw, 460px); height: auto; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,0.4); }
.rotate-gate__msg { position: relative; font-family: var(--font-display); font-weight: 800; font-size: 24px; color: var(--bone-bright); line-height: 1.25; }
.rotate-gate__msg span { display: block; font-family: var(--font-ui); font-weight: 600; font-size: 14px; color: var(--bone-dim); margin-top: 10px; }

/* ---- Branded boot splash (fades out once the first screen renders) ---- */
#boot-splash { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; background: var(--felt-app); transition: opacity .5s ease; }
#boot-splash::before { content: ''; position: absolute; inset: 0; background-image: var(--banig); opacity: .5; pointer-events: none; }
#boot-splash img { position: relative; width: min(64vw, 640px); height: auto; border-radius: 16px; box-shadow: 0 14px 46px rgba(0,0,0,0.45); animation: bootPop .6s cubic-bezier(.2,.8,.2,1) both; }
#boot-splash.hide { opacity: 0; pointer-events: none; }
@keyframes bootPop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #boot-splash img { animation: none; } }

/* ---- iOS "Add to Home Screen" hint (shown only on iOS Safari, not standalone) ---- */
#ios-hint { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 950; display: flex; align-items: center; gap: 10px; max-width: 92vw; padding: 9px 10px 9px 15px; border-radius: 999px; background: rgba(8,26,20,0.94); border: 1px solid var(--line-gold); color: var(--bone); font-family: var(--font-ui); font-size: 13px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,0.45); }
#ios-hint b { color: var(--gold-hi); font-weight: 800; }
#ios-hint button { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.08); color: var(--bone-dim); font-size: 12px; line-height: 1; cursor: pointer; }

@media (orientation: portrait) and (max-width: 900px) {
  #device { display: none; }
  #rotate-gate {
    display: flex; position: fixed; inset: 0; z-index: 500;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 26px; text-align: center; padding: 32px; background: var(--felt-app);
  }
  #rotate-gate::before { content: ''; position: absolute; inset: 0; background-image: var(--banig); pointer-events: none; }
}

/* Landscape phones: fill the screen edge-to-edge rather than letterboxing */
@media (orientation: landscape) and (max-height: 520px) {
  #app { padding: 0; }
  .device { width: 100%; height: 100dvh; max-width: none; border-radius: 0; aspect-ratio: auto; }
  .rail { width:calc(var(--rail-w) + env(safe-area-inset-left)); flex-basis:calc(var(--rail-w) + env(safe-area-inset-left)); padding-left:env(safe-area-inset-left); padding-top:max(8px,env(safe-area-inset-top)); padding-bottom:max(8px,env(safe-area-inset-bottom)); }
  .stage { padding-right:env(safe-area-inset-right); }
}
@media (orientation: landscape) and (max-height: 420px) {
  .topbar { padding: 6px 12px 2px; gap: 8px; }
  .wallet { gap: 6px; }
  .counter { gap: 5px; padding: 4px 6px 4px 7px; }
  .counter b { font-size: 12px; }
  .counter .coin, .counter .gem, .counter .plus { width: 18px; height: 18px; }
  .home__online { font-size: 10.5px; }
  .rail__fs { display:none; }
}
@media (max-width: 640px) {
  #app { padding: 0; }
  .device { border-radius: 0; }
}

.fade-in { animation: fadeIn .28s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
