:root {
  --sat: 54px;                 /* 顶部安全区：灵动岛 */
  --sab: 34px;                 /* 底部安全区：Home 条 */
  --blue: #2a8bf2;
  --tg-bubble-out: #e1f4cd;
  --tg-bubble-in: #ffffff;
  --sys-bg: #f2f2f7;
  --sep: rgba(60,60,67,.18);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font-family: var(--font); }
body { background: #0b0c10; overflow: hidden; }
button, input, textarea { font: inherit; }
button { border: 0; background: none; cursor: pointer; color: inherit; }

/* ---------- 外框 ---------- */
#stage { height: 100%; display: flex; align-items: center; justify-content: center; }
#phone {
  position: relative; width: 390px; height: 844px; max-height: 96vh;
  border-radius: 55px; overflow: hidden; background: #000;
  box-shadow: 0 0 0 11px #1c1c1e, 0 0 0 13px #3a3a3c, 0 30px 80px rgba(0,0,0,.6);
  color: #000; user-select: none;
}
@media (max-width: 500px) {
  :root { --sat: env(safe-area-inset-top, 54px); --sab: max(env(safe-area-inset-bottom, 34px), 34px); }
  html, body { background: #000; }
  #stage { display: block; height: auto; }
  #phone { position: fixed; top: -1px; left: 0; right: 0; bottom: -1px; width: auto; height: auto; max-height: none; border-radius: 0; box-shadow: none; overflow: visible; }
  #statusbar { display: none; }
  #homebar { display: none; }
}

/* ---------- 状态栏 ---------- */
#statusbar {
  position: absolute; z-index: 60; top: 0; left: 0; right: 0; height: 54px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 34px 0 42px; font-weight: 600; font-size: 16px; pointer-events: none;
  transition: color .2s;
}
#phone.status-light #statusbar { color: #fff; }
#phone.status-dark  #statusbar { color: #000; }
#statusbar .island { position: absolute; left: 50%; top: 11px; width: 120px; height: 35px; margin-left: -60px; background: #000; border-radius: 20px; }
.sb-right { display: flex; gap: 6px; align-items: center; }

/* ---------- 通用 ---------- */
.screen, .app { position: absolute; top: 0; left: 0; right: 0; bottom: -50px; padding-bottom: 50px; }
#homebar {
  position: absolute; z-index: 70; bottom: 8px; left: 50%; width: 136px; height: 5px; margin-left: -68px;
  background: #fff; border-radius: 3px; cursor: pointer; box-shadow: 0 0 0 .5px rgba(0,0,0,.25);
}
#phone.status-dark #homebar { background: #000; box-shadow: none; }
#homebar::before { content: ""; position: absolute; inset: -14px -20px; }
#toast {
  position: absolute; z-index: 90; left: 50%; top: calc(var(--sat) + 8px); transform: translate(-50%, -20px);
  max-width: 82%; padding: 10px 16px; border-radius: 18px; background: rgba(40,40,44,.92); color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 主屏幕 ---------- */
#home {
  background:
    radial-gradient(120% 80% at 15% 10%, #6d8cff 0%, transparent 55%),
    radial-gradient(100% 70% at 90% 30%, #c77dff 0%, transparent 55%),
    radial-gradient(120% 90% at 40% 100%, #ff8fa3 0%, transparent 60%),
    #2b2f77;
  padding: calc(var(--sat) + 14px) 22px 0; color: #fff;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), filter .35s;
}
#phone.in-app #home { transform: scale(.94); filter: brightness(.7); }
.widget {
  height: 158px; border-radius: 24px; padding: 18px 20px;
  background: rgba(255,255,255,.18); backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  box-shadow: inset 0 0 0 .5px rgba(255,255,255,.35); display: flex; flex-direction: column; justify-content: flex-end;
}
.w-time { font-size: 58px; font-weight: 300; letter-spacing: -1px; line-height: 1; }
.w-date { margin-top: 6px; font-size: 15px; opacity: .85; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); row-gap: 22px; margin-top: 26px; }
.icon { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11.5px; text-shadow: 0 1px 3px rgba(0,0,0,.35); }
.icon .tile {
  width: 60px; height: 60px; border-radius: 14px; display: grid; place-items: center; color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.25), inset 0 0 0 .5px rgba(255,255,255,.25);
  transition: transform .12s;
}
.icon:active .tile { transform: scale(.9); }
.icon svg { width: 34px; height: 34px; }
.search-pill {
  position: absolute; left: 50%; bottom: calc(var(--sab) + 104px); transform: translateX(-50%);
  padding: 6px 30px; border-radius: 16px; background: rgba(255,255,255,.22); font-size: 13px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.dock {
  position: absolute; left: 12px; right: 12px; bottom: calc(var(--sab) + 4px); height: 90px; padding: 15px 14px;
  border-radius: 34px; background: rgba(255,255,255,.22); backdrop-filter: blur(26px); -webkit-backdrop-filter: blur(26px);
  display: grid; grid-template-columns: repeat(4, 1fr); justify-items: center; align-items: center;
}
.dock .icon { font-size: 0; gap: 0; text-shadow: none; }

/* ---------- 应用外壳 ---------- */
#appLayer { position: absolute; inset: 0; pointer-events: none; }
.app {
  background: var(--sys-bg); pointer-events: auto; overflow: hidden;
  transform: scale(.4); opacity: 0; visibility: hidden; transform-origin: var(--ox, 50%) var(--oy, 50%);
  transition: transform .38s cubic-bezier(.2,.8,.2,1), opacity .25s, visibility 0s .38s;
}
.app.open { transform: none; opacity: 1; visibility: visible; transition-delay: 0s; }
.view {
  position: absolute; inset: 0; background: var(--sys-bg); display: flex; flex-direction: column;
  transition: transform .32s cubic-bezier(.2,.8,.2,1);
}
.view.right { transform: translateX(100%); }
.view.behind { transform: translateX(-28%); }
.navbar {
  flex: none; padding: var(--sat) 8px 0; min-height: calc(var(--sat) + 48px); display: flex; align-items: center;
  background: rgba(249,249,251,.94); border-bottom: .5px solid var(--sep); gap: 4px;
}
.navbar h1 { margin: 0; flex: 1; text-align: center; font-size: 17px; font-weight: 600; }
.nav-btn { min-width: 44px; height: 44px; display: grid; place-items: center; color: var(--blue); font-size: 17px; }
.nav-btn svg { width: 22px; height: 22px; }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; user-select: text; }
.scroll::-webkit-scrollbar { width: 0; }

/* ---------- Telegram：聊天列表 ---------- */
.tg-list { background: #fff; }
.chat-row { display: flex; gap: 12px; padding: 9px 14px; align-items: center; width: 100%; text-align: left; position: relative; }
.chat-row:active { background: #e8e8ed; }
.chat-row .body { flex: 1; min-width: 0; padding-bottom: 9px; border-bottom: .5px solid var(--sep); margin-bottom: -9px; padding-top: 2px; }
.chat-row .top { display: flex; justify-content: space-between; gap: 8px; }
.chat-row .name { font-weight: 600; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .time { color: #8e8e93; font-size: 13.5px; flex: none; }
.chat-row .preview { color: #8e8e93; font-size: 15px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 600; font-size: 22px; background-size: cover; background-position: center;
}
.avatar.sm { width: 38px; height: 38px; font-size: 16px; }
.empty { padding: 48px 28px; text-align: center; color: #8e8e93; line-height: 1.7; font-size: 15px; }

/* ---------- Telegram：聊天页 ---------- */
.chat-view { background: #d6e6c9; }
.chat-view::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(90% 60% at 10% 0%, #e7efc4 0%, transparent 60%),
    radial-gradient(90% 60% at 100% 40%, #bfe0d2 0%, transparent 60%),
    radial-gradient(90% 60% at 0% 100%, #c9d9f0 0%, transparent 60%), #d6e6c9;
}
.chat-view > * { position: relative; z-index: 1; }
.chat-nav { gap: 2px; }
.chat-nav .who { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.chat-nav .who b { font-size: 16.5px; font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-nav .who small { font-size: 12.5px; color: #8e8e93; }
.chat-nav .who small.typing { color: var(--blue); }
.msgs { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; margin: 10px 0 6px; padding: 3px 11px; font-size: 12.5px; font-weight: 500; color: #fff; background: rgba(60,80,60,.35); border-radius: 12px; }
.bub {
  position: relative; max-width: 78%; padding: 6px 10px 6px 11px; border-radius: 17px; line-height: 1.38; font-size: 16px;
  white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.1); user-select: text;
}
.bub.in { align-self: flex-start; background: var(--tg-bubble-in); border-bottom-left-radius: 5px; }
.bub.out { align-self: flex-end; background: var(--tg-bubble-out); border-bottom-right-radius: 5px; }
.bub.in.cont { border-top-left-radius: 5px; }
.bub.out.cont { border-top-right-radius: 5px; }
.bub.gap { margin-top: 7px; }
.bub .t { float: right; margin: 7px 0 -3px 10px; font-size: 11.5px; line-height: 1; color: rgba(0,0,0,.4); }
.bub.out .t { color: #5ea65a; }
.bub.typing { padding: 12px 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: #9aa0a6; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(var(--sab) + 6px);
  background: rgba(249,249,251,.96); border-top: .5px solid var(--sep);
}
.composer .field {
  flex: 1; display: flex; background: #fff; border: .5px solid rgba(60,60,67,.25); border-radius: 19px; padding: 0 12px;
}
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; padding: 8px 0; max-height: 120px; line-height: 21px; font-size: 16px;
  user-select: text;
}
.send {
  flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center;
  transition: opacity .15s, transform .15s;
}
.send:disabled { opacity: .35; transform: scale(.9); }
.send svg { width: 18px; height: 18px; }

/* ---------- iOS 设置风格 ---------- */
.group { margin: 22px 16px 0; background: #fff; border-radius: 12px; overflow: hidden; }
.group-title { margin: 22px 32px -14px; font-size: 13px; color: #6d6d72; }
.group-foot { margin: 8px 32px 0; font-size: 13px; color: #6d6d72; line-height: 1.45; }
.cell { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 48px; text-align: left; position: relative; }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.cell:active { background: #e8e8ed; }
.cell .grow { flex: 1; min-width: 0; }
.cell .sub { color: #8e8e93; font-size: 15px; }
.cell .chev { color: #c4c4c7; font-size: 20px; }
.cell.danger { color: #ff3b30; }
.field-row { display: flex; flex-direction: column; gap: 6px; padding: 11px 16px; position: relative; }
.field-row + .field-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.field-row label { font-size: 13px; color: #6d6d72; }
.field-row input, .field-row textarea {
  border: 0; outline: 0; background: transparent; font-size: 16px; width: 100%; resize: none; padding: 0; user-select: text;
}
.field-row textarea { min-height: 150px; line-height: 1.45; }
.avatar-edit { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 0 6px; }
.avatar-edit .avatar { width: 88px; height: 88px; font-size: 36px; }
.avatar-edit button { color: var(--blue); font-size: 15px; }
.pad-bottom { height: calc(var(--sab) + 40px); flex: none; }

/* ---------- 占位应用 ---------- */
.soon { flex: 1; display: grid; place-items: center; text-align: center; color: #8e8e93; padding: 30px; line-height: 1.8; }
.soon b { display: block; font-size: 22px; color: #1c1c1e; margin-bottom: 6px; }

/* ---------- 锁屏 ---------- */
#lock {
  position: absolute; inset: 0; z-index: 80; color: #fff; text-align: center; padding-top: calc(var(--sat) + 40px);
  background:
    radial-gradient(120% 80% at 15% 10%, #6d8cff 0%, transparent 55%),
    radial-gradient(100% 70% at 90% 30%, #c77dff 0%, transparent 55%),
    radial-gradient(120% 90% at 40% 100%, #ff8fa3 0%, transparent 60%), #2b2f77;
}
#lock[hidden] { display: none; }
.lock-time { font-size: 86px; font-weight: 600; letter-spacing: -2px; line-height: 1; margin-top: 30px; }
.lock-date { font-size: 20px; margin-top: 8px; opacity: .9; }
.lock-form { position: absolute; left: 36px; right: 36px; bottom: calc(var(--sab) + 70px); display: flex; flex-direction: column; gap: 12px; }
.lock-hint { font-size: 14px; opacity: .85; }
.lock-form input {
  border: 0; outline: 0; padding: 13px 16px; border-radius: 14px; text-align: center; font-size: 17px;
  background: rgba(255,255,255,.25); color: #fff; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); user-select: text;
}
.lock-form input::placeholder { color: rgba(255,255,255,.7); }
.lock-form button { padding: 13px; border-radius: 14px; background: #fff; color: #2b2f77; font-weight: 600; font-size: 16px; }
.lock-err { min-height: 18px; font-size: 13px; color: #ffd3d3; }
