/* 2 Views PWA - x.com-style chrome, pixel game core */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #000000;
  --surface: #16181c;
  --surface2: #0a0d10;
  --border: #2f3336;
  --text: #e7e9ea;
  --muted: #71767b;
  --accent: #1d9bf0;
  --accent-dim: #05263b;
  --like: #f91880;
  --good: #00ba7c;
  --warn: #f4212e;
  --gold: #ffd400;
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  padding-top: env(safe-area-inset-top);
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--accent); color: #000; padding: 8px; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- sidebar (X-style) ---------- */
#sidebar {
  width: 240px; flex: 0 0 auto;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  position: sticky; top: 0; height: 100vh;
}
.xlogo { padding: 8px; color: var(--text); }
.xlogo svg { fill: currentColor; }
.navbtn {
  display: flex; align-items: center; gap: 16px;
  background: none; border: none; color: var(--text);
  font-size: 19px; padding: 12px 16px; border-radius: 9999px;
  text-align: left; width: 100%;
}
.navbtn svg { width: 24px; height: 24px; flex: 0 0 auto; }
.navbtn:hover, .navbtn:focus-visible { background: rgba(231, 233, 234, 0.1); }
.navbtn.active { font-weight: 800; }
.navbtn.active span { text-decoration: underline; text-underline-offset: 6px; }
#postBtn {
  margin-top: 12px; background: var(--accent); color: #fff; border: none;
  border-radius: 9999px; padding: 14px 0; font-size: 17px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
#postBtn:hover { filter: brightness(1.1); }
#postBtn svg { width: 18px; height: 18px; }
#installBtn {
  margin-top: 8px; background: none; border: 2px solid var(--border); color: var(--text);
  border-radius: 9999px; padding: 10px 0; font-weight: 700; font-size: 13px; letter-spacing: 1px;
}
#installBtn:hover { border-color: var(--muted); }
.sidefoot { margin-top: auto; color: var(--muted); font-size: 12px; padding: 8px 16px; }

/* ---------- shell ---------- */
#shell { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
#topbar {
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; }
#toptabs { display: none; gap: 4px; flex: 1; }
#toptabs .navbtn { font-size: 14px; padding: 8px 14px; width: auto; }
#authbox { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border);
  background: var(--accent); color: #000; font-weight: 900; display: flex; align-items: center; justify-content: center;
}
.handle { font-size: 13px; font-weight: 700; }

#main { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------- pills & buttons ---------- */
.pill {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 9999px; padding: 10px 18px; font-weight: 700; font-size: 14px;
}
.pill:hover:not(:disabled) { background: #1d1f23; }
.pill.small { padding: 6px 12px; font-size: 12px; }
.pill.ghost { opacity: 0.5; }
.pill.danger { color: var(--warn); border-color: var(--warn); }
.pill.equipped { color: var(--good); border-color: var(--good); cursor: default; }
.pilltab { display: inline-flex; }
#lbTabs { display: inline-flex; gap: 8px; }
#lbTabs .tab.active { background: var(--accent); color: #000; border-color: var(--accent); }
.pxbtn {
  background: var(--accent); color: #000; border: none; border-radius: 9999px;
  padding: 13px 26px; font-weight: 800; font-size: 15px;
}
.pxbtn:hover { filter: brightness(1.1); }
.pxbtn:active { transform: scale(0.97); }
.pxbtn.primary { background: var(--accent); color: #fff; }
.rowflex { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- screens ---------- */
.screen { max-width: 620px; margin: 0 auto; padding: 16px 16px 96px; }
.screenhead { font-size: 20px; font-weight: 800; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sectionhead { font-size: 15px; margin: 18px 0 8px; color: var(--muted); }
.card { border: 1px solid var(--border); border-radius: 16px; padding: 16px; margin: 12px 0; background: var(--surface2); }
.fineprint { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 10px 0; }

/* ---------- HUD ---------- */
#screen-game { display: flex; flex-direction: column; align-items: center; padding-bottom: 96px; }
#hud { width: 100%; max-width: 560px; padding: 8px 12px; }
.vrow { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
#hudViews {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Courier New", monospace;
  font-size: clamp(38px, 9vmin, 58px); font-weight: 900; line-height: 0.9;
  letter-spacing: 1px; text-shadow: 4px 4px 0 var(--accent-dim); font-variant-numeric: tabular-nums;
}
.vsub { color: var(--muted); font-size: 10px; letter-spacing: 2px; margin-top: 4px; font-weight: 700; }
.rstats { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
#hudTimer { font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
#hudTimer.low { color: var(--warn); animation: blink 0.5s steps(1) infinite; }
#hudLikes { color: var(--muted); font-size: 12px; font-weight: 700; }
#hudCombo { color: var(--gold); font-size: 13px; font-weight: 900; visibility: hidden; }
#hudCombo.pop { animation: pop 0.18s steps(2); }
#bar { margin-top: 6px; height: 12px; border: 2px solid var(--accent-dim); background: var(--surface2); border-radius: 4px; overflow: hidden; }
#hudFill { height: 100%; width: 0%; background: var(--accent); }

/* ---------- stage & overlays ---------- */
#stage { position: relative; border: 3px solid var(--border); border-radius: 16px; overflow: hidden; background: #000; touch-action: none; }
#stage.hurt { border-color: var(--warn); }
#cv { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
#stage::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 20;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 3px);
}
#warn {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 6;
  background: var(--warn); color: #000; font-weight: 900; font-size: 12px; letter-spacing: 1px;
  padding: 7px 6px; text-align: center; animation: blink 0.45s steps(1) infinite; pointer-events: none;
  font-family: ui-monospace, monospace;
}
#pband {
  position: absolute; top: 46px; left: 8px; right: 8px; z-index: 6;
  background: var(--gold); color: #000; font-weight: 900; font-size: 12px; letter-spacing: 1px;
  padding: 7px 6px; text-align: center; animation: blink 0.3s steps(1) infinite; pointer-events: none;
  font-family: ui-monospace, monospace;
}
.ov {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 16px; background: rgba(0, 0, 0, 0.92); overflow-y: auto;
}
.title {
  font-family: ui-monospace, monospace;
  font-size: 44px; font-weight: 900; letter-spacing: 4px; text-shadow: 5px 5px 0 var(--accent-dim);
}
.tag { color: var(--muted); font-size: 13px; line-height: 1.7; }
.big {
  font-family: ui-monospace, monospace;
  font-size: 38px; font-weight: 900; letter-spacing: 3px; text-shadow: 4px 4px 0 var(--accent-dim);
}
.line { color: var(--muted); font-size: 13px; max-width: 280px; line-height: 1.6; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; font-size: 11px; color: var(--muted); font-weight: 700; }
.bestline { color: var(--gold); font-weight: 900; letter-spacing: 2px; font-size: 13px; animation: blink 0.6s steps(1) infinite; }
.bestline.win { color: var(--good); }
.bankline { color: var(--muted); font-size: 12px; font-weight: 700; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.credit { color: var(--muted); font-size: 10px; letter-spacing: 0.5px; }
.howto { width: 100%; max-width: 320px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface2); }
.howto summary {
  cursor: pointer; padding: 9px 12px; font-size: 12px; font-weight: 800;
  letter-spacing: 1px; color: var(--muted); list-style: none;
}
.howto summary::-webkit-details-marker { display: none; }
.howto summary::before { content: '+ '; color: var(--accent); }
.howto[open] summary::before { content: '\2212 '; }
.howto[open] summary { border-bottom: 1px solid var(--border); }
.howto .legend { padding: 10px; }
.ctl { color: var(--muted); font-size: 10px; line-height: 1.9; }
.best { color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: 1px; }
#btnPauseHud { margin-top: 10px; }

.modecard {
  background: var(--surface2); color: var(--text); border: 2px solid var(--border); border-radius: 14px;
  padding: 10px 18px; display: flex; flex-direction: column; gap: 2px; min-width: 150px;
}
.modecard strong { font-size: 15px; letter-spacing: 1px; }
.modecard span { font-size: 11px; color: var(--muted); }
.modecard em { font-size: 10px; color: var(--gold); font-style: normal; font-weight: 700; }
.modecard.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
#modeCards { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#challengeCard {
  border: 2px solid var(--gold); border-radius: 14px; padding: 12px 16px; max-width: 300px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
#chText { font-size: 12px; line-height: 1.6; }

.legend { display: flex; flex-direction: column; gap: 7px; align-items: center; font-size: 11px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chip {
  display: inline-block; padding: 3px 8px; border: 2px solid; font-weight: 700; font-size: 10px;
  background: var(--surface2); border-radius: 4px;
  font-family: ui-monospace, monospace;
}
.lrow { color: var(--muted); }
.lrow.bad { color: var(--warn); font-weight: 900; }

#touch { position: absolute; bottom: 10px; left: 0; right: 0; z-index: 8; display: flex; justify-content: space-between; padding: 0 12px; pointer-events: none; }
.tbtn {
  pointer-events: auto; width: 66px; height: 58px; font-size: 24px;
  background: rgba(22, 24, 28, 0.85); border: 3px solid var(--border); color: var(--text); border-radius: 12px;
}
.tbtn:active { background: #1d3038; }
.tbtn:focus { outline: none; }
@media (hover: hover) and (pointer: fine) { #touch { display: none; } }

/* ---------- leaderboard ---------- */
.lbtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.lbtable th { text-align: left; color: var(--muted); font-size: 11px; padding: 6px 8px; border-bottom: 1px solid var(--border); letter-spacing: 1px; }
.lbtable td { padding: 8px; border-bottom: 1px solid #1d1f23; }
.lbtable .lbviews { font-weight: 900; color: var(--text); font-variant-numeric: tabular-nums; }
.lbtable .lbname { font-weight: 700; }
.badge {
  display: inline-block; border: 1px solid var(--border); color: var(--muted);
  font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 3px 8px; border-radius: 4px;
}
.badge.x { color: var(--accent); border-color: var(--accent); }
.loading { color: var(--muted); padding: 20px; text-align: center; }

/* ---------- shop ---------- */
.bankline { font-weight: 800; color: var(--gold); font-size: 14px; letter-spacing: 0.5px; }
#shopGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 8px; }
.shophead { grid-column: 1 / -1; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: 2px; margin-top: 10px; }
.shopcard {
  border: 1px solid var(--border); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px; align-items: center; background: var(--surface2);
}
.swatch { width: 56px; height: 56px; border-radius: 12px; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; text-align: center; }
.swatch.av-egg { border-radius: 50% 50% 45% 45%; }
.swatch.av-smiley { border-radius: 50%; }
.swatch.av-skull { clip-path: polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%); }
.swatch.av-bot { clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%); }
.swatch-text { font-size: 9px; padding: 6px; color: var(--text); }
.shopname { font-size: 13px; font-weight: 700; }

/* ---------- profile ---------- */
.profidentity { display: flex; gap: 14px; align-items: center; }
.bigavatar {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 26px; color: #000; flex: 0 0 auto;
}
.avatar img, .bigavatar-img { border-radius: 50%; object-fit: cover; display: block; }
.avatar img { width: 30px; height: 30px; }
.bigavatar-img { width: 64px; height: 64px; }
.profname { font-weight: 800; font-size: 17px; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.statcard { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: var(--surface2); }
.statv { font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; }
.statk { color: var(--muted); font-size: 10px; letter-spacing: 1px; margin-top: 4px; font-weight: 700; }

/* ---------- right rail ---------- */
#rail { width: 350px; flex: 0 0 auto; border-left: 1px solid var(--border); padding: 16px; display: none; flex-direction: column; gap: 16px; height: 100vh; overflow-y: auto; }
.railtext { font-size: 13px; line-height: 1.6; margin: 8px 0; }
#rail h3 { font-size: 18px; font-weight: 800; }

/* ---------- ad placeholders ---------- */
.adcard {
  border: 2px dashed var(--border); border-radius: 12px; min-height: 120px;
  display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center;
  padding: 12px; text-align: center;
}
.adtag {
  font-size: 9px; font-weight: 900; letter-spacing: 2px; color: var(--muted);
  border: 1px solid var(--border); padding: 2px 8px; border-radius: 4px;
}
.adlabel { font-weight: 800; font-size: 13px; }
.adnote { color: var(--muted); font-size: 10px; max-width: 220px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 9999px; font-size: 13px; font-weight: 700; z-index: 100;
  max-width: 90vw; text-align: center; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

/* ---------- mobile bottom tabs ---------- */
#bottombar {
  display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.9); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
#bottombar .navbtn { flex: 1; flex-direction: column; gap: 2px; font-size: 10px; padding: 8px 0; border-radius: 0; align-items: center; text-align: center; }
#bottombar .navbtn span { font-weight: 700; }

/* ---------- breakpoints ---------- */
@media (min-width: 1000px) {
  #bottombar { display: none; }
  #toptabs { display: flex; }
  .brand strong { display: none; }
  #sidebar .navbtn span { display: inline; }
}
@media (max-width: 999px) {
  #sidebar { display: none; }
  #screen-game, .screen { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@media (min-width: 1150px) {
  #rail { display: flex; }
}

/* ---------- x sign-in setup panel ---------- */
.setuplabel { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 1px; margin-bottom: 6px; }
#xClientIdInput {
  width: 100%; background: var(--surface2); border: 2px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, monospace; font-size: 13px;
}
#xClientIdInput:focus { outline: none; border-color: var(--accent); }
.setuprow { display: flex; align-items: center; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.cburl {
  font-family: ui-monospace, monospace; font-size: 11px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; word-break: break-all;
}

/* ---------- animation ---------- */
@keyframes blink { 50% { opacity: 0.25; } }
@keyframes pop { 50% { transform: scale(1.35); } }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  #stage::after { display: none; }
}
