/* 通话界面基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    font-family: -apple-system, "SF Pro Display", "PingFang SC", sans-serif;
}

:root { --statusbar-h: 44px; }

.call-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background: #000;
    color: white;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* 状态栏 - 仿iOS样式 */
.status-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    z-index: 100;
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
}

.status-bar-time {
    font-size: 12px;
    font-weight: 600;
}

.status-bar-icons {
    display: flex;
    gap: 4px;
    align-items: center;
}

.signal-icon {
    display: inline-block;
    width: 16px;
    height: 10px;
    position: relative;
}

.signal-icon::before {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 3px;
    height: 100%;
    background: white;
    border-radius: 1px;
}

.signal-icon::after {
    content: '';
    position: absolute;
    left: 5px;
    bottom: 2px;
    width: 3px;
    height: 8px;
    background: white;
    border-radius: 1px;
}

.signal-icon span {
    position: absolute;
    left: 10px;
    bottom: 4px;
    width: 3px;
    height: 6px;
    background: rgba(255,255,255,0.6);
    border-radius: 1px;
}

.wifi-icon {
    display: inline-block;
    width: 14px;
    height: 10px;
    position: relative;
}

.wifi-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    width: 10px;
    height: 10px;
    border: 1px solid white;
    border-radius: 50%;
}

.battery-icon {
    display: inline-block;
    width: 18px;
    height: 9px;
    border: 1px solid white;
    border-radius: 2px;
    position: relative;
    margin-left: 2px;
}

.battery-icon::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    bottom: 1px;
    width: 12px;
    background: white;
    border-radius: 1px;
}

/* 刘海区域 */
.notch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 20px;
    background: #000;
    border-radius: 0 0 10px 10px;
    z-index: 101;
}

/* 屏幕容器 */
/* 三个屏幕绝对定位叠在一起。
   不能用 height:100% 当 flex 子项 —— 三个屏幕会互相挤压，高度塌成 0。 */
.screen {
    position: absolute;
    top: var(--statusbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    visibility: visible;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0s;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    /* 光靠 opacity:0 不够 —— 隐藏屏上的 backdrop-filter 仍会渲染，
       在手机外框里会露出一道可见的边。visibility 延到淡出结束再生效，
       这样过渡动画不受影响。 */
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s linear 0.3s;
}

/* 来电界面样式 */
.screen-incoming {
    background: linear-gradient(135deg, #1a1a1a 0%, #0d0d0d 100%);
    /* 不要在这里写 position:relative —— 会覆盖 .screen 的 absolute，
       屏幕高度就塌了。定位统一由 .screen 负责。 */
    overflow: hidden;
}

.screen-incoming::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, transparent 30%, rgba(0,0,0,0.8) 100%);
    /* 去掉 backdrop-filter：底下是近乎纯黑的背景，模糊没有任何视觉效果，
       却会额外起一个合成层，在手机外框里露出一道边。 */
    z-index: 1;
}

.incoming-content {
    position: relative;
    z-index: 2;
    text-align: center;
    margin-top: 100px;
    /* 必须占满宽度：父级 align-items:center 会把它收缩成内容宽，
       里面用 left:0/right:0 绝对定位的按钮排就跟着塌了。 */
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    color: white;
    border: 3px solid rgba(255,255,255,0.2);
}

.caller-name {
    font-size: 34px;
    font-weight: 300;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.caller-subtitle {
    font-size: 17px;
    color: rgba(255,255,255,0.6);
    font-weight: 400;
}

.action-buttons {
    position: absolute;
    bottom: 80px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 60px;
}

.action-button {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.1s ease;
    border: none;
    outline: none;
    position: relative;
}

.action-button:active {
    transform: scale(0.92);
    transition: all 0.1s ease;
}

.decline-button {
    background: #FF3B30;
}

.accept-button {
    background: #34C759;
    animation: breath 2s infinite ease-in-out;
}

@keyframes breath {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.action-button svg {
    width: 32px;
    height: 32px;
    fill: white;
}

/* 通话界面样式 */
.screen-active {
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
}

.active-header {
    text-align: center;
    margin-top: 50px;
}

.contact-name {
    font-size: 34px;
    font-weight: 300;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.timer {
    font-size: 17px;
    color: rgba(255,255,255,0.6);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 20px;
    margin: 40px 0;
    max-width: 300px;
}

.control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-button {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.1s ease;
    border: none;
    outline: none;
}

.control-button:active {
    transform: scale(0.92);
    transition: all 0.1s ease;
}

.control-button.active {
    background: white;
}

.control-button.active svg {
    fill: #000;
}

.control-label {
    font-size: 12px;
    color: rgba(255,255,255,0.8);
    font-weight: 500;
}

.control-button svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.end-call-button {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #FF3B30;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.1s ease;
    border: none;
    outline: none;
    margin-bottom: 30px;
}

.end-call-button:active {
    transform: scale(0.92);
    transition: all 0.1s ease;
}

.end-call-button svg {
    width: 32px;
    height: 32px;
    fill: white;
    transform: rotate(135deg);
}

/* 通话状态行：iOS 就是在计时器这个位置显示「正在呼叫…」之类。
   错误提示也走这里，不再单独开字幕区。 */
.call-status {
    margin-top: 6px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.55);
    min-height: 16px;
    transition: opacity 0.2s ease;
}


/* 挂断动画 */
.end-call-button.pressed {
    animation: endCallPress 0.1s ease;
}

@keyframes endCallPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

/* 响应式适配 */
@media (max-width: 375px) {
    .action-buttons {
        gap: 40px;
    }
    
    .controls-grid {
        gap: 15px;
    }
    
    .control-button {
        width: 68px;
        height: 68px;
    }
}

@media (max-height: 667px) {
    .incoming-content {
        margin-top: 80px;
    }
    
    .action-buttons {
        bottom: 60px;
    }
}

/* 隐藏滚动条 */
::-webkit-scrollbar {
    display: none;
}

/* 挂断/拒接的话筒要旋转 135°，这是 iOS 的做法 */
.decline-button svg,
.end-call-button svg {
    transform: rotate(135deg);
}


/* ── 首页（联系人选择），由 scripts/gen_home.py 生成 ── */

/* .screen 默认 align-items:center + space-between，那是给通话界面用的；
   首页是列表，要左对齐、从顶部开始铺 */
.screen-home {
  align-items: stretch;
  justify-content: flex-start;
  padding-top: 8px;
}
.home-title {
  font-size: 34px;
  font-weight: 700;
  color: white;
  margin: 20px 0 24px 20px;
}

.contact-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px;
}

.contact-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.contact-row:active {
  background-color: rgba(255, 255, 255, 0.1);
  transform: scale(0.99);
}

.contact-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 500;
  color: white;
  margin-right: 16px;
  flex-shrink: 0;
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-size: 17px;
  color: white;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-sub {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-call-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: #34C759;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 16px;
  flex-shrink: 0;
}

.contact-row:not(:first-child)::before {
  content: '';
  position: absolute;
  left: 88px;
  right: 0;
  top: 0;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.08);
  transform-origin: left top;
  transform: scaleY(0.5);
}

.home-hint {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  margin: 20px 0;
}


/* 去电时这一屏是「正在呼叫」，主叫方没有接听键，
   只留一个居中的挂断键 */
.screen-incoming .accept-button { display: none; }
.screen-incoming .action-buttons { gap: 0; }

/* iOS 的分隔线从头像右侧开始，不顶到最左边 */
.contact-row + .contact-row {
  border-top: 0.5px solid rgba(255, 255, 255, 0.08);
}
.contact-row { padding: 10px 0; }
.contact-call-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: #34C759; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; margin-left: 12px;
}
.contact-call-btn svg { width: 20px; height: 20px; fill: #fff; }
.home-hint { padding-bottom: 28px; }


/* 通话结束页：绿色话筒会被读成"再打一次"，这里要的是"回通讯录"，
   所以换成中性色并配文字标签 */
.back-home-label {
  margin-top: 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
}

/* ── 桌面端：包成一台手机 ──────────────────────────────────
   手机上（窄屏）保持满屏直出，不套任何外框。
   判据用视口尺寸而不是 UA：竖屏手机不会同时满足 520×680。
   平板会命中外框，那是可接受的——它本来也不是手机。            */
@media (min-width: 520px) and (min-height: 680px) {
  html, body {
    height: 100%;
    overflow: hidden;
    background:
      radial-gradient(1200px 800px at 50% -10%, #2b2b30 0%, #151517 55%, #0b0b0c 100%);
  }

  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* 覆盖掉移动端那套 fixed 满屏 */
  .call-container {
    position: relative;
    top: auto;
    left: auto;
    width: 390px;
    height: 844px;
    max-height: calc(100vh - 48px);
    border-radius: 46px;
    overflow: hidden;
    padding: 0;
    /* 用 box-shadow 叠出机身边框和投影，不用多加 DOM */
    box-shadow:
      0 0 0 11px #121214,
      0 0 0 12px #35353a,
      0 26px 60px rgba(0, 0, 0, 0.6),
      0 4px 14px rgba(0, 0, 0, 0.5);
  }

  /* 屏幕从状态栏下方开始，所以只裁下面两个角；
     上面也裁的话会在状态栏下留一道可见的弧线 */
  .screen {
    border-radius: 0 0 46px 46px;
  }

  /* 状态栏要避开圆角，不然左上角的时间会被切掉一块 */
  .status-bar {
    top: 14px;
    padding: 0 30px;
  }

  /* 刘海做成灵动岛那种胶囊，浮在状态栏之上 */
  .notch {
    top: 10px;
    width: 104px;
    height: 26px;
    border-radius: 14px;
    background: #000;
  }

  /* 屏幕内容整体下移，给状态栏让位 */
  .screen {
    top: calc(var(--statusbar-h) + 10px);
  }

  /* 内容全黑，灵动岛在上面本来就看不出来，留着反而是道多余的边 */
  .notch { display: none; }
}


/* ── 拨号键盘 ────────────────────────────────────────── */
.keypad-overlay {
  position: absolute;
  left: 0; right: 0;
  /* 下边缘必须让开挂断键（它从屏底往上约 130px 开始），
     否则遮罩会盖住按钮上沿 */
  top: 96px;
  bottom: 148px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* 必须全不透明：0.92 会让底下的六宫格透出来，两层圆按钮叠在一起很脏 */
  background: #000;
  z-index: 20;
  transition: opacity 0.2s ease;
}
.keypad-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
.keypad-display {
  min-height: 34px;
  margin-bottom: 14px;
  font-size: 28px;
  letter-spacing: 3px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 14px 24px;
}
.keypad-key {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.1s ease;
}
.keypad-key:active {
  background: rgba(255, 255, 255, 0.4);
  transform: scale(0.94);
}
.keypad-key span { font-size: 30px; font-weight: 400; line-height: 1; }
.keypad-key em {
  font-style: normal;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 3px;
}
.keypad-hide {
  margin-top: 18px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 15px;
  cursor: pointer;
}

/* 这两个在本应用里没有对应能力，做成禁用比装个假开关诚实 */
.control-item.disabled { opacity: 0.32; }
.control-item.disabled .control-button { cursor: default; }
