:root {
  --pink: #f08cb4;
  --pink-deep: #e2679a;
  --cream: #fff7f1;
  --ink: #3a2a36;
  --red: #ec5a56;
  --green: #3fbf6b;
  --glass: rgba(40, 26, 38, 0.55);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: linear-gradient(135deg, #f2d5e1 0%, #d8c7e6 55%, #c6d9e8 100%);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #ffd5e8; outline-offset: 3px; }

.phone {
  position: relative;
  width: 100%;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  overflow: clip;
  background: #765563;
}

@media (min-width: 600px) {
  .phone {
    width: 400px;
    height: min(860px, calc(100dvh - 48px));
    margin-top: max(24px, calc((100dvh - 860px) / 2));
    border-radius: 48px;
    border: 6px solid transparent;
    background: linear-gradient(#765563, #765563) padding-box,
      linear-gradient(145deg, #fff7f8 0%, #d6c2cf 28%, #b7a9c2 50%, #f2dce6 77%, #fff6f1 100%) border-box;
    box-shadow: 0 24px 64px rgba(111, 76, 111, 0.24), 0 0 0 1px rgba(255, 250, 253, 0.65);
  }
}

.ambient {
  position: absolute;
  inset: -30px;
  background: #3b2735 center / cover no-repeat;
  filter: blur(14px) brightness(0.62) saturate(1.15);
  transition: background-image 0.6s ease;
}

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.screen.active { opacity: 1; pointer-events: auto; }

/* ---------- 来电 ---------- */

.ring-screen { background: linear-gradient(160deg, #89666b 0%, #765565 52%, #654c5b 100%); }

.ring-music {
  position: absolute;
  top: calc(var(--safe-top) + 18px);
  right: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 239, 248, 0.32);
  border-radius: 999px;
  background: rgba(255, 236, 245, 0.13);
  backdrop-filter: blur(10px);
  font-size: 12px;
}

.ring-music svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ring-music.playing { background: rgba(255, 228, 242, 0.24); }
.ring-music-hint {
  position: absolute;
  top: calc(var(--safe-top) + 134px);
  left: 28px;
  right: 28px;
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 247, 251, 0.9);
}

.ring-video {
  position: absolute;
  left: 0;
  right: 0;
  top: 20%;
  width: 100%;
  height: 62%;
  object-fit: cover;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 12%, #000 78%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 12%, #000 78%, transparent 100%);
}

.caller {
  position: absolute;
  top: calc(var(--safe-top) + 56px);
  left: 28px;
  right: 28px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.caller-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  image-rendering: pixelated;
}

.caller h1 { margin: 0; font-size: 26px; letter-spacing: 0.5px; }
.caller-sub { margin: 4px 0 0; font-size: 16px; opacity: 0.85; }

.dots::after {
  content: "";
  animation: dots 1.4s steps(4) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.config-warning {
  position: absolute;
  top: calc(var(--safe-top) + 140px);
  left: 24px;
  right: 24px;
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(236, 90, 86, 0.9);
  font-size: 13px;
  line-height: 1.5;
}

.config-warning code { background: rgba(0, 0, 0, 0.2); padding: 0 4px; border-radius: 4px; }

.ring-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 56px);
  display: flex;
  justify-content: space-around;
}

.round-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}

.round-btn svg {
  width: 72px;
  height: 72px;
  padding: 20px;
  border-radius: 50%;
  fill: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
}

.round-btn.decline svg { background: var(--red); transform: rotate(0deg); }
.round-btn.accept svg { background: var(--green); }
.ring-screen .round-btn.accept svg { animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 191, 107, 0.6); }
  60% { box-shadow: 0 0 0 18px rgba(63, 191, 107, 0); }
}

/* ---------- 通话 ---------- */

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.call-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  transform-origin: 50% 70%;
}

.stage.speaking .call-video { animation: talk 0.9s ease-in-out infinite; }

@keyframes talk {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.012) translateY(-2px); }
}

.call-top {
  position: absolute;
  top: calc(var(--safe-top) + 18px);
  left: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.timer, .location {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
}

.location { font-size: 12px; font-weight: 500; }
.location::before { content: "📍 "; }

.pip {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  right: 14px;
  width: 30%;
  aspect-ratio: 3 / 4;
  padding: 0;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  overflow: hidden;
  background: linear-gradient(160deg, #7a9a5a, #4c6b3c);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.pip video { display: block; width: 100%; height: 100%; object-fit: cover; }
.pip .pip-avatar { image-rendering: pixelated; }
.pip #selfVideo { display: none; transform: scaleX(-1); }
.pip.rear #selfVideo { transform: none; }
.pip.live .pip-avatar { display: none; }
.pip.live #selfVideo { display: block; }

.dialogue {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(var(--safe-bottom) + 128px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.state-line {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  font-size: 13px;
}

.state-line i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #bbb;
}

.state-line.listening i { background: var(--green); }
.state-line.recording i { background: var(--red); animation: blink 0.8s infinite; }
.state-line.thinking i { background: #f5c451; animation: blink 0.6s infinite; }
.state-line.speaking i { background: var(--pink); animation: blink 0.9s infinite; }

@keyframes blink { 50% { opacity: 0.3; } }

.user-line {
  align-self: flex-end;
  max-width: 80%;
  margin: 0;
  padding: 7px 12px;
  border-radius: 14px 14px 4px 14px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  font-size: 14px;
}

.bubble {
  position: relative;
  padding: 18px 16px 12px;
  border-radius: 18px;
  background: rgba(255, 247, 241, 0.94);
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.bubble p { margin: 0; font-size: 15px; line-height: 1.6; min-height: 1.6em; white-space: pre-wrap; }

.name-tag {
  position: absolute;
  top: -12px;
  left: 12px;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.text-input {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(var(--safe-bottom) + 112px);
  display: flex;
  gap: 8px;
}

.text-input:not([hidden]) ~ .controls { bottom: calc(var(--safe-bottom) + 14px); }
.call-screen.typing .dialogue { bottom: calc(var(--safe-bottom) + 170px); }

.text-input input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font: inherit;
  outline: none;
}

.text-input button {
  padding: 0 16px;
  border-radius: 999px;
  background: var(--pink-deep);
  font-weight: 600;
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 18px);
  display: flex;
  justify-content: space-around;
  padding: 0 10px;
}

.ctrl { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; }
.ctrl:disabled { opacity: 0.5; cursor: default; }

.ctrl-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(10px);
  transition: background 0.2s;
}

.ctrl-icon svg { width: 26px; height: 26px; fill: #fff; }
.ctrl-icon .lens { fill: #4a3445; }
.ctrl.active .ctrl-icon { background: #fff; }
.ctrl.active .ctrl-icon svg { fill: var(--ink); }
.ctrl.active .ctrl-icon .lens { fill: #fff; }
.ctrl.hangup .ctrl-icon { background: var(--red); }

.sheet {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(var(--safe-bottom) + 10px);
  max-height: min(78dvh, 680px);
  overflow: auto;
  padding: 16px;
  border-radius: 24px;
  background: rgba(45, 30, 42, 0.88);
  backdrop-filter: blur(16px);
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.35);
  animation: rise 0.25s ease;
}

@keyframes rise { from { transform: translateY(30px); opacity: 0; } }

.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-close { width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }

.scene-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.scene {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid transparent;
  text-align: center;
  font-size: 13px;
}

.scene img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.scene span { display: block; padding: 5px 0; background: rgba(0, 0, 0, 0.35); }
.scene.selected { border-color: var(--pink); }

.scene.selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--pink);
  font-weight: 700;
}

.recent-history { margin-top:14px; }
.recent-history h3 { margin:0 0 8px; font-size:13px; }
.history-empty { margin:0; color:#e3cbd8; font-size:12px; }
.history-list { display:flex; flex-direction:column; gap:0; max-height:min(32dvh, 240px); overflow:auto; margin:0; padding:0; list-style:none; overscroll-behavior:contain; }
.history-list li { display:grid; grid-template-columns:40px minmax(0,1fr); gap:8px; padding:8px 0; border-top:1px solid rgba(255,255,255,.14); }
.history-list li:first-child { border-top:0; }
.history-speaker { color:#f5b7d3; font-size:12px; }
.history-list li[data-role="user"] .history-speaker { color:#b5e1d3; }
.history-list p { min-width:0; margin:0; color:#fff7fb; font-size:12px; line-height:1.55; overflow-wrap:anywhere; white-space:pre-wrap; }

.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }

.sheet-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 14px;
}

/* ---------- 结束 ---------- */

.ended-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(30, 20, 28, 0.55);
}

.ended-avatar { width: 96px; height: 96px; border-radius: 50%; border: 3px solid #fff; image-rendering: pixelated; }
.ended-screen h2 { margin: 12px 0 0; font-size: 22px; }
.ended-screen p { margin: 0 0 40px; opacity: 0.8; }

.toast {
  position: absolute;
  top: calc(var(--safe-top) + 70px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 86%;
  padding: 9px 16px;
  border-radius: 14px;
  background: rgba(20, 12, 18, 0.88);
  font-size: 13px;
  line-height: 1.5;
  z-index: 10;
}

[hidden] { display: none !important; }

.game-preview { position:absolute; bottom:calc(var(--safe-bottom) + 176px); left:22px; right:22px; padding:10px 12px; border:1px solid rgba(255,239,248,.22); border-radius:14px; background:rgba(40,26,38,.56); backdrop-filter:blur(10px); }
.game-preview p { margin:0; font-size:12px; line-height:1.6; overflow-wrap:anywhere; }
.game-preview p + p { margin-top:4px; color:#f8dbe9; }
.game-preview button { min-height:36px; margin-top:6px; padding:6px 10px; border-radius:10px; background:rgba(255,255,255,.15); font-size:12px; }
.connection-panel { position:absolute; inset:calc(var(--safe-top) + 8px) 8px calc(var(--safe-bottom) + 8px); z-index:20; overflow:auto; padding:20px; border:1px solid rgba(255,255,255,.18); border-radius:26px; background:rgba(51,34,47,.97); box-shadow:0 16px 48px rgba(20,12,18,.45); overscroll-behavior:contain; scrollbar-width:thin; }
.connection-panel .sheet-head { position:sticky; top:-20px; z-index:1; padding:12px 0; background:#33222f; }
.connection-panel .sheet-close { flex-shrink:0; width:36px; height:36px; }
.mode-notice { margin:0 0 18px; padding:12px; border-radius:14px; background:rgba(240,140,180,.15); font-size:13px; line-height:1.7; overflow-wrap:anywhere; }
.connection-form { display:flex; flex-direction:column; gap:9px; margin:0 0 18px; }
.connection-form label { font-size:13px; font-weight:600; }
.connection-form input, .connection-form select { width:100%; min-width:0; min-height:44px; padding:10px 12px; border:1px solid #c8b3c1; border-radius:12px; background:var(--cream); color:var(--ink); font:inherit; font-size:16px; }
.primary-action { min-height:44px; margin-top:5px; padding:11px; border-radius:12px; background:#b63f72; font-weight:600; }
.form-hint { margin:0 0 10px; font-size:13px; line-height:1.7; color:#f7deec; }
.account-controls { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:16px; font-size:13px; }
.account-controls p { margin:0; overflow-wrap:anywhere; }
.account-controls button { flex-shrink:0; min-height:40px; padding:7px 12px; border-radius:10px; background:rgba(255,255,255,.14); }
.world-details { padding:14px; margin:0 0 16px; border:1px solid rgba(255,239,248,.22); border-radius:16px; }
.world-details h3 { margin:0 0 7px; font-size:14px; }
.game-identity { margin:0 0 12px; color:#f7deec; font-size:12px; line-height:1.6; overflow-wrap:anywhere; }
.world-details dl { display:grid; grid-template-columns:64px minmax(0,1fr); gap:10px; margin:0; font-size:13px; line-height:1.6; }
.world-details dt { color:#edc9dc; }
.world-details dd { margin:0; overflow-wrap:anywhere; }
.world-freshness { margin:14px 0 0; padding-top:10px; border-top:1px solid rgba(255,239,248,.2); color:#ffe0ab; font-size:12px; line-height:1.6; }
.refresh-worlds { width:100%; min-height:44px; padding:10px; border:1px solid rgba(255,239,248,.35); border-radius:12px; font-size:14px; }
.connection-message { margin:12px 0 0; color:#f7deec; font-size:13px; line-height:1.7; overflow-wrap:anywhere; }
.connection-message[data-error="true"] { color:#ffbfba; }
.round-btn.text-answer svg { background:#b63f72; }
.call-top { top:calc(var(--safe-top) + 62px); max-width:calc(70% - 30px); }
.location { font-size:12px; font-weight:500; line-height:1.5; overflow-wrap:anywhere; }
.call-world-status { padding:6px 10px; border-radius:12px; background:var(--glass); font-size:12px; line-height:1.6; overflow-wrap:anywhere; }
.pip { top:calc(var(--safe-top) + 62px); }
.bubble p { max-height:26dvh; overflow-y:auto; overflow-wrap:anywhere; }
.scene-hint { margin:0 0 12px; color:#f7deec; font-size:12px; line-height:1.6; }
.text-redial { min-height:44px; margin-top:16px; padding:10px 16px; border:1px solid rgba(255,239,248,.35); border-radius:999px; background:var(--glass); font-size:13px; }
@media (max-height:650px) { .ring-actions { bottom:calc(var(--safe-bottom) + 24px); } .game-preview { bottom:calc(var(--safe-bottom) + 142px); } .caller { top:calc(var(--safe-top) + 60px); } }

.native-app .phone {
  width: 100%;
  height: 100dvh;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.connection-open {
  position: absolute;
  top: calc(var(--safe-top) + 18px);
  left: 20px;
  z-index: 2;
  padding: 7px 11px;
  border: 1px solid rgba(255, 239, 248, 0.32);
  border-radius: 999px;
  background: rgba(40, 26, 38, 0.3);
  font-size: 12px;
}

.connection-dialog {
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 24px;
  border: 1px solid #ead7e2;
  border-radius: 24px;
  background: #fff7f9;
  color: var(--ink);
  box-shadow: 0 20px 70px #3a2a3650;
}

.connection-dialog::backdrop { background: #20121c99; backdrop-filter: blur(6px); }
.connection-dialog .sheet-close { background: #3a2a3610; }
.connection-dialog p, .connection-dialog small { font-size: 13px; line-height: 1.65; }
.connection-dialog label { display: block; margin: 20px 0 8px; font-size: 14px; font-weight: 600; }
.connection-dialog input { width: 100%; padding: 12px; border: 1px solid #d8bfce; border-radius: 10px; font: inherit; font-size: 16px; color: var(--ink); background: #fff; }
.connection-dialog input:focus { outline: 2px solid var(--pink-deep); outline-offset: 2px; }
.connection-dialog small { display: block; margin-top: 8px; color: #796370; }
.connection-status { color: #a73051; overflow-wrap: anywhere; }
.connection-status:empty { display: none; }
.connection-save { width: 100%; margin-top: 20px; padding: 13px; border-radius: 12px; background: #a8406b; color: #fff; font-weight: 600; }
.connection-save:disabled { opacity: 0.6; cursor: wait; }
