/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: 'DM Mono', 'SF Mono', monospace;

  /* Screen dimensions */
  --phone-w: 375px;
  --phone-h: 680px;

  /* Accent colors per contact */
  --sleep-bubble: #3a4a62;
  --sleep-bubble-light: #4a5e7a;
  --travel-bubble: #7a5c1e;
  --travel-bubble-light: #9a7228;
  --mall-bubble: #2a4430;
  --mall-bubble-light: #365a40;

  --received-bg: #222228;
  --sent-bg: #1a7fe8;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0a0f;
  font-family: var(--font-ui);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* ─── Desktop background ─────────────────────────────────── */
.desktop {
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 30% 60%, #0e1a2a 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 70% 30%, #0a1a0e 0%, transparent 70%),
    #070710;
}
.desktop-grain {
  position: fixed; inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px;
}

/* ─── Phone shell ─────────────────────────────────────────── */
.phone-shell {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.88);
  width: calc(var(--phone-w) + 24px);
  transform-origin: center center;
  height: calc(var(--phone-h) + 70px);
  background: linear-gradient(160deg, #1c1c22 0%, #111115 60%, #0d0d10 100%);
  border-radius: 52px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.06),
    0 0 0 2px rgba(0,0,0,0.8),
    0 40px 120px rgba(0,0,0,0.9),
    inset 0 1px 0 rgba(255,255,255,0.08),
    inset 0 -1px 0 rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 12px 20px;
  gap: 0;
}

/* Side buttons (decoration) */
.phone-shell::before {
  content: '';
  position: absolute;
  left: -3px; top: 120px;
  width: 3px; height: 40px;
  background: #1a1a20;
  border-radius: 2px 0 0 2px;
  box-shadow: 0 55px 0 #1a1a20;
}
.phone-shell::after {
  content: '';
  position: absolute;
  right: -3px; top: 140px;
  width: 3px; height: 64px;
  background: #1a1a20;
  border-radius: 0 2px 2px 0;
}

/* Dynamic island */
.phone-island {
  width: 110px; height: 30px;
  background: #000;
  border-radius: 20px;
  margin-bottom: 8px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}

/* ─── Phone screen ────────────────────────────────────────── */
.phone-screen {
  width: var(--phone-w);
  height: var(--phone-h);
  background: #000;
  border-radius: 36px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.phone-home-bar {
  width: 134px; height: 5px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  margin-top: 10px;
}

/* ─── Glitch overlay ──────────────────────────────────────── */
.glitch-overlay {
  position: absolute; inset: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}

/* Sleep glitch: screen dims + blur */
.glitch-overlay.glitch-sleep {
  background: rgba(20, 30, 50, 0.7);
  backdrop-filter: blur(4px);
  animation: glitch-sleep 0.7s ease forwards;
}
@keyframes glitch-sleep {
  0%   { opacity: 0; }
  15%  { opacity: 0.85; }
  40%  { opacity: 0.6; backdrop-filter: blur(8px); }
  70%  { opacity: 0.3; backdrop-filter: blur(2px); }
  100% { opacity: 0; backdrop-filter: blur(0); }
}

/* Travel glitch: GPS pulse + text scramble visual */
.glitch-overlay.glitch-travel {
  background: repeating-linear-gradient(
    90deg,
    transparent 0px,
    transparent 3px,
    rgba(210,160,40,0.04) 3px,
    rgba(210,160,40,0.04) 4px
  );
  animation: glitch-travel 0.65s ease forwards;
}
.glitch-overlay.glitch-travel::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(210,160,40,0.15) 0%, transparent 70%);
  animation: gps-pulse 0.65s ease forwards;
}
@keyframes glitch-travel {
  0%   { opacity: 0; transform: translateX(0); }
  10%  { opacity: 1; transform: translateX(-3px); }
  30%  { opacity: 0.8; transform: translateX(5px); }
  50%  { opacity: 0.6; transform: translateX(-2px); }
  80%  { opacity: 0.2; transform: translateX(1px); }
  100% { opacity: 0; transform: translateX(0); }
}
@keyframes gps-pulse {
  0%   { opacity: 0; transform: scale(0.5); }
  30%  { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(0.8); }
}

/* Mall glitch: grid flicker */
.glitch-overlay.glitch-mall {
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 6px,
    rgba(100,180,100,0.04) 6px,
    rgba(100,180,100,0.04) 7px
  ),
  repeating-linear-gradient(
    90deg,
    transparent 0px,
    transparent 14px,
    rgba(100,180,100,0.03) 14px,
    rgba(100,180,100,0.03) 15px
  );
  animation: glitch-mall 0.8s ease forwards;
}
.glitch-overlay.glitch-mall::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(80,180,80,0.06);
  animation: flicker-pulse 0.8s steps(1) forwards;
}
@keyframes glitch-mall {
  0%   { opacity: 0; }
  5%   { opacity: 1; }
  20%  { opacity: 0.6; }
  35%  { opacity: 1; }
  55%  { opacity: 0.4; }
  80%  { opacity: 0.1; }
  100% { opacity: 0; }
}
@keyframes flicker-pulse {
  0%,20%,40%,60%,80% { opacity: 1; }
  10%,30%,50%,70%,90%,100% { opacity: 0; }
}

/* ─── Screens ─────────────────────────────────────────────── */
.screen {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}



/* Loading screen */
#screenLoading {
  background: #020306;
  overflow: hidden;
}
.loading-screen-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
  transform: scale(1.22);
}
/* Content warning */
#screenWarning {
  background: #09090d;
  align-items: center;
  justify-content: center;
  padding: 34px;
}
.content-warning {
  width: 100%;
  text-align: left;
}
.warning-label {
  color: #777;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 14px;
}
.content-warning p {
  color: #f2f2f2;
  font-size: 19px;
  line-height: 1.45;
  margin-bottom: 28px;
}
.warning-continue,
.settings-command {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  color: white;
  font-family: var(--font-ui);
  font-size: 15px;
  padding: 13px 16px;
}
.warning-continue:active,
.settings-command:active {
  background: rgba(255,255,255,0.18);
}
/* ─── Home screen ─────────────────────────────────────────── */
#screenHome {
  background: linear-gradient(170deg, #0d1b2a 0%, #050d15 40%, #000 100%);
}

.home-wallpaper {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 30%, rgba(20,60,120,0.25) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 70%, rgba(10,40,80,0.2) 0%, transparent 70%);
  pointer-events: none;
}

.home-statusbar {
  position: relative; z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px 4px;
  color: white;
}
.status-time {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}
.status-icons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.home-date {
  position: relative; z-index: 1;
  text-align: center;
  margin-top: 30px;
  color: white;
}
.home-date-day {
  font-size: 17px;
  font-weight: 300;
  opacity: 0.7;
  letter-spacing: 0.5px;
}
.home-date-num {
  font-size: 72px;
  font-weight: 200;
  line-height: 1;
  letter-spacing: -3px;
  margin-top: 4px;
}

.home-apps {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 10px;
  padding: 30px 18px 18px;
  margin-top: 20px;
}

.app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: default;
}
.app-icon.clickable { cursor: pointer; }
.app-icon.clickable:active .app-icon-bg { transform: scale(0.93); }

.app-icon-bg {
  width: 60px; height: 60px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.app-icon-bg svg {
  width: 32px; height: 32px;
}
.app-icon span {
  font-size: 11px;
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  font-weight: 400;
  letter-spacing: -0.1px;
}

.app-badge {
  position: absolute;
  top: -5px; right: -5px;
  width: 20px; height: 20px;
  background: #ff3b30;
  border-radius: 50%;
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #000;
}

/* Dock */
.home-dock {
  position: absolute;
  bottom: 20px;
  left: 18px; right: 18px;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(20px);
  border-radius: 28px;
  padding: 12px 8px;
  display: flex;
  justify-content: space-around;
  z-index: 2;
  border: 1px solid rgba(255,255,255,0.08);
}
.dock-icon { cursor: pointer; }
.dock-icon .app-icon-bg {
  width: 56px; height: 56px;
  border-radius: 14px;
}

/* ─── App header (shared) ─────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 50px 16px 14px;
  background: rgba(18,18,22,0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}
.app-header-title {
  font-size: 17px;
  font-weight: 600;
  color: white;
  letter-spacing: -0.3px;
}
.back-btn, .header-action {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #1a7fe8;
  display: flex;
  align-items: center;
  width: 40px;
  height: 40px;
  justify-content: center;
}
.back-btn svg, .header-action svg { width: 22px; height: 22px; }

/* ─── Messages list ───────────────────────────────────────── */
#screenMessages {
  background: #111115;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 16px;
  background: rgba(255,255,255,0.07);
  border-radius: 12px;
  padding: 8px 12px;
}
.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: #666;
  font-size: 15px;
  font-family: var(--font-ui);
  width: 100%;
}

.contact-list {
  overflow-y: auto;
  flex: 1;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  transition: background 0.15s;
}
.contact-row:active { background: rgba(255,255,255,0.04); }

.contact-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-sleep  { background: #1a2438; }
.avatar-travel { background: #2a1e08; }
.avatar-mall   { background: #0e1e12; }

.contact-avatar svg { width: 36px; height: 36px; }

.contact-info { flex: 1; overflow: hidden; }
.contact-name-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}
.contact-name { font-size: 16px; font-weight: 600; color: #e0e0e0; }
.contact-time { font-size: 12px; color: #555; }
.contact-preview { font-size: 14px; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Chat screen ─────────────────────────────────────────── */
#screenChat {
  background: #0c0c10;
}

.chat-header { padding-top: 50px; }
.chat-header-center {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-header-info {
  display: flex;
  flex-direction: column;
}
.chat-contact-name {
  font-size: 15px;
  font-weight: 600;
  color: white;
  line-height: 1.2;
}
.chat-status {
  font-size: 11px;
  color: #34c759;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Timestamp divider */
.msg-divider {
  text-align: center;
  font-size: 11px;
  color: #444;
  margin: 8px 0 4px;
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}

/* Bubble */
.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.bubble-row.sent { justify-content: flex-end; }
.bubble-row.received { justify-content: flex-start; }

.bubble-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.bubble {
  max-width: 72%;
  padding: 10px 13px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  color: #e8e8e8;
  word-wrap: break-word;
}
.bubble-row.sent .bubble {
  background: var(--sent-bg);
  border-bottom-right-radius: 5px;
  color: white;
}
.bubble-row.received .bubble {
  border-bottom-left-radius: 5px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--received-bg);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
}
.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #555;
  animation: typing-bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%,60%,100% { transform: translateY(0); background: #555; }
  30%          { transform: translateY(-5px); background: #888; }
}

/* ─── Chat input bar ──────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 24px;
  background: rgba(18,18,22,0.95);
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}
.chat-input-field {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border-radius: 24px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.1);
}
.chat-input-field input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #aaa;
  font-size: 15px;
  font-family: var(--font-ui);
  padding: 10px 4px;
}
.emoji-btn, .send-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 4px;
}
.send-btn svg { width: 34px; height: 34px; }

/* ─── Settings screen ─────────────────────────────────────── */
#screenSettings {
  background: #0e0e12;
}
.settings-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}
.settings-section-label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 12px 20px 6px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  background: rgba(255,255,255,0.02);
  cursor: pointer;
}
.settings-row:active { background: rgba(255,255,255,0.06); }
.settings-row-info {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ccc;
  font-size: 15px;
}
.settings-row-hint {
  font-size: 12px;
  color: #444;
  padding: 6px 20px 12px;
  line-height: 1.5;
}

/* Toggle */
.toggle {
  width: 51px; height: 31px;
  background: #3a3a3a;
  border-radius: 16px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s ease;
  flex-shrink: 0;
}
.toggle.on { background: #34c759; }
.toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.3s ease;
}
.toggle.on .toggle-knob { transform: translateX(20px); }

.settings-input-row {
  gap: 14px;
}
.settings-text-input {
  width: 138px;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  color: #ddd;
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 9px 10px;
  outline: none;
}
.settings-text-input::placeholder {
  color: #555;
}
.settings-command {
  width: calc(100% - 40px);
  margin: 0 20px;
  text-align: center;
}
.settings-version {
  text-align: center;
  color: #333;
  font-size: 12px;
  font-family: var(--font-mono);
  padding: 32px 0 16px;
}

/* ─── Bubble colors per contact ───────────────────────────── */
body.contact-sleep .bubble-row.received .bubble {
  background: var(--sleep-bubble);
}
body.contact-travel .bubble-row.received .bubble {
  background: var(--travel-bubble);
}
body.contact-mall .bubble-row.received .bubble {
  background: var(--mall-bubble);
}

/* Sleep bubble subtle scan line */
body.contact-sleep .bubble-row.received .bubble {
  background: linear-gradient(160deg, #4a5e7a 0%, #3a4a62 100%);
  box-shadow: 0 1px 6px rgba(80,120,200,0.15);
}
body.contact-travel .bubble-row.received .bubble {
  background: linear-gradient(160deg, #9a7228 0%, #7a5c1e 100%);
  box-shadow: 0 1px 6px rgba(200,160,40,0.15);
}
body.contact-mall .bubble-row.received .bubble {
  background: linear-gradient(160deg, #365a40 0%, #2a4430 100%);
  box-shadow: 0 1px 6px rgba(80,180,80,0.1);
}

/* Avatar bg per contact */
body.contact-sleep .bubble-avatar { background: #1a2438; }
body.contact-travel .bubble-avatar { background: #2a1e08; }
body.contact-mall .bubble-avatar { background: #0e1e12; }

/* ─── Animations ──────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble-row {
  animation: fadeInUp 0.25s ease forwards;
}
