/* =====================
   Spotify-inspired Theme + Layout & Bubble Grouping
   ===================== */

/* Tokens */
:root{
  --bg:#121212; --bg-raise:#0d0d0d;
  --card:#181818; --card-2:#1e1e1e; --line:#262626;
  --text:#e9edf1; --muted:#a7abb0;
  --accent:#1DB954; --accent-2:#1ed760;
  --danger:#ff5d5d; --ok:#1DB954; --ring:rgba(29,185,84,.35);
  --shadow:0 10px 30px rgba(0,0,0,.4);
  --radius:12px; --radius-lg:16px;
  --usernameColor:#4caf50;
}
@media (prefers-color-scheme: light){
  :root{ --bg:#f7fafc; --bg-raise:#fff; --card:#fff; --card-2:#fff; --line:#e5e7eb;
         --text:#0f1419; --muted:#5b636e; --ring:rgba(29,185,84,.28);
         --shadow:0 10px 24px rgba(15,20,25,.08); }
}

/* Base */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; padding:18px;
  font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,"Apple Color Emoji","Segoe UI Emoji";
  color:var(--text); background:var(--bg);
  display:flex; align-items:center; justify-content:center;
}

/* ===== App frame (cap width so it never spans whole screen) ===== */
#container, .content-container, .timer-container{
  width:min(960px, calc(100% - 32px));
  margin:0 auto;
  background:var(--card); border:1px solid var(--line);
  border-radius:var(--radius-lg); box-shadow:var(--shadow);
  padding:16px;
}

/* ===== Stacked header looks like ONE bubble ===== */
header, #chatHeader{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:12px 16px; border:1px solid var(--line);
  background:linear-gradient(180deg, var(--card-2), var(--card));
}
header{
  border-top-left-radius:var(--radius);
  border-top-right-radius:var(--radius);
  border-bottom-left-radius:0;
  border-bottom-right-radius:0;
  margin-bottom:0;                 /* no gap */
}
#chatHeader{
  border-top:none;                 /* merge with header */
  border-top-left-radius:0;
  border-top-right-radius:0;
  border-bottom-left-radius:var(--radius);
  border-bottom-right-radius:var(--radius);
  margin-top:0;                    /* no gap */
}
header h1, #chatHeader h1, #chatHeader h2{
  margin:0; font-size:clamp(18px,2vw,21px); font-weight:700; letter-spacing:.2px;
}

/* ===== Screen cards (bigger + centered) ===== */
#entryScreen, #makeAccountScreen, #loginScreen, #settingsScreen, #mainScreen{
  max-width: 840px;
  margin:12px auto;
  padding:16px;
  background:var(--card); border:1px solid var(--line);
  border-radius:var(--radius);
  text-align:center;
}
#entryScreen input, #makeAccountScreen input, #loginScreen input, #settingsScreen input{
  max-width:520px; width:100%; margin:8px auto;
}
#entryScreen > button, #makeAccountScreen > button, #loginScreen > button,
#settingsScreen > button, #mainScreen > button{ margin:6px 8px; }

/* ===== Chat layout ===== */
#chatScreen{ display:grid; grid-template-rows:auto 1fr auto; gap:10px; }

/* Vertical stacking only */
#chatWindow{
  height:clamp(360px, 62vh, 680px);
  overflow:auto; padding:12px;
  border:1px solid var(--line); border-radius:var(--radius);
  background:linear-gradient(180deg, #0f0f0f, #121212);
  scroll-behavior:smooth;

  display:flex;
  flex-direction:column;
  align-items:stretch;   /* messages fill width */
  gap:10px;
}

/* ===== One GIANT bubble per user run =====
   Your app.js already groups consecutive messages by username into a single
   .messageBlock. We style the .messageBlock itself as the bubble and make
   each .chatMessage inside it look like stacked lines/paragraphs. */
.messageBlock{
  width:100%;
  background:#1a1a1a;
  border:1px solid #222;
  border-radius:14px;
  padding:10px 12px;
}
.chatUsername{
  color:var(--muted);
  font-weight:800;
  margin-bottom:6px;
  letter-spacing:.25px;
}
.chatMessage{
  display:block;             /* forces each message onto new line inside the bubble */
  width:100%;
  margin:6px 0;
  padding:0;
  background:transparent;    /* no inner bubble */
  border:none;
  line-height:1.35;
  word-wrap:break-word;
  white-space:pre-wrap;
}

/* Timestamps: small + gray (still inline at end) */
#chatWindow .timestamp{
  font-size:12px;
  line-height:1;
  color:rgba(255,255,255,.48);
  white-space:nowrap;
  margin-left:8px;
}

#chatWindow { scroll-behavior: smooth; }

/* Media inside giant bubble */
.chatMessage img, .chatMessage video, .chatMessage audio{
  border-radius:10px; max-width:100%;
}
.chatMessage video, .chatMessage audio{ width:100%; }

/* Controls */
#chatControls{ display:grid; grid-template-columns:1fr auto auto; gap:10px; align-items:center; }
#messageControls{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
#fileControls, #autoScrollControls{ display:flex; gap:10px; align-items:center; justify-content:flex-end; }

/* Inputs */
input[type="text"], input[type="password"], input[type="number"], #roomCode{
  width:100%; padding:12px 14px;
  border-radius:999px; border:1px solid var(--line);
  background:#101010; color:var(--text);
  outline:none; transition:box-shadow .18s ease, border-color .18s ease, background .18s ease;
}
input::placeholder{ color:color-mix(in oklab, var(--text) 35%, transparent); }
input:focus{ border-color:var(--accent); box-shadow:0 0 0 5px var(--ring); background:#0e0e0e; }

/* Buttons */
button, #chooseFileButton{
  -webkit-tap-highlight-color:transparent; appearance:none;
  border:1px solid var(--line);
  background:linear-gradient(180deg, var(--accent), var(--accent-2));
  color:#0b0b0b; padding:11px 16px; border-radius:999px;
  font-weight:800; letter-spacing:.2px; cursor:pointer;
  transition:transform .06s ease, filter .15s ease, box-shadow .2s ease, border-color .15s ease;
  box-shadow:0 6px 18px rgba(29,185,84,.18);
}
button:hover, #chooseFileButton:hover{ filter:brightness(1.05); }
button:active, #chooseFileButton:active{ transform:translateY(1px); }

/* Secondary buttons */
button.secondary{ background:#222; color:var(--text); border-color:var(--line); box-shadow:none; }

/* Toggle */
#autoScrollLabel{
  user-select:none; display:flex; align-items:center; gap:10px;
  padding:8px 10px; border-radius:999px; background:#1a1a1a; border:1px solid var(--line);
}
#autoScrollCheckbox{
  appearance:none; width:40px; height:22px; border-radius:999px; background:#2a2a2a; position:relative; cursor:pointer; transition:background .18s ease;
}
#autoScrollCheckbox::after{
  content:""; position:absolute; top:2px; left:2px; width:18px; height:18px; border-radius:50%; background:#f5f5f5; transition:left .18s ease;
}
#autoScrollCheckbox:checked{ background:var(--accent); }
#autoScrollCheckbox:checked::after{ left:20px; }

/* Info + errors */
#error, .error{ color:#ff6b6b; font-weight:700; }
#info-frame{ margin-top:12px; padding:12px; border-radius:var(--radius); background:#151515; border:1px solid var(--line); }

/* Games & Time pages centering */
.content-container, .timer-container{ margin:0 auto; }
.section{ margin-top:10px; padding:14px; background:var(--card); border:1px solid var(--line); border-radius:var(--radius); }
.button-container{ display:grid; grid-template-columns:repeat(auto-fit, minmax(160px, 1fr)); gap:10px; margin-top:12px; justify-items:center; }
.back-button, #backButton{ margin:0 auto 12px; display:inline-block; }

/* Time page */
#time{ font-size:clamp(32px,8vw,60px); font-weight:800; letter-spacing:1px; text-align:center; padding:6px 0 12px; }
#period{ text-align:center; color:var(--muted); margin-bottom:14px; }
.sublabel{ color:var(--muted); font-size:.95rem; }
#specific-time{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; justify-content:center; }
#specific-time input{ width:140px; }
#specificTimer{ margin-top:8px; text-align:center; }

/* Scrollbar (webkit) */
#chatWindow::-webkit-scrollbar{ width:10px; }
#chatWindow::-webkit-scrollbar-thumb{ background:#2a2a2a; border-radius:10px; border:2px solid transparent; background-clip:padding-box; }
#chatWindow::-webkit-scrollbar-track{ background:transparent; }

/* Responsive */
@media (max-width: 620px){
  #chatControls{ grid-template-columns:1fr; }
  #fileControls, #autoScrollControls{ justify-content:flex-start; }
}
