* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Cascadia Mono', 'Consolas', 'SF Mono', 'Courier New', monospace;
  background: linear-gradient(145deg, #1a1b26 0%, #24283b 100%);
  color: #c0caf5;
  min-height: 100vh;
}

/* Lobby */
body.lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.card {
  background: rgba(36, 40, 59, 0.9);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  color: #7aa2f7;
}

.subtitle {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  color: #a9b1d6;
}

.join-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: #9ece6a;
}

.join-form input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid #3b4261;
  border-radius: 8px;
  background: #1a1b26;
  color: #c0caf5;
  font-size: 1rem;
  font-family: inherit;
}

.join-form input:focus {
  outline: none;
  border-color: #7aa2f7;
}

.join-form button {
  width: 100%;
  padding: 0.75rem;
  margin-top: 0.5rem;
  border: none;
  border-radius: 8px;
  background: #7aa2f7;
  color: #1a1b26;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.join-form button:hover {
  background: #89b4fa;
}

/* Chat page – theme/font variables (overridden by JS) */
.chat-page {
  --chat-font-size: 1rem;
  --chat-bg: linear-gradient(145deg, #1a1b26 0%, #24283b 100%);
  --chat-header-bg: rgba(36, 40, 59, 0.95);
  --chat-border: #3b4261;
  --chat-input-bg: #1a1b26;
  --chat-text: #c0caf5;
  --chat-accent: #7aa2f7;
  --chat-msg-other-bg: #3b4261;
  --chat-msg-own-bg: #7aa2f7;
  --chat-system: #565f89;
}

.chat-page.theme-amber {
  --chat-bg: linear-gradient(145deg, #1e1b1a 0%, #2d2620 100%);
  --chat-header-bg: rgba(45, 38, 32, 0.95);
  --chat-border: #4a3f36;
  --chat-input-bg: #1e1b1a;
  --chat-text: #e0d4c8;
  --chat-accent: #d4a574;
  --chat-msg-other-bg: #4a3f36;
  --chat-msg-own-bg: #c4956a;
  --chat-system: #8b7355;
}

.chat-page.theme-slate {
  --chat-bg: linear-gradient(145deg, #0f1419 0%, #1a2332 100%);
  --chat-header-bg: rgba(26, 35, 50, 0.95);
  --chat-border: #2d3d52;
  --chat-input-bg: #0f1419;
  --chat-text: #b8d4e8;
  --chat-accent: #58a6ff;
  --chat-msg-other-bg: #2d3d52;
  --chat-msg-own-bg: #58a6ff;
  --chat-system: #6b8fb8;
}

.chat-page.theme-gray {
  --chat-bg: linear-gradient(145deg, #2a2a2e 0%, #3d3d42 100%);
  --chat-header-bg: rgba(61, 61, 66, 0.95);
  --chat-border: #505056;
  --chat-input-bg: #2a2a2e;
  --chat-text: #d4d4d8;
  --chat-accent: #9ca3af;
  --chat-msg-other-bg: #505056;
  --chat-msg-own-bg: #6b7280;
  --chat-system: #71717a;
}

.chat-page.theme-blue {
  --chat-bg: linear-gradient(145deg, #0c1929 0%, #132f4c 100%);
  --chat-header-bg: rgba(19, 47, 76, 0.95);
  --chat-border: #1e4976;
  --chat-input-bg: #0c1929;
  --chat-text: #b8d4f0;
  --chat-accent: #0ea5e9;
  --chat-msg-other-bg: #1e4976;
  --chat-msg-own-bg: #0284c7;
  --chat-system: #5b8fc4;
}

/* Image background themes – applied to messages area only */
.chat-page.theme-waterfront .messages,
.chat-page.theme-buildings .messages,
.chat-page.theme-apartments .messages,
.chat-page.theme-fireflies .messages,
.chat-page.theme-snowy-lot .messages {
  background-color: #0f0f12;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
}

/* Darkening overlay on image themes so text stays readable */
.chat-page.theme-waterfront .messages::before,
.chat-page.theme-buildings .messages::before,
.chat-page.theme-apartments .messages::before,
.chat-page.theme-fireflies .messages::before,
.chat-page.theme-snowy-lot .messages::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  z-index: 0;
}

/* Chat page */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100dvh;
  background: var(--chat-bg);
  color: var(--chat-text);
}


.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--chat-header-bg);
  border-bottom: 1px solid var(--chat-border);
}

.back-link {
  color: var(--chat-accent);
  text-decoration: none;
  font-size: 0.95rem;
}

.back-link:hover {
  text-decoration: underline;
}

.room-badge, .nick-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.room-badge {
  background: var(--chat-system);
  color: var(--chat-text);
}

.user-count {
  font-size: 0.75rem;
  color: #7aa2f7;
  padding: 0.15rem 0.45rem;
  background: rgba(122, 162, 247, 0.12);
  border-radius: 8px;
}

.nick-badge {
  background: var(--chat-accent);
  color: #1a1b26;
  margin-left: auto;
}

.header-icon-btn {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--chat-text);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.header-icon-btn:hover {
  background: var(--chat-border);
  opacity: 1;
}

.messages-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.yt-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.yt-bg iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 100%;
  min-height: 100%;
  width: 177.78vh;
  height: 56.25vw;
  transform: translate(-50%, -50%);
  border: none;
}

.messages {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.messages-wrap.yt-active .messages {
  background: transparent !important;
  background-image: none !important;
}

.messages-wrap.yt-active .messages::before {
  display: none !important;
}

.msg {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  font-size: var(--chat-font-size);
  word-break: break-word;
  position: relative;
}

.react-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(59, 66, 97, 0.85);
  color: #c0caf5;
  font-size: 13px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.msg:hover .react-btn {
  display: flex;
}

.react-btn:hover {
  background: #565f89;
}

.reaction-picker {
  position: absolute;
  top: -34px;
  right: 0;
  display: flex;
  gap: 1px;
  background: #1e2030;
  border: 1px solid #3b4261;
  border-radius: 8px;
  padding: 3px;
  z-index: 10;
}

.reaction-picker button {
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.reaction-picker button:hover {
  background: #3b4261;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-pill {
  border: 1px solid #3b4261;
  background: #1e2030;
  color: #c0caf5;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  cursor: pointer;
}

.reaction-pill:hover {
  background: #3b4261;
}

.reaction-pill.reacted {
  border-color: #7aa2f7;
  background: rgba(122, 162, 247, 0.15);
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--chat-system);
  font-size: calc(var(--chat-font-size) * 0.9);
}

.msg.own {
  align-self: flex-end;
  background: var(--chat-msg-own-bg);
  color: #1a1b26;
}

.msg.other {
  align-self: flex-start;
  background: var(--chat-msg-other-bg);
  color: var(--chat-text);
}

.msg .sender {
  font-size: calc(var(--chat-font-size) * 0.8);
  margin-bottom: 0.2rem;
  opacity: 0.9;
}

.msg img.chat-photo {
  max-width: 240px;
  max-height: 300px;
  border-radius: 8px;
  display: block;
  margin-top: 0.25rem;
  cursor: pointer;
}

.photo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: zoom-out;
}

.photo-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}

.send-form {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--chat-header-bg);
  border-top: 1px solid var(--chat-border);
}

.input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap input {
  width: 100%;
  padding: 0.65rem 4.5rem 0.65rem 0.75rem;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  background: var(--chat-input-bg);
  color: var(--chat-text);
  font-size: var(--chat-font-size);
  font-family: inherit;
}

.input-wrap input:focus {
  outline: none;
  border-color: var(--chat-accent);
}

.input-icon-btn {
  position: absolute;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #565f89;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-icon-btn:hover {
  color: var(--chat-text);
  background: var(--chat-border);
}

#photo-btn { right: 2.25rem; }
#emoji-btn { right: 0.4rem; }

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  width: 280px;
  max-height: 220px;
  overflow-y: auto;
  background: #1a1b26;
  border: 1px solid #3b4261;
  border-radius: 10px;
  padding: 0.5rem;
  display: none;
  flex-wrap: wrap;
  gap: 2px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 500;
}

.emoji-picker.open {
  display: flex;
}

.emoji-picker button {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-picker button:hover {
  background: #3b4261;
}

.send-form > button[type="submit"] {
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--chat-accent);
  color: #1a1b26;
  font-size: var(--chat-font-size);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.send-form > button[type="submit"]:hover {
  filter: brightness(1.1);
}

.send-form > button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Settings overlay & panel */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.settings-overlay.open {
  opacity: 1;
  visibility: visible;
}

.settings-panel {
  background: #1a1b26;
  border-radius: 12px;
  padding: 0;
  width: 100%;
  max-width: 340px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  border: 1px solid #3b4261;
}

.settings-panel .settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #3b4261;
}

.settings-panel .settings-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: #c0caf5;
}

.settings-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #a9b1d6;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.settings-close:hover {
  background: #3b4261;
  color: #c0caf5;
}

.settings-body {
  padding: 1.25rem;
}

.setting-group {
  margin-bottom: 1.25rem;
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: #9ece6a;
}

.setting-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.size-opt,
.theme-opt {
  padding: 0.5rem 0.85rem;
  border: 1px solid #3b4261;
  border-radius: 8px;
  background: #24283b;
  color: #c0caf5;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.size-opt:hover,
.theme-opt:hover {
  border-color: #7aa2f7;
  background: #2d3250;
}

.size-opt.active,
.theme-opt.active {
  border-color: #7aa2f7;
  background: #7aa2f7;
  color: #1a1b26;
}

.theme-options .theme-opt {
  min-width: 4rem;
}

/* Volume slider */
.volume-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #3b4261;
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #7aa2f7;
  cursor: pointer;
  border: none;
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #7aa2f7;
  cursor: pointer;
  border: none;
}

.volume-value {
  font-size: 0.85rem;
  color: #a9b1d6;
  min-width: 2.5rem;
  text-align: right;
}

.font-size-preview {
  margin-top: 0.4rem;
  padding: 0.4rem 0.6rem;
  background: #24283b;
  border-radius: 6px;
  border: 1px solid #3b4261;
  color: #a9b1d6;
  word-break: break-word;
}

/* Radio panel */
.radio-panel {
  max-width: 380px;
}

.radio-search-wrap {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.radio-search-wrap input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1px solid #3b4261;
  border-radius: 8px;
  background: #1a1b26;
  color: #c0caf5;
  font-size: 0.9rem;
  font-family: inherit;
}

.radio-search-wrap input:focus {
  outline: none;
  border-color: #7aa2f7;
}

.radio-search-wrap button {
  padding: 0.55rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: #7aa2f7;
  color: #1a1b26;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.radio-search-wrap button:hover {
  filter: brightness(1.1);
}

.radio-results {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.radio-results .radio-empty {
  text-align: center;
  color: #565f89;
  font-size: 0.85rem;
  padding: 1.5rem 0;
}

.radio-station {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid #3b4261;
  border-radius: 8px;
  background: #24283b;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.radio-station:hover {
  border-color: #7aa2f7;
  background: #2d3250;
}

.radio-station-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  background: #3b4261;
  flex-shrink: 0;
}

.radio-station-info {
  flex: 1;
  min-width: 0;
}

.radio-station-name {
  font-size: 0.9rem;
  color: #c0caf5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.radio-station-meta {
  font-size: 0.75rem;
  color: #565f89;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Now playing bar */
.now-playing[hidden] {
  display: none !important;
}

.now-playing {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  background: #1e2030;
  border-bottom: 1px solid #3b4261;
  font-size: 0.8rem;
  color: #9ece6a;
}

.now-playing-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing-stop {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #f7768e;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.now-playing-ctrl {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #c0caf5;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.now-playing-ctrl:hover {
  background: #3b4261;
}

.now-playing-stop:hover {
  background: #3b4261;
}

/* YouTube panel */
.yt-url-wrap {
  display: flex;
  gap: 0.5rem;
}

.yt-url-wrap input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1px solid #3b4261;
  border-radius: 8px;
  background: #1a1b26;
  color: #c0caf5;
  font-size: 0.9rem;
  font-family: inherit;
}

.yt-url-wrap input:focus {
  outline: none;
  border-color: #7aa2f7;
}

.yt-url-wrap button {
  padding: 0.55rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: #ff0000;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.yt-url-wrap button:hover {
  filter: brightness(1.15);
}
