:root {
  --bg: #0c1b26;
  --bg-deep: #081118;
  --panel: #152736;
  --panel-glass: rgba(21, 39, 54, 0.72);
  --edge: #24425a;
  --accent: #7cfc9b;
  --accent2: #4dd2ff;
  --blossom: #f4a6cf;
  --text: #eaf6ff;
  --muted: #8fb0c4;
  --font-display: Georgia, "Times New Roman", serif;
}

.leave-top-btn {
  order: -2;
  background: rgba(255, 93, 93, 0.14);
  color: #ffd6d6;
  font-size: 1.25rem;
  font-weight: 900;
}

* { 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;
}

body {
  background:
    radial-gradient(1200px 720px at 78% -10%, rgba(77, 210, 255, 0.10), transparent 60%),
    radial-gradient(900px 600px at 12% 108%, rgba(124, 252, 155, 0.07), transparent 55%),
    linear-gradient(180deg, #0e2130 0%, var(--bg) 46%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

#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;
}

/* ===== Rain overlay (home screen ambience) ===== */
.rain-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.rain-layer i {
  position: absolute;
  top: -18vh;
  width: 1px;
  height: 11vh;
  background: linear-gradient(180deg, transparent, rgba(196, 233, 255, 0.38));
  animation: rain-fall linear infinite;
}
@keyframes rain-fall {
  to { transform: translate3d(-3vw, 130vh, 0); }
}
.mist-layer {
  position: fixed;
  left: -30%;
  right: -30%;
  bottom: -6%;
  height: 42vh;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(48% 68% at 30% 82%, rgba(170, 216, 238, 0.075), transparent 70%),
    radial-gradient(42% 60% at 72% 90%, rgba(140, 232, 188, 0.055), transparent 70%);
  animation: mist-drift 26s ease-in-out infinite alternate;
}
@keyframes mist-drift {
  from { transform: translateX(-3%); }
  to   { transform: translateX(3%); }
}

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

#screen-loading {
  justify-content: flex-start;
  overflow-y: auto;
}
#screen-loading > *:not(.rain-layer):not(.mist-layer):not(.home-profile-btn) { position: relative; z-index: 1; }
#screen-loading > .home-profile-btn { z-index: 2; }

.title {
  font-family: var(--font-display);
  font-size: 2.9rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.5px;
  background: linear-gradient(105deg, #d3fff4 8%, #b6ddff 42%, #e6c8ff 72%, #d3fff4 96%);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 34px rgba(140, 214, 255, 0.28);
  animation: title-shimmer 9s ease-in-out infinite;
}
.title span {
  background: linear-gradient(120deg, var(--accent) 20%, #b7ffde 55%, var(--accent) 85%);
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}
@keyframes title-shimmer {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}
.title-lotus {
  width: 62px;
  height: 62px;
  margin-top: max(10px, env(safe-area-inset-top));
  filter: drop-shadow(0 6px 18px rgba(244, 166, 207, 0.35));
  animation: lotus-bob 5.4s ease-in-out infinite;
}
@keyframes lotus-bob {
  0%, 100% { transform: translateY(0) rotate(-1.6deg); }
  50% { transform: translateY(-7px) rotate(1.6deg); }
}
.menu-version { color: var(--muted); font-size: 0.78rem; margin: 0; }
.tagline {
  color: var(--muted);
  margin: 0 0 12px;
  font-style: italic;
  letter-spacing: 0.02em;
}

.mode-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 0 auto 6px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--panel-glass);
  backdrop-filter: blur(10px);
}

.mode-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 1.02rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
}
.mode-toggle-btn:active { transform: scale(0.96); }
.mode-toggle-btn:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.mode-toggle-btn.active {
  background: linear-gradient(180deg, rgba(38, 66, 88, 0.95), rgba(21, 39, 54, 0.98));
  border-color: rgba(124, 252, 155, 0.45);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(77, 210, 255, 0.16);
}
.mode-toggle-emoji { font-size: 1.15rem; line-height: 1; }

.chess-glyph {
  font-size: 2.1rem;
  line-height: 1;
  color: #10202b;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}


/* ===== Buttons ===== */
.btn {
  font-size: 1.1rem;
  padding: 14px 26px;
  border: 1px solid var(--edge);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(38, 66, 88, 0.85), rgba(21, 39, 54, 0.92));
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
}
.btn:hover { border-color: rgba(124, 252, 155, 0.4); box-shadow: 0 4px 18px rgba(77, 210, 255, 0.14); }
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(180deg, #96ffb2, var(--accent) 55%, #55d67c);
  border-color: rgba(124, 252, 155, 0.6);
  color: #06210f;
  box-shadow: 0 6px 22px rgba(124, 252, 155, 0.28);
}
.btn-primary:hover { box-shadow: 0 8px 28px rgba(124, 252, 155, 0.4); }
.btn-danger { background: #ff5d5d; color: #fff; }
.btn-big { font-size: 1.4rem; padding: 18px 48px; border-radius: 18px; }
.btn-small { font-size: 0.82rem; padding: 8px 12px; border-radius: 10px; }


/* ===== 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: var(--edge);
}

.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 var(--edge);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}
.status { color: var(--accent2); min-height: 1.2em; margin: 4px 0 0; transition: opacity 0.3s ease; }

@media (prefers-reduced-motion: reduce) {
  .title, .title-lotus, .mist-layer, .rain-layer i { animation: none !important; }
  .flower-lobby-card, .flower-art, .btn { transition: none; }
}

.home-lobby-controls {
  width: min(100%, 720px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  padding: 0 2px 10px;
}

.home-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--edge);
  border-radius: 20px;
  background: var(--panel-glass);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 34px rgba(4, 12, 20, 0.35);
}

.home-section h2 {
  margin: 0;
  font-size: 0.86rem;
  text-align: left;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.home-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.flower-lobby-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.flower-lobby-card {
  min-height: 116px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--flower), transparent 45%);
  border-radius: 18px;
  background:
    radial-gradient(circle at 18% 18%, color-mix(in srgb, var(--flower), transparent 55%), transparent 42%),
    linear-gradient(135deg, rgba(21, 39, 54, 0.96), rgba(12, 20, 32, 0.92));
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: transform 0.16s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.flower-lobby-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--flower), transparent 12%);
  box-shadow: 0 12px 30px color-mix(in srgb, var(--flower), transparent 78%);
}
.flower-lobby-card:hover .flower-art { transform: rotate(6deg) scale(1.06); }
.flower-lobby-card:active { transform: scale(0.98); }

.flower-art {
  width: 58px;
  height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--flower), transparent 18%);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--flower), transparent 82%);
  font-size: 2rem;
  transition: transform 0.22s ease;
}

.flower-svg {
  width: 48px;
  height: 48px;
  display: block;
}

.flower-svg .flower-stem {
  fill: none;
  stroke: #28794d;
  stroke-width: 3;
  stroke-linecap: round;
}

.flower-svg .flower-center { fill: #ffe28f; }
.lotus-svg .lotus-leaf { fill: #2fa86c; opacity: 0.9; }
.lotus-svg .lotus-petal { fill: #f6a7d2; stroke: #ffe2f1; stroke-width: 1.2; }
.lotus-svg .lotus-front { fill: #ffd1e8; }
.iris-svg .iris-standard { fill: #7d5cff; stroke: #e2d6ff; stroke-width: 1.2; }
.iris-svg .iris-fall { fill: #b18cff; stroke: #f3e7ff; stroke-width: 1.2; }
.lily-svg .lily-petal { fill: #fff6c8; stroke: #f0c96a; stroke-width: 1.2; }
.clover-svg .clover-leaf { fill: #32c878; stroke: #c5ffd9; stroke-width: 1.2; }
.anemone-svg .anemone-petal { fill: #8ed8ff; stroke: #e5f7ff; stroke-width: 1; opacity: 0.96; }
.anemone-svg .anemone-center { fill: #263a76; }
.poppy-svg .poppy-petal { fill: #ff7f5f; stroke: #ffd1c2; stroke-width: 1.2; }
.poppy-svg .poppy-center { fill: #5d3328; }
.aster-svg .aster-petal { fill: #d9a6ff; stroke: #f5e2ff; stroke-width: 0.9; }
.orchid-svg .orchid-petal { fill: #cf8cff; stroke: #f7dbff; stroke-width: 1.2; }
.orchid-svg .orchid-lip { fill: #fff4c2; stroke: #d477c9; stroke-width: 1.2; }

.flower-lobby-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flower-lobby-name {
  font-size: 1.05rem;
  font-weight: 900;
}

.flower-lobby-status {
  color: var(--accent2);
  font-size: 0.86rem;
  font-weight: 800;
}

.flower-lobby-meta {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.25;
}

.home-secondary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.home-join-code {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.home-join-code input { text-transform: uppercase; }

.home-profile-btn {
  position: fixed;
  right: 16px;
  top: max(16px, env(safe-area-inset-top));
}

/* ===== 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 {
  position: relative;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #10202b;
  font-size: 0.72rem;
  font-weight: 900;
}

.host-crown {
  position: absolute;
  left: 50%;
  top: -9px;
  transform: translateX(-50%) rotate(-4deg);
  color: #ffd86b;
  font-size: 0.78rem;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* ===== Play screen ===== */
#screen-play {
  padding: 0;
  justify-content: flex-start;
  position: relative;
  gap: 0;
  height: 100%;
  overflow: hidden;
}
#game-select > option {color:black;}
#stage {
    display: block;
    width: 100%;
    flex: 1;
    min-height: 0;
    touch-action: none;
    background: linear-gradient(180deg, #10283a, #173d4d 45%, #0d202d);
}

/* 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(9, 22, 33, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--edge);
  flex-shrink: 0;
}

.play-menu-bar .player-list {
  flex: 1 1 auto;
  justify-content: flex-end;
}

/* ===== Voice + chat controls ===== */
.voice-btn.voice-on {
  background: rgba(124, 252, 155, 0.22);
  box-shadow: 0 0 0 2px rgba(124, 252, 155, 0.55);
}
.voice-btn.voice-pending {
  opacity: 0.6;
}

.chat-btn { position: relative; }
.chat-unread {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ff5d5d;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
  pointer-events: none;
}

.swatch.speaking::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: speaking-pulse 1.1s ease-out infinite;
  pointer-events: none;
}
@keyframes speaking-pulse {
  0% { transform: scale(0.9); opacity: 0.95; }
  70% { transform: scale(1.25); opacity: 0.25; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* ===== Chat toasts ===== */
.chat-toasts {
  position: absolute;
  left: 10px;
  bottom: max(120px, 18vh);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  max-width: min(78vw, 340px);
  pointer-events: none;
}
.chat-toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid var(--edge);
  background: rgba(9, 22, 33, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 0.88rem;
  line-height: 1.35;
  text-align: left;
  animation: chat-toast-in 0.22s ease-out;
  overflow-wrap: anywhere;
}
.chat-toast.fading { opacity: 0; transform: translateY(-6px); transition: opacity 0.5s ease, transform 0.5s ease; }
.chat-toast .swatch { flex-shrink: 0; margin-top: 2px; }
.chat-toast-name { font-weight: 800; margin-right: 6px; }
@keyframes chat-toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Chat drawer ===== */
.chat-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 130;
  display: flex;
  flex-direction: column;
  max-height: min(62vh, 480px);
  padding: 14px 14px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--edge);
  border-radius: 22px 22px 0 0;
  background: linear-gradient(180deg, #14293a, var(--bg) 70%);
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.45);
  transform: translateY(105%);
  transition: transform 0.28s ease;
  pointer-events: none;
}
.chat-drawer.open {
  transform: translateY(0);
  pointer-events: auto;
}
.chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.chat-drawer-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-family: var(--font-display);
}
.chat-log {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px;
  text-align: left;
}
.chat-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.chat-line .swatch { flex-shrink: 0; margin-top: 3px; }
.chat-line-name { font-weight: 800; margin-right: 6px; }
.chat-line-time { color: var(--muted); font-size: 0.72rem; margin-left: 6px; }
.chat-empty { color: var(--muted); font-size: 0.88rem; margin: auto; }
.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.chat-input { flex: 1; min-width: 0; }

.voice-audio-sink {
  position: fixed;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.session-pill {
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.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;
}

.reset-btn {
  width: auto;
  min-width: 58px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 0.86rem;
  font-weight: 800;
}

.profile-menu-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: none;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.profile-menu-btn:active { transform: scale(0.92); }

.player-profile-btn {
  flex: 0 0 auto;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 20px;
  font: inherit;
}

.player-profile-btn:active { transform: scale(0.92); }

.menu-profile-dot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #10202b;
  font-size: 1.45rem;
  font-weight: 900;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.18) inset;
}

.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(21, 39, 54, 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(21, 39, 54, 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:
    radial-gradient(900px 540px at 85% -6%, rgba(77, 210, 255, 0.08), transparent 60%),
    linear-gradient(180deg, #0e2130, var(--bg) 50%, var(--bg-deep));
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  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;
}

/* ===== Modal (welcome + tutorial) ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
  background: rgba(6, 14, 21, 0.72);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}

.modal-card {
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 20px;
  border: 1px solid var(--edge);
  border-radius: 22px;
  background:
    radial-gradient(560px 300px at 82% -8%, rgba(77, 210, 255, 0.10), transparent 60%),
    linear-gradient(165deg, #14293a, var(--bg) 62%, var(--bg-deep));
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
  text-align: left;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.45rem;
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}

.modal-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.welcome-identity {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.welcome-name-field { flex: 1; min-width: 0; }

.welcome-online-group {
  max-height: 180px;
  overflow-y: auto;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.welcome-actions .btn { width: 100%; }

.tutorial-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tutorial-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.tutorial-emoji {
  font-size: 1.35rem;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

.tutorial-list kbd {
  padding: 1px 6px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--panel);
  font-size: 0.82em;
}


.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-header h2 { margin: 0; font-size: 1.35rem; font-family: var(--font-display); letter-spacing: 0.02em; }

.profile-edit-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--edge);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(21, 39, 54, 0.86), rgba(12, 20, 32, 0.72));
}

.app-update-group {
  padding: 14px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: rgba(21, 39, 54, 0.55);
}

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

.version-row .menu-version {
  font-weight: 800;
}

.version-row .manage-btn {
  flex: 1 1 210px;
}

.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;
  color: #10202b;
  font-size: 1.9rem;
  font-weight: 900;
  flex-shrink: 0;
}
.preview-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.profile-name-field { min-width: 0; }
.profile-compact-field { align-items: center; }

.profile-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: rgba(21, 39, 54, 0.42);
}

.profile-shortcuts h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.shortcut-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-shortcut,
.icon-shortcut {
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.color-shortcut {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.16) inset;
}

.icon-shortcut {
  min-width: 38px;
  height: 38px;
  border-radius: 13px;
  background: var(--panel);
  color: var(--text);
  font-size: 1.25rem;
}

.color-shortcut.selected,
.icon-shortcut.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.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 var(--edge);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
}
.text-input:focus { outline: none; border-color: var(--accent); }

.profile-color-input {
  width: 72px;
  height: 48px;
  padding: 2px;
  border-radius: 12px;
  border: 2px solid var(--edge);
  background: var(--panel);
  cursor: pointer;
}

.emoji-input {
  width: 86px;
  text-align: center;
  font-size: 1.8rem;
}

.manage-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: rgba(21, 39, 54, 0.55);
}

.manage-group h3 {
  margin: 0 0 2px;
  font-size: 0.95rem;
}

.online-player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.online-player-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(8, 20, 30, 0.28);
}

.online-player-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.online-player-avatar {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #10202b;
  font-size: 1.1rem;
  font-weight: 900;
}

.online-player-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.online-player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.online-player-status {
  color: var(--muted);
  font-size: 0.78rem;
}

.online-invite-btn {
  min-height: 34px;
  padding: 0 10px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #06210f;
  font-size: 0.82rem;
  font-weight: 900;
  cursor: pointer;
}

.online-join-btn {
  min-height: 34px;
  padding: 0 10px;
  border: none;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 900;
  cursor: pointer;
}

.online-join-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.lobby-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lobby-controls h3 {
  margin: 4px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.lobby-controls.hidden { display: none; }

.lobby-left-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.lobby-code-group {
  gap: 8px;
}

.invite-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(8, 20, 30, 0.38);
}

.invite-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invite-code-row strong {
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-transform: none;
}

.invite-qr-wrap {
  display: flex;
  justify-content: center;
}

.invite-qr {
  width: 148px;
  height: 148px;
  padding: 10px;
  border-radius: 14px;
  background: #fff;
}

.invite-link-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.invite-link-input {
  font-size: 0.84rem;
}

.invite-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.manage-btn {
  width: 100%;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.manage-btn:active { transform: scale(0.98); }
.manage-btn.muted { opacity: 0.72; }
.manage-btn.danger { color: #ffd6d6; }

.music-picker {
  position: relative;
  width: 100%;
}

.music-picker-toggle {
  text-align: left;
  padding: 0 40px 0 14px;
}

.music-picker-toggle::after {
  content: "▾";
  position: absolute;
  right: 14px;
}

.music-picker-menu {
  display: none;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--edge);
  border-radius: 14px;
  background: rgba(8, 20, 30, 0.56);
}

.music-picker.open .music-picker-menu { display: flex; }

.music-track-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  background: rgba(21, 39, 54, 0.74);
}

.music-track-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}

.music-track-choice input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.music-track-choice span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.music-track-choice strong {
  color: var(--text);
  font-size: 0.9rem;
}

.music-track-choice small, .music-empty {
  color: var(--muted);
  font-size: 0.78rem;
}

.music-sample-btn {
  min-height: 34px;
  border: none;
  border-radius: 10px;
  padding: 0 10px;
  background: #26364a;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.music-sample-btn:active { transform: scale(0.96); }

.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 {
  color: var(--text);
  font-size: 1.55rem;
  font-weight: 800;
  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 var(--edge);
  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 var(--edge);
  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 var(--edge);
  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 var(--edge);
  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;
}

@media (max-width: 560px) {
  .flower-lobby-list { grid-template-columns: 1fr; }
  .screen { padding: 18px; }
  .profile-edit-card {
    grid-template-columns: auto 1fr auto;
    align-items: end;
  }
  .profile-name-field { grid-column: 2 / -1; }
  .profile-compact-field { align-items: stretch; }
  .profile-color-input { width: 52px; }
  .emoji-input { width: 58px; }
}
