:root {
  --bg: #0e0b17;
  --ink: #efeaf8;
  --dim: #8d86a3;
  --rule: #2b2440;
  --pink: #ff3d9a;
  --cyan: #35e0ff;
  --emo: #7b5cff;
  --bar: 40px;
  --chat: 250px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: radial-gradient(1200px 700px at 50% 45%, #2a2145 0%, #171226 45%, var(--bg) 100%);
  color: var(--ink);
  font: 14px/1.35 "Helvetica Neue", Helvetica, Arial, sans-serif;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
[hidden] { display: none !important; }

#board { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* top strip: everything you can click lives here */
#bar {
  position: fixed; top: 0; left: 0; right: var(--chat); height: var(--bar);
  display: flex; align-items: center; gap: 24px; padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.bar-left { font-weight: 700; }
.bar-left .you { color: var(--cyan); }
.bar-left .coop { color: var(--pink); }
#record { margin-left: 14px; color: var(--dim); font-weight: 400; font-variant-numeric: tabular-nums; }
.bar-mid { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; }
#status[data-kind="cooper"] { color: var(--pink); }
#status[data-kind="check"] { color: #ff6b6b; font-weight: 700; }
#result b { color: var(--cyan); }
#result[data-kind="loss"] b { color: var(--pink); }
#result-sub { color: var(--dim); }
.bar-right { display: flex; gap: 18px; }
.bar-right button, #btn-rematch { color: var(--dim); }
.bar-right button:hover:not(:disabled), #btn-rematch:hover { color: var(--ink); text-decoration: underline; }
.bar-right button:disabled { opacity: 0.35; cursor: default; }
#btn-new, #btn-rematch { color: var(--pink); font-weight: 700; }
#btn-rematch { margin-left: 8px; }
.bar-right button[aria-pressed="false"] { text-decoration: line-through; }

/* chat: a plain column down the right edge */
#chat {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--chat);
  display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--rule);
}
.chat-head { height: var(--bar); display: flex; align-items: center; padding: 0 12px; color: var(--dim); border-bottom: 1px solid var(--rule); }
#chat-log {
  flex: 1; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
  padding: 10px 12px; font-size: 13px;
}
.msg { overflow-wrap: anywhere; }
.msg b { margin-right: 5px; }

/* cooper */
#stream { position: fixed; left: 14px; bottom: 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; pointer-events: none; }
#bubble {
  position: relative; max-width: 440px; margin-left: 4px; padding: 10px 14px;
  background: #fff; color: #15101f; border-radius: 3px;
  font-size: 17px; font-weight: 700; line-height: 1.25;
  opacity: 0; transition: opacity 0.1s;
}
#bubble.show { opacity: 1; }
#bubble::after { content: ""; position: absolute; left: 40px; bottom: -10px; border: 10px solid transparent; border-top-color: #fff; border-bottom: 0; border-left-width: 0; }
#bubble-text { white-space: pre-wrap; }
#bubble[data-emotion="rage"] { animation: rattle 0.09s linear infinite; }
@keyframes rattle { 0% { translate: -1px 0; } 50% { translate: 1px 1px; } 100% { translate: 0 -1px; } }

#cam-frame[data-emotion="rage"] { --emo: #ff4b4b; }
#cam-frame[data-emotion="laugh"] { --emo: #ffd23d; }
#cam-frame[data-emotion="hype"] { --emo: #ff8a1f; }
#cam-frame[data-emotion="shock"] { --emo: #ffffff; }
#cam-frame[data-emotion="sad"] { --emo: #6c8cff; }
#cam-frame[data-emotion="cope"] { --emo: #8fd3ff; }
#cam-frame[data-emotion="nervous"] { --emo: #c9a2ff; }
#cam-frame[data-emotion="think"] { --emo: var(--cyan); }
#cam-frame[data-emotion="bored"] { --emo: #8d879c; }
#cam-frame[data-emotion="disgust"] { --emo: #8fdc6a; }
#cam-frame[data-emotion="smug"] { --emo: var(--pink); }

#cam-frame { position: relative; width: 300px; height: 270px; overflow: hidden; border: 3px solid var(--emo); background: #0d0a16; transition: border-color 0.15s; }
.cam-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 70% at 10% 0%, rgba(255, 61, 154, 0.55), transparent 60%),
    radial-gradient(120% 70% at 95% 10%, rgba(53, 224, 255, 0.45), transparent 60%),
    linear-gradient(180deg, #1a1330, #0c0916);
  animation: rgb 9s linear infinite;
}
@keyframes rgb { to { filter: hue-rotate(360deg); } }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#emotes { position: absolute; inset: 0; overflow: hidden; }
.emote { position: absolute; font-size: 30px; animation: floatUp 1.4s ease-out forwards; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(0, 12px) scale(0.3); }
  18% { opacity: 1; transform: translate(0, 0) scale(1.25) rotate(var(--tilt)); }
  100% { opacity: 0; transform: translate(var(--drift), -70px) scale(0.9) rotate(var(--tilt)); }
}
.tag { position: absolute; padding: 2px 6px; font-size: 11px; font-weight: 700; background: rgba(0, 0, 0, 0.7); }
.tag.live { top: 0; left: 0; background: #e3152b; }
.tag.viewers { top: 0; right: 0; font-weight: 400; font-variant-numeric: tabular-nums; }
.tag.name { left: 0; bottom: 0; font-size: 13px; background: var(--emo); color: #100c1a; transition: background 0.15s; }
.tag.name span { font-weight: 400; font-size: 11px; opacity: 0.75; }

#offline { position: absolute; inset: 0; display: none; place-items: center; text-align: center; background: #0a0810; }
#offline b { display: block; font-size: 18px; letter-spacing: 0.1em; }
#offline span { color: var(--dim); font-size: 12px; }
#cam-frame.offline #offline { display: grid; }
#cam-frame.offline { --emo: #55506a; }

/* promotion */
#promo { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(8, 6, 14, 0.6); }
.promo-box { display: flex; border: 3px solid var(--pink); background: var(--bg); }
.promo-box button { width: 72px; height: 72px; font-size: 44px; line-height: 1; color: #efe3c8; }
.promo-box button:hover { background: var(--pink); color: #100c1a; }

/* start */
#start { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(14, 11, 23, 0.93); transition: opacity 0.25s; }
#start.gone { opacity: 0; pointer-events: none; }
.start-in { width: min(520px, calc(100vw - 48px)); }
.start-in h1 { margin: 0 0 14px; font: 400 76px/0.92 Impact, "Arial Narrow Bold", "Helvetica Neue", sans-serif; text-transform: uppercase; color: var(--pink); }
.start-in p { margin: 0 0 22px; font-size: 16px; color: var(--ink); max-width: 400px; }
#btn-start { padding: 11px 22px; background: var(--cyan); color: #0e0b17; font-size: 16px; font-weight: 700; }
#btn-start:hover:not(:disabled) { background: #fff; }
#btn-start:disabled { background: var(--rule); color: var(--dim); cursor: default; }
.start-in label { margin-left: 16px; color: var(--dim); cursor: pointer; }
.start-in input { accent-color: var(--pink); }
#file-note { margin-top: 20px !important; color: #ff9c9c !important; font-size: 13px !important; }

@media (max-width: 900px) {
  #chat { display: none; }
  .bar-mid { display: none; }
  #bar { right: 0; gap: 12px; justify-content: space-between; }
  .bar-right { gap: 12px; }
  #record { display: none; }
}
@media (max-width: 820px), (max-height: 600px) {
  #cam-frame { width: 200px; height: 180px; }
  #bubble { font-size: 14px; max-width: 280px; }
  .start-in h1 { font-size: 52px; }
}
@media (prefers-reduced-motion: reduce) { .cam-bg, #bubble[data-emotion="rage"] { animation: none; } }
