/* ═══ 阅后即焚 · Snapchat-style UI ═══ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

:root {
  --yellow: #FFFC00;
  --yellow-dim: #f0ed00;
  --dark: #1a1a2e;
  --bg: #ffffff;
  --gray: #f5f5f5;
  --gray-border: #e8e8e8;
  --text: #1a1a2e;
  --text-secondary: #888;
  --red: #ff3b30;
  --green: #34c759;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

/* ═══ Screen Management ═══ */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ═══ Auth Screen ═══ */
#auth-screen {
  background: var(--yellow);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo {
  margin-bottom: 40px;
}
.auth-logo h1 {
  font-size: 32px;
  font-weight: 800;
  color: var(--dark);
  margin: 8px 0 4px;
}
.auth-logo p {
  font-size: 14px;
  color: var(--dark);
  opacity: 0.7;
}

.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--dark);
}
.auth-tab {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  color: var(--dark);
  cursor: pointer;
  transition: 0.2s;
}
.auth-tab.active {
  background: var(--dark);
  color: var(--yellow);
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 12px;
}
.auth-form.active {
  display: flex;
}
.auth-form input {
  padding: 16px;
  border: 2px solid var(--dark);
  border-radius: var(--radius);
  font-size: 16px;
  background: rgba(255,255,255,0.9);
  outline: none;
}
.auth-form input:focus {
  background: #fff;
}
.auth-btn {
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--dark);
  color: var(--yellow);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
}
.auth-btn:active {
  transform: scale(0.97);
}

.auth-error {
  color: var(--red);
  font-size: 14px;
  min-height: 20px;
  margin-top: 8px;
}

.auth-note {
  margin-top: 32px;
  font-size: 12px;
  color: var(--dark);
  opacity: 0.5;
}

/* ═══ Main App Layout ═══ */
#main-app {
  display: none;
  flex-direction: column;
  height: 100%;
}
#main-app.active {
  display: flex;
}

/* ═══ Top Bar ═══ */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--yellow);
  border-bottom: 1px solid var(--yellow-dim);
  flex-shrink: 0;
}
#current-user {
  font-weight: 700;
  font-size: 18px;
  color: var(--dark);
}
.top-actions {
  display: flex;
  gap: 8px;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--dark);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active {
  background: rgba(0,0,0,0.1);
}

/* ═══ Views ═══ */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.view.active {
  display: flex;
}
.view.fullscreen-view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: #000;
}

.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-border);
}
.view-header h2 {
  font-size: 18px;
  font-weight: 700;
}
.back-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
}

/* ═══ Chat List ═══ */
.chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state p {
  margin-bottom: 12px;
  font-size: 16px;
}
.empty-state .hint {
  font-size: 13px;
}
.empty-state.small {
  padding: 30px 20px;
}
.action-btn {
  padding: 10px 24px;
  background: var(--yellow);
  border: 2px solid var(--dark);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-border);
  cursor: pointer;
  transition: background 0.15s;
}
.chat-item:active {
  background: var(--gray);
}
.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--yellow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--dark);
  flex-shrink: 0;
  margin-right: 12px;
}
.chat-info {
  flex: 1;
  min-width: 0;
}
.chat-name {
  font-weight: 600;
  font-size: 15px;
}
.chat-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-time {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  flex-shrink: 0;
}
.status-dot.online {
  background: var(--green);
}

/* ═══ Friends View ═══ */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}
.search-bar input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
}
#search-btn {
  padding: 12px 20px;
  background: var(--dark);
  color: var(--yellow);
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}
.search-results, .friends-list {
  flex: 1;
  overflow-y: auto;
}
.friend-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-border);
}
.friend-item .chat-avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}
.friend-info {
  flex: 1;
}
.friend-name {
  font-weight: 600;
  font-size: 15px;
}
.friend-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.friend-status.online {
  color: var(--green);
}
.add-friend-btn {
  padding: 8px 16px;
  background: var(--yellow);
  border: 2px solid var(--dark);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.add-friend-btn.added {
  background: var(--gray);
  color: var(--text-secondary);
  border-color: var(--gray-border);
}
.remove-friend-btn {
  padding: 8px 12px;
  background: none;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* ═══ Chat Detail ═══ */
#chat-detail-view {
  background: var(--gray);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  word-wrap: break-word;
  position: relative;
}
.msg-bubble.sent {
  align-self: flex-end;
  background: var(--yellow);
  color: var(--dark);
  border-bottom-right-radius: 4px;
}
.msg-bubble.received {
  align-self: flex-start;
  background: #fff;
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-bubble.destroyed {
  opacity: 0.4;
  font-style: italic;
}
.msg-meta {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.msg-bubble.sent .msg-meta {
  justify-content: flex-end;
}
.msg-timer-tag {
  background: var(--dark);
  color: var(--yellow);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 600;
}
.msg-status {
  font-size: 11px;
}
.msg-status.opened {
  color: var(--red);
}

.msg-media {
  max-width: 200px;
  max-height: 280px;
  border-radius: 12px;
  display: block;
}

/* ═══ Timer Bar ═══ */
.timer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid var(--gray-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 0;
}
.timer-bar::-webkit-scrollbar {
  display: none;
}
.timer-label {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-weight: 600;
}
.timer-options {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.timer-options::-webkit-scrollbar {
  display: none;
}
.timer-opt {
  padding: 6px 12px;
  border: 1.5px solid var(--gray-border);
  border-radius: 20px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: 0.2s;
}
.timer-opt.active {
  background: var(--dark);
  color: var(--yellow);
  border-color: var(--dark);
}

/* ═══ Input Bar ═══ */
.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid var(--gray-border);
  flex-shrink: 0;
}
.input-btn {
  background: none;
  border: none;
  color: var(--dark);
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#msg-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-border);
  border-radius: 22px;
  font-size: 15px;
  outline: none;
  background: var(--gray);
}
#msg-input:focus {
  border-color: var(--yellow-dim);
  background: #fff;
}
.send-btn {
  padding: 10px 20px;
  background: var(--yellow);
  border: 2px solid var(--dark);
  border-radius: 22px;
  font-size: 14px;
  font-weight: 700;
  color: var(--dark);
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:active {
  transform: scale(0.95);
}
.send-btn:disabled {
  opacity: 0.4;
}

/* ═══ Camera View ═══ */
#camera-view {
  background: #000;
}
#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
}
.camera-top {
  display: flex;
  justify-content: space-between;
}
.camera-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.camera-bottom {
  display: flex;
  justify-content: center;
}
.capture-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255,255,255,0.3);
  cursor: pointer;
  transition: 0.15s;
}
.capture-btn:active {
  transform: scale(0.9);
  background: rgba(255,255,255,0.6);
}

/* ═══ Content Viewer (阅后即焚) ═══ */
.content-viewer {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: #000;
  flex-direction: column;
}
.content-viewer.active {
  display: flex;
}

.viewer-timer {
  position: absolute;
  top: 12px;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 210;
}
.timer-ring {
  position: relative;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.timer-ring svg {
  position: absolute;
  top: 0;
  left: 0;
  transform: rotate(-90deg);
}
.timer-ring circle {
  fill: none;
  stroke-width: 4;
}
.timer-ring .ring-bg {
  stroke: rgba(255,255,255,0.2);
}
.timer-ring .ring-fg {
  stroke: #fff;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.1s linear;
}
#timer-text {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  z-index: 1;
}

.viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px 40px;
  overflow: hidden;
}
.viewer-content img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
}
.viewer-content .text-content {
  color: #fff;
  font-size: 18px;
  text-align: center;
  word-wrap: break-word;
}

.viewer-info {
  position: absolute;
  bottom: 20px;
  bottom: calc(20px + var(--safe-bottom));
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255,255,255,0.6);
  font-size: 13px;
}

.viewer-close {
  position: absolute;
  top: 12px;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ═══ Incoming Notification ═══ */
.incoming-notification {
  display: none;
  position: absolute;
  top: 8px;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 8px;
  right: 8px;
  z-index: 150;
  background: var(--dark);
  border-radius: var(--radius);
  padding: 12px 16px;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: slideDown 0.3s ease;
}
.incoming-notification.active {
  display: flex;
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.notif-icon {
  font-size: 24px;
}
.notif-info {
  flex: 1;
}
.notif-sender {
  color: var(--yellow);
  font-weight: 700;
  font-size: 14px;
}
.notif-timer {
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  margin-top: 2px;
}
.notif-open {
  background: var(--yellow);
  color: var(--dark);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

/* ═══ Typing Indicator ═══ */
.typing-indicator {
  align-self: flex-start;
  padding: 10px 14px;
  background: #fff;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  font-size: 14px;
  color: var(--text-secondary);
}
.typing-indicator::after {
  content: '●●●';
  letter-spacing: 2px;
  animation: typingPulse 1.2s infinite;
}
@keyframes typingPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ═══ Utility ═══ */
.hidden {
  display: none !important;
}
.fade-in {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
