:root {
  --bg: #12121f;
  --panel: #1c1c2e;
  --accent: #7cfc9b;
  --accent2: #4dd2ff;
  --text: #eef0ff;
  --muted: #9a9ab5;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

#app {
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

input, textarea, select {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

/* ===== Screens ===== */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  height: 100%;
  padding: 24px;
  text-align: center;
}
.screen.active { display: flex; }

.title { font-size: 2.4rem; margin: 0; letter-spacing: -1px; }
.title span { color: var(--accent); }
.menu-version { color: var(--muted); font-size: 0.78rem; margin: -12px 0 0; }
.tagline { color: var(--muted); margin: 0 0 12px; }

/* ===== Buttons ===== */
.btn {
  font-size: 1.1rem;
  padding: 14px 26px;
  border: none;
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #06210f; }
.btn-danger { background: #ff5d5d; color: #fff; }
.btn-big { font-size: 1.4rem; padding: 18px 48px; border-radius: 18px; }

/* ===== Menu ===== */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  color: var(--muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #2c2c44;
}

.join-row { display: flex; gap: 10px; }
.code-input {
  width: 130px;
  font-size: 1.6rem;
  text-align: center;
  letter-spacing: 6px;
  text-transform: uppercase;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid #2c2c44;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}
.status { color: var(--accent2); min-height: 1.2em; margin: 4px 0 0; }

/* ===== Lobby ===== */
.code-big {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 10px;
  color: var(--accent);
}
.qr {
  background: #fff;
  padding: 12px;
  border-radius: 14px;
  line-height: 0;
}
.join-url-label { color: var(--muted); font-size: 0.85rem; margin: 0; }
.join-url-label span { color: var(--accent2); }

.player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  padding: 8px 14px;
  border-radius: 20px;
}
.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

/* ===== Play screen ===== */
#screen-play { padding: 0; justify-content: flex-start; position: relative; gap:0; }
#game-select > option {color:black;}
#stage {
    width: 100%;
    flex: 1;
    min-height: 0;
    touch-action: none;
    background: radial-gradient(circle at 50% 40%, #1e1e34, #0d0d18);
}

/* Play menu bar */
.play-menu-bar {
  width: 100%;
  min-height: 58px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(18, 18, 31, 0.96);
  border-bottom: 1px solid #2c2c44;
  flex-shrink: 0;
}

.play-menu-bar::before {
  content: "";
  flex: 1 1 auto;
  order: 8;
}

.menu-icon-btn {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  border: none;
  background: var(--panel);
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.menu-icon-btn:active { transform: scale(0.92); }

.menu-settings-btn {
  order: 9;
  margin-left: auto;
}

.menu-icon-btn.active {
  background: var(--accent);
  color: #06210f;
}

.menu-icon-btn.recording {
  background: rgba(255, 93, 93, 0.88);
  animation: ptt-pulse 1s ease-in-out infinite;
}

.game-picker {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 0 0 auto;
}

.game-picker select {
  max-width: 112px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  text-transform: none;
  letter-spacing: 0;
  outline: none;
}

.draw-dock {
  position: absolute;
  left: 16px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
}

.draw-main-btn {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 50%;
  border: none;
  background: rgba(28, 28, 46, 0.9);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.draw-main-btn.active {
  background: var(--accent);
  color: #06210f;
}

.draw-main-btn:active { transform: scale(0.92); }

.draw-toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 24px;
  background: rgba(28, 28, 46, 0.9);
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  max-width: calc(100vw - 80px);
}

.draw-tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
}

.draw-size-control {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.draw-size-control input {
  width: 72px;
  accent-color: var(--accent);
}

.draw-tool-btn.active {
  background: var(--accent);
  color: #06210f;
}

.draw-clear-btn {
  background: rgba(255, 93, 93, 0.18);
}

.draw-color-input {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.video-tray {
  position: fixed;
  z-index: 19;
  top: calc(66px + env(safe-area-inset-top));
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(42vw, 180px);
  pointer-events: none;
}

.video-tile {
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(124, 252, 155, 0.8);
  border-radius: 14px;
  background: #05050a;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.video-tile video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.video-label {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.live-pill {
  padding: 2px 5px;
  border-radius: 999px;
  background: #ff5d5d;
  color: #fff;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
}

.badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ff5d5d;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  pointer-events: none;
}
.hidden { display: none !important; }

/* ===== Profile sheet (slides in from right) ===== */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}
.sheet.open {
  transform: translateX(0);
  pointer-events: auto;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-header h2 { margin: 0; font-size: 1.2rem; }

.app-update-group {
  padding: 14px;
  border: 1px solid #2c2c44;
  border-radius: 16px;
  background: rgba(28, 28, 46, 0.55);
}

.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-small {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.profile-preview-main {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}
.preview-dot {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  flex-shrink: 0;
}
.preview-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.field-group label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.text-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #2c2c44;
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
}
.text-input:focus { outline: none; border-color: var(--accent); }

.swatch-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.swatch-opt {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.swatch-opt:active { transform: scale(0.9); }
.swatch-opt.selected { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.icon-opt {
  font-size: 1.55rem;
  height: 50px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--panel);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, transform 0.08s;
}
.icon-opt:active { transform: scale(0.9); }
.icon-opt.selected { border-color: var(--accent); }

/* ===== Chat panel (slides up from bottom) ===== */
.chat-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 56vh;
  background: var(--bg);
  border-top: 1px solid #2c2c44;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}
.chat-panel.open {
  transform: translateY(0);
  pointer-events: auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #2c2c44;
  flex-shrink: 0;
  font-weight: 600;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Individual messages */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-msg.mine { flex-direction: row-reverse; }
.chat-msg.sys {
  justify-content: center;
  font-size: 0.76rem;
  color: var(--muted);
  font-style: italic;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.msg-body { max-width: 74%; }
.msg-name {
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 3px;
  padding: 0 4px;
  opacity: 0.85;
}
.chat-msg.mine .msg-name { text-align: right; }
.msg-bubble {
  background: var(--panel);
  padding: 8px 12px;
  border-radius: 4px 14px 14px 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.mine .msg-bubble {
  border-radius: 14px 4px 14px 14px;
  background: var(--accent);
  color: #06210f;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid #2c2c44;
  flex-shrink: 0;
}

.ptt-row {
  padding: 0 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.ptt-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: 24px;
  border: 2px solid #2c2c44;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: border-color 0.15s, background 0.15s;
}
.ptt-btn.recording {
  border-color: #ff5d5d;
  background: rgba(255, 93, 93, 0.12);
  animation: ptt-pulse 1s ease-in-out infinite;
}
@keyframes ptt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 93, 0.35); }
  50%       { box-shadow: 0 0 0 10px rgba(255, 93, 93, 0); }
}

/* Voice message bubble */
.voice-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 130px;
}
.voice-icon { font-size: 1rem; }
.voice-dur {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  flex: 1;
}
.play-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s;
}
.play-btn:active { background: rgba(255, 255, 255, 0.32); }
.play-btn.expired { opacity: 0.38; cursor: default; }
.chat-text-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: none;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
}
.chat-text-input:focus { outline: none; }
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.2rem;
  flex-shrink: 0;
}
