:root {
  --primary: #5b6ef7;
  --primary-light: #eef1ff;
  --primary-dark: #4a5de0;
  --bg: #f7f8fc;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 999px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Menlo', monospace;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  background: var(--card-bg);
  padding:0;
  box-shadow: 0 0 40px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
}

.app-header {
  text-align: center;
  padding: 32px 24px 24px;
}
.app-logo {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 12px;
  box-shadow: 0 4px 14px rgba(91,110,247,0.35);
}
.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 32px;
  min-height: 100vh;
  padding-left: 24px;
  padding-right: 24px;
  padding-bottom: 24px;
}
.logo-area {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 12px;
  box-shadow: 0 4px 14px rgba(91,110,247,0.35);
}
.title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  margin-bottom: 32px;
}

.code-input-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.code-input-wrap input {
  width: 48px;
  height: 56px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color var(--transition);
}
.code-input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,110,247,0.15);
}
.code-input-wrap input.filled {
  border-color: var(--primary);
  background: var(--primary-light);
}

.clear-row {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.btn-clear {
  padding: 8px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: #fff;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-clear:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-vstack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 260px;
}
.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  box-shadow: 0 4px 14px rgba(91,110,247,0.35);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(91,110,247,0.45);
}
.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg);
}

#mainPage {
  display: none;
  flex:1;
  flex-direction: column;
}

.room-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-light);
  border:1px solid rgba(91,110,247,0.15);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 8px 16px;
  flex-shrink: 0;
}
.room-banner-left { display: flex; align-items: center; gap: 10px; }
.room-dot {
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(34,197,94,0.4);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.room-label { font-size: 12px; color: var(--text-secondary); }
.room-code-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 3px;
  font-family: var(--font-mono);
}
.room-banner-right { display: flex; align-items: center; gap: 8px; }

.online-info {
  font-size: 12px;
  color: #fff;
  background: var(--primary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  position: relative;
}
.online-info:hover { background: var(--primary-dark); }

.device-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  border: 1px solid var(--border);
  z-index: 50;
  padding: 8px;
  animation: panel-in 0.2s ease-out;
}
.device-panel.show { display: block; }
@keyframes panel-in { from { opacity:0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.device-panel-header {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.device-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
}
.device-item.current { color: var(--primary); font-weight: 500; }
.device-item .device-time { margin-left: auto; font-size: 11px; color: var(--text-muted); }

.btn-exit {
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(239,68,68,0.08);
  color: #ef4444;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.send-area {
  background: var(--card-bg);
  border:1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 8px 16px;
  flex-shrink: 0;
  margin-top: 8px;
}
.send-area textarea {
  width: 100%;
  min-height: 56px;
  max-height: 120px;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  font-family: inherit;
}
.send-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.upload-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: #fff;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}
.send-btn {
  margin-left: auto;
  padding: 7px 22px;
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(91,110,247,0.35);
}
.upload-status {
  display: none;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}
.upload-status.active { display: block; }

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 0 2px;
}
.section-title button {
  margin-left: auto;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: #ef4444;
  font-size: 12px;
  cursor: pointer;
}

.text-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.text-item {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  animation: msg-in 0.25s ease-out;
  transition: background 0.15s;
}
.text-item:active { background: var(--primary-light); }
@keyframes msg-in { from { opacity:0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.text-content {
  flex: 1;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
  user-select: all;
}
.text-content img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 2px;
  cursor: zoom-in;
}
.copy-icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.copy-icon:active { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-jump {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-jump:active { background: var(--primary); color: #fff; border-color: var(--primary); }

.btn-save {
  flex-shrink: 0;
  padding: 0 10px;
  height: 30px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
}

.empty-state {
  text-align: center;
  padding: 48px 0 32px;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
  animation: float 3s ease-in-out infinite;
}
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.empty-text { font-size: 14px; }

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 999;
  display: none;
  pointer-events: none;
}
.toast.show {
  display: block;
  animation: toast-in 0.2s ease-out forwards;
}
@keyframes toast-in { to { transform: translate(-50%, -50%) scale(1); } }

/* Image overlay */
.img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fade-in 0.2s ease-out;
}
.img-overlay img {
  max-width: 92%;
  max-height: 82%;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}
.img-overlay .overlay-actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;
}
.img-overlay .btn-download {
  padding: 8px 24px;
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.img-overlay .btn-close-overlay {
  padding: 8px 24px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
@keyframes fade-in { from { opacity:0; } to { opacity: 1; } }

/* QR float */
#qr-float {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
#qr-popover {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  padding: 16px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
#qr-trigger {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(91,110,247,0.35);
}

/* Confirm dialog */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease-out;
}
.confirm-dialog {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 300px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.confirm-dialog-icon { font-size: 32px; margin-bottom: 12px; }
.confirm-dialog-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 16px; }
.confirm-dialog-actions { display: flex; gap: 10px; }
.confirm-dialog-actions button {
  flex: 1;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
}
.confirm-dialog-actions .btn-cancel {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
}
.confirm-dialog-actions .btn-ok {
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* Mobile */
body.is-mobile .container { max-width: 100%; }
body.is-mobile .app-header { padding: 24px 20px 20px; }
body.is-mobile .app-logo { width: 42px; height: 42px; font-size: 20px; }
body.is-mobile .app-title { font-size: 18px; }
body.is-mobile .room-code-text { font-size: 16px; }
body.is-mobile .send-row { flex-wrap: wrap; }
body.is-mobile .text-content { user-select: text; }
body.is-mobile #qr-float { display: none !important; }
body.is-mobile .login-page { padding: 24px 20px 20px; }
body.is-mobile .logo-area { width: 42px; height: 42px; font-size: 20px; }
body.is-mobile .title { font-size: 18px; margin-bottom: 24px; }
body.is-mobile .code-input-wrap input { width: 42px; height: 48px; font-size: 20px; }
