/* =========================================================================
   Billiards client styles. Dark pool-hall look: near-black green room, brass
   accents, cream ink. The table is one canvas (render.js); the HUD, power
   bar and pop-ups are DOM around it. Layout switches between portrait (table
   rotated, controls along the bottom) and landscape (controls on the right)
   via a class on #game that client.js sets from the window shape.
   ========================================================================= */
:root {
  --bg: #0a1411;
  --bg2: #10231c;
  --card: rgba(16, 32, 26, 0.95);
  --edge: rgba(255, 240, 200, 0.10);
  --ink: #f6efdc;
  --muted: #a9b8a8;
  --brass: #e0b25a;
  --brass-d: #9a7224;
  --felt: #0f7a4a;
  --felt-d: #0b5d3b;
  --red: #e5484d;
  --green: #4ade80;
  --hud: rgba(8, 18, 14, 0.82);
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body { position: fixed; inset: 0; }
#app { position: fixed; inset: 0; height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; }
[hidden] { display: none !important; }

.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--edge);
  font-weight: 650; letter-spacing: .01em;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  user-select: none; -webkit-user-select: none;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.big { min-height: 52px; font-size: 17px; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn.primary {
  background: linear-gradient(180deg, #f0c66d, #c9932f); color: #1d1405; border-color: #f7d999;
  box-shadow: 0 3px 0 #7e5a17, 0 6px 18px rgba(224, 178, 90, .25);
}
.btn.primary:hover { background: linear-gradient(180deg, #f6d283, #d29d38); }
.btn.secondary {
  background: linear-gradient(180deg, #14905a, #0c6a41); border-color: #2fb377;
  box-shadow: 0 3px 0 #06402a;
}
.btn.secondary:hover { background: linear-gradient(180deg, #18a066, #0e774a); }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.linkish { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: 14px; cursor: pointer; }
.linkish:hover { color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------------- menu ---------------- */
#menu {
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(30, 150, 95, .35), transparent 60%),
    radial-gradient(90% 60% at 50% 110%, rgba(224, 178, 90, .10), transparent 60%),
    var(--bg);
}
.menu-scroll {
  position: absolute; inset: 0; overflow-y: auto;
  padding: calc(20px + var(--sat)) calc(16px + var(--sar)) calc(20px + var(--sab)) calc(16px + var(--sal));
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.logo { text-align: center; margin-top: 2vh; }
.logo-balls { width: 190px; height: auto; display: block; margin: 0 auto -4px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.lb { transform-origin: center; animation: bob 3.2s ease-in-out infinite; transform-box: fill-box; }
.lb-b { animation-delay: -1.1s; }
.lb-c { animation-delay: -2.2s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.brand-name { margin: 0; font-weight: 400; letter-spacing: .01em; }
.logo .brand-name { font-size: clamp(34px, 9vw, 52px); line-height: 1.05; }
.brand-name b { font-weight: 850; color: var(--brass); }
.tag { margin: 6px 0 0; color: var(--muted); font-size: 15px; }

.card {
  width: 100%; max-width: 440px;
  background: var(--card); border: 1px solid var(--edge); border-radius: 18px;
  padding: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.45);
  display: flex; flex-direction: column; gap: 14px;
}
.card h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--brass); font-weight: 750; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .join input, .linkbox input {
  width: 100%; min-height: 46px; padding: 8px 14px; border-radius: 12px;
  background: rgba(0,0,0,.35); border: 1px solid var(--edge); color: var(--ink); font-size: 17px; outline: none;
}
.field input:focus, .join input:focus { border-color: var(--brass); }
.group { display: flex; flex-direction: column; gap: 8px; }
.group.two { flex-direction: row; gap: 10px; }
.group.two .btn { flex: 1; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn.level { flex-direction: column; gap: 0; min-height: 60px; padding: 6px; }
.btn.level b { font-size: 16px; }
.btn.level small { font-size: 11.5px; opacity: .75; font-weight: 500; }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: .2em; min-height: 42px; font-size: 16px; }
.join .btn { min-width: 76px; }
.msg { margin: 0; padding: 8px 12px; border-radius: 10px; background: rgba(229, 72, 77, .15); color: #ffb3b5; font-size: 14px; }
.invite { padding: 12px; border-radius: 12px; background: rgba(224, 178, 90, .12); border: 1px solid rgba(224, 178, 90, .35); display: flex; flex-direction: column; gap: 10px; }
.invite p { margin: 0; }
.foot { display: flex; align-items: center; gap: 16px; padding-bottom: 8px; }
.netdot { width: 8px; height: 8px; border-radius: 50%; background: #666; }
.netdot.up { background: var(--green); box-shadow: 0 0 8px var(--green); }

.sheet {
  position: absolute; inset: 0; z-index: 10; background: rgba(3, 8, 6, .72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet .card p { margin: 0; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-size: 14px; min-height: 42px; }
.row-btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }
.code-pill { padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.06); color: var(--muted); font-size: 14px; }
.code-pill b { color: var(--ink); letter-spacing: .15em; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; }
#sfw-copy { margin-top: 12px; }
.check input { accent-color: var(--brass); width: 16px; height: 16px; margin: 0; }
.spinner { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: transparent; animation: spin 0.9s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- game ---------------- */
#game {
  background: radial-gradient(100% 80% at 50% 45%, #15291f 0%, #0a1411 70%);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#game.active { display: grid; }
#game.portrait {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);   /* minmax: a long name must not widen the page */
  grid-template-areas: "hud" "status" "stage" "controls";
}
#game.landscape {
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "hud hud" "status status" "stage controls";
}
.hud {
  grid-area: hud; display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0;
  padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 4px calc(8px + var(--sal));
  position: relative; z-index: 3;
}
.hud-logo { font-size: 20px; white-space: nowrap; position: absolute; left: calc(12px + var(--sal)); top: calc(50% + var(--sat) / 2); transform: translateY(-50%); }
#game.portrait .hud-logo { display: none; }
@media (max-width: 1100px) { .hud-logo { display: none; } }
.pcard {
  flex: 0 1 330px; min-width: 0; display: flex; align-items: center; gap: 8px; position: relative;
  padding: 6px 10px 6px 6px; border-radius: 14px; background: var(--hud); border: 1px solid var(--edge);
  transition: border-color .2s, box-shadow .2s, opacity .2s;
}
.pcard.right { flex-direction: row-reverse; text-align: right; padding: 6px 6px 6px 10px; }
.pcard.turn { border-color: rgba(224, 178, 90, .7); box-shadow: 0 0 0 1px rgba(224,178,90,.35), 0 0 18px rgba(224,178,90,.18); }
.pcard:not(.turn) > :not(.bubble) { opacity: .78; }   /* not the bubble: it must stay solid over the name */
.avatar { position: relative; width: 40px; height: 40px; flex: none; }
.avatar svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: rgba(255,255,255,.05); stroke: rgba(255,255,255,.12); stroke-width: 3; }
.ring { fill: none; stroke: var(--brass); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 106.8; stroke-dashoffset: 106.8; transition: stroke .3s; }
.ring.low { stroke: var(--red); }
.initial { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; }
.pinfo { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.pname { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; display: flex; align-items: baseline; min-width: 0; }
.pname .nm { overflow: hidden; text-overflow: ellipsis; min-width: 0; }   /* the name shrinks, the offline tag stays */
.pcard.right .pname { justify-content: flex-end; }
.pname .off { font-size: 11px; color: var(--red); margin: 0 4px; font-weight: 600; flex: none; }
.pballs { display: flex; gap: 2px; min-height: 13px; flex-wrap: nowrap; overflow: hidden; }
.pcard.right .pballs { justify-content: flex-end; }
.pballs .mb { width: 13px; height: 13px; border-radius: 50%; flex: none; position: relative; box-shadow: inset -2px -2px 3px rgba(0,0,0,.35); }
.pballs .mb.stripe { background: #f3ecd8 !important; overflow: hidden; }
.pballs .mb.stripe::after { content: ''; position: absolute; left: 0; right: 0; top: 4px; bottom: 4px; background: var(--c); }
.pballs .mb.down { opacity: .18; }
.pballs .tag { font-size: 11px; color: var(--muted); margin: 0; }
/* Emote / trash-talk bubble: over the speaker's own card, beside the avatar (covering the
   name and balls for a few seconds). It used to hang below the card, over the status line
   and the mute / leave buttons, and caught taps; now it stays inside the HUD row and lets
   taps through. Two lines at most. */
.bubble {
  position: absolute; top: 4px; bottom: 4px; left: 52px; right: 6px; z-index: 6; pointer-events: none;
  display: flex; align-items: center; overflow: hidden;
  background: #f6efdc; color: #1a1a1a; padding: 2px 10px; border-radius: 12px; font-weight: 700; font-size: 14px; line-height: 1.2;
  box-shadow: 0 4px 14px rgba(0,0,0,.45); animation: bubble-pop .25s ease-out;
}
.bubble > span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.pcard.right .bubble { left: 6px; right: 52px; justify-content: flex-end; text-align: right; }
/* narrow cards on a portrait phone: smaller text, up to three lines (still inside the card) */
#game.portrait .bubble { font-size: 12px; line-height: 1.15; padding: 2px 8px; }
#game.portrait .bubble > span { -webkit-line-clamp: 3; line-clamp: 3; }
@keyframes bubble-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; background: var(--hud); border: 1px solid var(--edge); font-size: 16px; display: flex; align-items: center; justify-content: center; }

/* The status row has a fixed height (two lines of text, or the buttons if taller) and the
   text is clamped to two lines, so a message that wraps, or the text clearing while the
   balls roll, never resizes the table canvas under the player's finger. */
.status {
  grid-area: status; display: flex; align-items: center; gap: 8px;
  height: max(38px, calc(2.4em + 6px)); overflow: hidden;
  padding: 2px calc(8px + var(--sar)) 4px calc(8px + var(--sal)); font-size: 14px; text-align: center;
}
.status .lines {
  flex: 1; min-width: 0; line-height: 1.2; max-height: 2.4em; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.status .icon-btn { width: 32px; height: 32px; border-radius: 10px; font-size: 14px; flex: none; }
#status-line { font-weight: 700; color: var(--ink); }
#status-line:not(:empty) { margin-right: 8px; }
.status .last { color: var(--muted); }
#game.portrait .status { font-size: 13px; }

#stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hint {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 2; pointer-events: none;
  background: rgba(8, 18, 14, .85); border: 1px solid rgba(224,178,90,.5); color: var(--ink);
  padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 650;
  width: max-content; max-width: calc(100% - 24px); text-align: center;  /* wraps instead of running off a phone */
}

.controls { grid-area: controls; display: flex; align-items: center; gap: 12px; z-index: 3; }
#game.portrait .controls { padding: 6px calc(12px + var(--sar)) calc(10px + var(--sab)) calc(12px + var(--sal)); }
#game.landscape .controls { flex-direction: column; justify-content: center; padding: 10px calc(14px + var(--sar)) calc(12px + var(--sab)) 6px; }

.spin-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; }
.spin-btn .face, .bigball {
  position: relative; display: block; border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #fff 0%, #f1ead6 35%, #c9c0a8 85%, #9d957f 100%);
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.spin-btn .face { width: 44px; height: 44px; }
.tip { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; left: 50%; top: 50%; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px rgba(255,255,255,.7); }
.emote-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--hud); border: 1px solid var(--edge); font-size: 24px; line-height: 1; }

.power { position: relative; touch-action: none; cursor: grab; display: flex; align-items: center; justify-content: center; }
.power .track { position: relative; border-radius: 999px; background: rgba(0,0,0,.45); border: 1px solid var(--edge); overflow: hidden; }
.power .fill { position: absolute; border-radius: inherit; background: linear-gradient(90deg, #4ade80, #e0b25a 60%, #e5484d); }
.power .grip { position: absolute; background: #f6efdc; border-radius: 3px; box-shadow: 0 0 6px rgba(0,0,0,.6); }
.power .plabel { position: absolute; pointer-events: none; font-size: 12px; color: var(--muted); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.power.disabled { opacity: .4; cursor: default; }
.power.dragging .plabel, .power.live .plabel { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.9), 0 0 6px rgba(0,0,0,.7); }
/* portrait: horizontal bar, drag right */
#game.portrait .power { flex: 1; height: 54px; }
#game.portrait .power .track { width: 100%; height: 26px; }
#game.portrait .power .fill { left: 0; top: 0; bottom: 0; width: 0; }
#game.portrait .power .grip { top: 3px; bottom: 3px; width: 6px; left: 0; }
#game.portrait .power .plabel { top: 50%; transform: translateY(-50%); }
/* landscape: vertical bar, pull down */
#game.landscape .power { flex: 1; width: 60px; max-height: 420px; min-height: 160px; }
#game.landscape .power .track { width: 28px; height: 100%; }
#game.landscape .power .fill { left: 0; right: 0; top: 0; height: 0; background: linear-gradient(180deg, #4ade80, #e0b25a 60%, #e5484d); }
#game.landscape .power .grip { left: 3px; right: 3px; height: 6px; top: 0; }
#game.landscape .power .plabel { writing-mode: vertical-rl; transform: rotate(180deg); }

.pop {
  position: absolute; z-index: 8; background: var(--card); border: 1px solid var(--edge); border-radius: 18px;
  padding: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.55); display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.pop p { margin: 0; }
.spin-pop { width: 230px; }
#game.portrait .spin-pop { left: calc(12px + var(--sal)); bottom: calc(80px + var(--sab)); }
#game.landscape .spin-pop { right: calc(90px + var(--sar)); bottom: calc(20px + var(--sab)); }
.bigball { width: 150px; height: 150px; touch-action: none; cursor: crosshair; }
.bigball .tip { width: 18px; height: 18px; margin: -9px 0 0 -9px; }
.bigball::before { content: ''; position: absolute; inset: 50% 0 auto 0; height: 1px; background: rgba(0,0,0,.12); }
.bigball::after { content: ''; position: absolute; inset: 0 auto 0 50%; width: 1px; background: rgba(0,0,0,.12); }
.emote-pop { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; width: 260px; }
#game.portrait .emote-pop { right: calc(12px + var(--sar)); bottom: calc(80px + var(--sab)); }
#game.landscape .emote-pop { right: calc(90px + var(--sar)); bottom: calc(20px + var(--sab)); }
.emote-pop .btn { min-height: 38px; font-size: 14px; padding: 4px 8px; }

.overlay { position: absolute; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(3, 8, 6, .55); backdrop-filter: blur(3px); animation: fade .35s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.over-card { text-align: center; align-items: center; max-width: 380px; }
.over-card h2 { font-size: 26px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.over-card p { margin: 0; }
.over-card .row-btns { width: 100%; }
.trophy {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 36% 30%, #555 0%, #161616 55%, #000 100%); color: #111; font-weight: 900; font-size: 20px;
  position: relative; box-shadow: 0 6px 18px rgba(0,0,0,.6);
}
.trophy::before { content: ''; position: absolute; width: 30px; height: 30px; border-radius: 50%; background: #f6efdc; }
.trophy { isolation: isolate; }
.trophy::before { z-index: -1; }
.over-card.win .trophy { box-shadow: 0 0 0 3px var(--brass), 0 0 30px rgba(224,178,90,.6); }

.netstat {
  position: fixed; left: 50%; top: calc(8px + var(--sat)); transform: translateX(-50%); z-index: 20;
  background: #4a1b1d; color: #ffd6d7; border: 1px solid #8a3235; padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 650;
}
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--sab)); transform: translateX(-50%); z-index: 21; max-width: calc(100% - 32px);
  background: rgba(246, 239, 220, .96); color: #1a1a1a; padding: 8px 16px; border-radius: 12px; font-weight: 650; font-size: 15px;
  box-shadow: 0 8px 26px rgba(0,0,0,.45); text-align: center;
}

/* short landscape (phone on its side): squeeze the chrome so the table gets the height */
@media (max-height: 520px) {
  #game.landscape .hud { padding-top: calc(3px + var(--sat)); padding-bottom: 2px; }
  #game.landscape .pcard { padding: 3px 8px 3px 3px; }
  #game.landscape .pcard.right { padding: 3px 3px 3px 8px; }
  #game.landscape .avatar { width: 30px; height: 30px; }
  #game.landscape .bubble { left: 38px; font-size: 13px; }
  #game.landscape .pcard.right .bubble { left: 3px; right: 38px; }
  #game.landscape .pname { font-size: 13px; }
  #game.landscape .status { padding-top: 0; padding-bottom: 2px; font-size: 12px; height: calc(2.4em + 2px); }
  #game.landscape .status .icon-btn { width: 28px; height: 28px; }
  #game.landscape .controls { gap: 6px; padding-top: 4px; padding-bottom: calc(6px + var(--sab)); }
  #game.landscape .power { min-height: 70px; }
  #game.landscape .spin-btn .face { width: 36px; height: 36px; }
  #game.landscape .spin-btn small { display: none; }
  #game.landscape .emote-btn { width: 38px; height: 38px; font-size: 20px; }
}
@media (max-width: 380px) {
  .pname { font-size: 14px; }
  .avatar { width: 34px; height: 34px; }
  .bubble { left: 46px; font-size: 13px; }
  .pcard.right .bubble { left: 6px; right: 46px; }
}
