:root {
  --bg: #0a0a0b;
  --bg-elevated: #141417;
  --bg-card: #1c1c20;
  --bg-card-hover: #24242a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --text-dim: #9a9aa2;
  --text-faint: #5c5c64;
  --accent: #ffffff;
  --gloss: linear-gradient(180deg, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0.02) 40%, rgba(255,255,255,0) 100%);
  --gloss-strong: linear-gradient(180deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.03) 50%, rgba(255,255,255,0) 100%);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --radius-sm: 10px;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 50% -10%, #1a1a1e 0%, #0a0a0b 55%);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.topbar {
  position: fixed;
  top: -80px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding: 14px 16px;
  z-index: 50;
  transition: top 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.topbar.visible {
  top: 0;
  pointer-events: all;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  background-image: var(--gloss);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 10px 8px 18px;
  box-shadow: var(--shadow);
  position: relative;
}

.topbar-label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-id {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.12em;
  font-family: "SF Mono", "Menlo", monospace;
}

.copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  background-image: var(--gloss);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}

.copy-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

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

.copy-feedback {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  opacity: 0;
  transform: translateY(-4px);
  transition: all 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
}

.copy-feedback.show {
  opacity: 1;
  transform: translateY(0);
}

.screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.screen[hidden] {
  display: none !important;
}

.title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 32px;
  max-width: 360px;
  line-height: 1.5;
}

.roller-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 420px;
}

.roller-frame {
  position: relative;
  width: 100%;
  max-width: 340px;
  margin-bottom: 36px;
}

.roller-window {
  height: 72px;
  overflow: hidden;
  background: var(--bg-card);
  background-image: var(--gloss-strong);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 0 40px rgba(255,255,255,0.02);
  position: relative;
}

.roller-window::before,
.roller-window::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 35px;
  z-index: 2;
  pointer-events: none;
}

.roller-window::before {
  top: 0;
  background: linear-gradient(180deg, rgba(28,28,32,1) 0%, rgba(28,28,32,0) 100%);
}

.roller-window::after {
  bottom: 0;
  background: linear-gradient(0deg, rgba(28,28,32,1) 0%, rgba(28,28,32,0) 100%);
}

.roller-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.roller-strip .roller-item {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text);
  white-space: nowrap;
}

.roller-placeholder {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 72px;
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

.spinner {
  font-size: 28px;
  position: relative;
  display: inline-block;
  width: 1em;
  height: 1em;
}
.spinner.center {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
}
.spinner .spinner-blade {
  position: absolute;
  left: 0.4629em;
  bottom: 0;
  width: 0.074em;
  height: 0.2777em;
  border-radius: 0.0555em;
  background-color: transparent;
  transform-origin: center -0.2222em;
  animation: spinner-fade9234 1s infinite linear;
}
.spinner .spinner-blade:nth-child(1)  { animation-delay: 0s;     transform: rotate(0deg); }
.spinner .spinner-blade:nth-child(2)  { animation-delay: 0.083s; transform: rotate(30deg); }
.spinner .spinner-blade:nth-child(3)  { animation-delay: 0.166s; transform: rotate(60deg); }
.spinner .spinner-blade:nth-child(4)  { animation-delay: 0.249s; transform: rotate(90deg); }
.spinner .spinner-blade:nth-child(5)  { animation-delay: 0.332s; transform: rotate(120deg); }
.spinner .spinner-blade:nth-child(6)  { animation-delay: 0.415s; transform: rotate(150deg); }
.spinner .spinner-blade:nth-child(7)  { animation-delay: 0.498s; transform: rotate(180deg); }
.spinner .spinner-blade:nth-child(8)  { animation-delay: 0.581s; transform: rotate(210deg); }
.spinner .spinner-blade:nth-child(9)  { animation-delay: 0.664s; transform: rotate(240deg); }
.spinner .spinner-blade:nth-child(10) { animation-delay: 0.747s; transform: rotate(270deg); }
.spinner .spinner-blade:nth-child(11) { animation-delay: 0.83s;  transform: rotate(300deg); }
.spinner .spinner-blade:nth-child(12) { animation-delay: 0.913s; transform: rotate(330deg); }
@keyframes spinner-fade9234 {
  0%   { background-color: #69717d; }
  100% { background-color: transparent; }
}

.primary-btn {
  background: var(--bg-card);
  background-image: var(--gloss-strong);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.15s ease;
  letter-spacing: 0.01em;
}

.primary-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.connect-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 420px;
}

.connect-form {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.peer-input {
  flex: 1;
  background: var(--bg-card);
  background-image: var(--gloss);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
  padding: 14px 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

.peer-input:focus {
  border-color: var(--accent);
}

.peer-input::placeholder {
  letter-spacing: normal;
  font-family: -apple-system, sans-serif;
  font-weight: 400;
  font-size: 14px;
  color: var(--text-faint);
}

.connect-status {
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  min-height: 18px;
}

.connect-status.error { color: #d8a0a0; }
.connect-status.success { color: #a0d8b8; }

.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  padding: 0;
  padding-top: 48px;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  background-image: var(--gloss);
  flex-shrink: 0;
  z-index: 10;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #6ee0a0;
  box-shadow: 0 0 8px rgba(110, 224, 160, 0.6);
  flex-shrink: 0;
}

.status-dot.offline {
  background: var(--text-faint);
  box-shadow: none;
}

.chat-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.chat-peer-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chat-peer-id {
  font-size: 15px;
  font-weight: 600;
  font-family: "SF Mono", "Menlo", monospace;
  letter-spacing: 0.1em;
}

.leave-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.leave-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 18px 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.msg-group {
  display: flex;
  flex-direction: column;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
}

.msg-group:hover {
  background: var(--bg-card);
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-sender {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.msg-group.own .msg-sender {
  color: #a0c8f8;
}

.msg-group.peer .msg-sender {
  font-family: "SF Mono", "Menlo", monospace;
  letter-spacing: 0.05em;
  color: #f0b8a0;
}

.msg-time-header {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 400;
  margin-top: 0;
}

/* Per-bubble wrapper */
.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  padding: 1px 0;
  border-radius: 4px;
}

/* Header actions: sits right after the timestamp, shown on group hover */
.msg-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 2px 6px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  margin-left: 4px;
}

.msg-group:hover .msg-header-actions {
  opacity: 1;
  pointer-events: all;
}

.msg-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.msg-action-btn:hover {
  color: var(--text);
  background: var(--bg-card-hover);
}

.msg-action-btn:active {
  transform: scale(0.95);
}

/* Reply quote block inside message */
.msg-reply-quote {
  display: flex;
  align-items: baseline;
  gap: 6px;
  border-left: 3px solid var(--border-strong);
  padding: 3px 8px;
  margin-bottom: 4px;
  border-radius: 0 4px 4px 0;
  background: rgba(255,255,255,0.03);
  max-width: 100%;
  overflow: hidden;
}

.msg-reply-quote-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.msg-reply-quote-text {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reply bar above input */
.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 18px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.reply-bar[hidden] {
  display: none;
}

.reply-bar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.reply-bar-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.reply-bar-label strong {
  color: var(--text);
}

.reply-bar-text {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-bar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.reply-bar-close:hover {
  color: var(--text);
  background: var(--bg-card);
  border-color: var(--border-strong);
}

.msg-bubble {
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}

.msg-time {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
}

.system-msg {
  .title { font-size: 22px; }
  .roller-strip .roller-item { font-size: 28px; }
}
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  margin: 14px 0;
  letter-spacing: 0.02em;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 26px;
  font-size: 12px;
  color: var(--text-faint);
  flex-shrink: 0;
}

.typing-indicator[hidden] {
  display: none;
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.message-input {
  flex: 1;
  background: var(--bg-card);
  background-image: var(--gloss);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 11px 14px;
  resize: none;
  outline: none;
  max-height: 140px;
  line-height: 1.4;
  transition: border-color 0.15s ease;
  display: block;
  width: 100%;
  writing-mode: horizontal-tb;
}

.message-input:focus {
  border-color: var(--accent);
}

.message-input::placeholder {
  color: var(--text-faint);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  background-image: var(--gloss-strong);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.attach-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-card);
}

.attach-btn:active {
  transform: scale(0.94);
}

.attach-btn.has-file {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-card);
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 0;
  background: var(--bg-elevated);
  position: relative;
}

.attachment-preview[hidden] {
  display: none;
}

.attachment-preview-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.attachment-preview-inner img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.attachment-preview-inner .attach-file-icon {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-dim);
}

.attachment-preview-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.attachment-preview-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-preview-size {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.attachment-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.attachment-remove:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.msg-attachment {
  margin-top: 6px;
}

.msg-attachment img {
  max-width: min(320px, 100%);
  max-height: 260px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.msg-attachment img:hover {
  opacity: 0.9;
}

.msg-attachment video {
  max-width: min(320px, 100%);
  max-height: 260px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

.msg-attachment audio {
  width: 100%;
  max-width: 280px;
  margin-top: 4px;
}

.msg-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  max-width: 260px;
}

.msg-attachment-file:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.msg-attachment-file-icon {
  color: var(--text-dim);
  flex-shrink: 0;
}

.msg-attachment-file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.msg-attachment-file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.msg-attachment-file-size {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
  animation: lightboxIn 0.2s ease;
}

@keyframes lightboxIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}