/* ==========================================================================
   直播取流 — 视觉：票据 / 仪表
   暗色是主场景（iPhone OLED 默认），亮色做成暖白「纸质票据」。
   字体只用系统栈：CJK 网络字体动辄数 MB，与 2Mbps 带宽 + 无外部 CDN 冲突。
   层次靠字重、字距、大小写与等宽数字，不靠字体本身。
   ========================================================================== */

:root {
  color-scheme: light dark;

  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
             "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --bg:        #F7F5F1;
  --surface:   #FFFFFF;
  --surface-2: #F2EFE9;
  --line:      #E4DED3;
  --line-2:    #D2CABB;
  --ink:       #17150F;
  --ink-2:     #4A4438;
  --ink-3:     #776F60;
  /* 拆成两个令牌：文字/边框用的 accent 要压暗才在浅底上达标，
     按钮底色用的 accent-solid 反而要亮才好看——两者对对比度的要求正好相反。 */
  --accent:              #9A5400;
  --accent-solid:        #F0A02A;
  --accent-solid-hover:  #E59420;
  --on-accent:           #2A1A00;
  --accent-bg:           #FBF1DF;
  --ok:        #146B4A;
  --err:       #A3231A;
  --glow-a:    rgba(168, 95, 0, .10);
  --glow-b:    rgba(23, 21, 15, .05);
  --shadow:    0 1px 2px rgba(23,21,15,.05), 0 10px 30px -14px rgba(23,21,15,.22);
  --shadow-lg: 0 2px 4px rgba(23,21,15,.06), 0 24px 60px -24px rgba(23,21,15,.30);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --pad: 20px;
  --ease: cubic-bezier(.22,.7,.28,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0C0E12;
    --surface:   #14181E;
    --surface-2: #1A1F27;
    --line:      #242A33;
    --line-2:    #333C48;
    --ink:       #E9EDF3;
    --ink-2:     #A9B2BF;
    --ink-3:     #7A8494;
    --accent:             #FFB020;
    --accent-solid:       #FFB020;
    --accent-solid-hover: #FFC960;
    --on-accent:          #1B1204;
    --accent-bg:          #2A2113;
    --ok:        #45D89B;
    --err:       #FF6F63;
    --glow-a:    rgba(255, 176, 32, .13);
    --glow-b:    rgba(90, 130, 255, .07);
    --shadow:    0 1px 2px rgba(0,0,0,.55), 0 12px 34px -16px rgba(0,0,0,.75);
    --shadow-lg: 0 2px 6px rgba(0,0,0,.6), 0 30px 70px -28px rgba(0,0,0,.85);
  }
}

* { box-sizing: border-box; }

/* `hidden` 属性的 display:none 来自浏览器默认样式，**任何作者样式里的 display 都会盖掉它**。
   后台面板是 display:flex，实测四个标签页会全部同时显示。这条兜底防住整类问题。 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* 氛围：两层柔和光晕 + 细颗粒，避免大片纯色显得廉价 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(115% 70% at 50% -12%, var(--glow-a), transparent 62%),
    radial-gradient(90% 60% at 108% 108%, var(--glow-b), transparent 60%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .35;
  background-image:
    repeating-linear-gradient(0deg, var(--glow-b) 0 1px, transparent 1px 3px);
  mask-image: radial-gradient(120% 90% at 50% 0%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(120% 90% at 50% 0%, #000 0%, transparent 75%);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 视图切换 ---------- */

.view { display: none; }
.view--active { display: block; }

.boot {
  display: none;
  place-items: center;
  min-height: 100svh;
}
.boot.view--active { display: grid; }

.boot__dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--glow-a);
  animation: pulse 1.4s var(--ease) infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--glow-a); opacity: 1; }
  70%  { box-shadow: 0 0 0 22px transparent; opacity: .5; }
  100% { box-shadow: 0 0 0 0 transparent; opacity: 1; }
}

/* ---------- 登录页 ---------- */

.login {
  display: flex;
  flex-direction: column;
  gap: 32px;
  justify-content: center;
  min-height: 100svh;
  padding: calc(env(safe-area-inset-top) + 40px) var(--pad)
           calc(env(safe-area-inset-bottom) + 40px);
  max-width: 460px;
  margin: 0 auto;
}

.brand { text-align: center; animation: rise .5s var(--ease) both; }

.brand__mark {
  position: relative;
  display: inline-block;
  width: 46px; height: 46px;
  border-radius: 15px;
  background: var(--ink);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.brand__mark::before {
  content: "";
  position: absolute; left: 12px; top: 12px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  transform: rotate(-38deg);
}
.brand__mark::after {
  content: "";
  position: absolute; left: 19px; top: 19px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}

.brand__name {
  margin: 0;
  font-size: 25px;
  font-weight: 650;
  letter-spacing: .16em;
  text-indent: .16em;
}

.brand__desc {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--ink-3);
  letter-spacing: .01em;
}

.keycard {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px var(--pad) 20px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise .5s var(--ease) .08s both;
}

.keycard__label {
  font-size: 11px;
  font-weight: 640;
  letter-spacing: .2em;
  text-indent: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: center;
}

.keycard__input {
  width: 100%;
  padding: 15px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .1em;
  text-align: center;
  text-transform: uppercase;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.keycard__input::placeholder {
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: .1em;
  opacity: .55;
}
.keycard__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-bg);
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0; padding: 0;
  list-style: none;
  color: var(--ink-3);
  font-size: 13.5px;
  animation: rise .5s var(--ease) .16s both;
}
.steps li { display: flex; align-items: center; gap: 11px; }
.steps__n {
  display: grid; place-items: center;
  flex: 0 0 21px; height: 21px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

/* ---------- 顶部状态条 ---------- */

.statusbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--bg); /* 老 Safari 兜底；支持 color-mix 的走下一行 */
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.statusbar__inner {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 640px;
  margin: 0 auto;
  padding: 11px var(--pad);
}

.stat { display: flex; align-items: baseline; gap: 5px; min-width: 0; }
.stat--dim { margin-left: auto; }

.stat__label {
  font-size: 10.5px;
  font-weight: 640;
  letter-spacing: .16em;
  color: var(--ink-3);
}
.stat__value {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.stat__value--sm { font-size: 12.5px; font-weight: 560; color: var(--ink-2); }

.statusbar__progress {
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity .2s var(--ease);
}
.statusbar__progress.is-on {
  opacity: 1;
  animation: sweep 1.1s linear infinite;
}
@keyframes sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ---------- 主区 ---------- */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 22px var(--pad) calc(env(safe-area-inset-bottom) + 56px);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.resolver { display: flex; flex-direction: column; gap: 12px; }

.field { position: relative; }

.field__input {
  display: block;
  width: 100%;
  padding: 15px 42px 15px 16px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px; /* iOS 下 <16px 会触发聚焦自动放大 */
  line-height: 1.55;
  resize: none;
  min-height: 92px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.field__input::placeholder { color: var(--ink-3); opacity: .8; }
.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-bg);
}

.field__clear {
  position: absolute;
  top: 9px; right: 9px;
  width: 28px; height: 28px;
  border: 0; border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 17px; line-height: 1;
  cursor: pointer;
}
.field__clear:hover { color: var(--ink); }

/* ---------- 按钮 ---------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: .06em;
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s var(--ease), background-color .18s var(--ease),
              border-color .18s var(--ease), color .18s var(--ease);
  -webkit-user-select: none; user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 2px; }
.btn:disabled { cursor: default; opacity: .6; }

.btn--primary {
  background: var(--accent-solid);
  color: var(--on-accent);
  box-shadow: var(--shadow);
}
.btn--primary:hover:not(:disabled) { background: var(--accent-solid-hover); }

.btn--lg { min-height: 54px; padding: 0 22px; }

.btn--sm {
  flex: 0 0 auto;
  padding: 7px 13px;
  font-size: 12.5px;
  letter-spacing: .08em;
  border-radius: var(--r-sm);
  /* 不加会被窄容器挤成竖排（请求头行里的「复制」实测踩到） */
  white-space: nowrap;
}

.btn--ghost {
  background: transparent;
  border-color: var(--line-2);
  color: var(--ink-2);
}
.btn--ghost:hover { border-color: var(--ink-3); color: var(--ink); }

.btn--action .btn__spinner {
  display: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin .7s linear infinite;
}
.btn--action.is-busy .btn__spinner { display: block; }
.btn--action.is-busy .btn__label { opacity: .82; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 结果票据 ---------- */

.result { display: flex; flex-direction: column; gap: 14px; }

.ticket {
  position: relative;
  padding: 20px var(--pad) 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: rise .34s var(--ease) both;
}
.ticket::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent 78%);
}

.ticket__head {
  display: flex;
  align-items: center;
  gap: 10px;
  animation: rise .34s var(--ease) .03s both;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 660;
  letter-spacing: .07em;
}
.chip::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

.ticket__quality {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--ink-3);
}

.ticket__anchor {
  margin: 12px 0 0;
  font-size: 19px;
  font-weight: 660;
  letter-spacing: .01em;
  animation: rise .34s var(--ease) .06s both;
}

.ticket__title {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--ink-2);
  animation: rise .34s var(--ease) .08s both;
}
.ticket__title:empty { display: none; margin: 0; }

/* 票根：流地址 */
.stub {
  position: relative;
  margin: 16px 0;
  padding: 13px 15px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-2);
  animation: rise .34s var(--ease) .1s both;
}
.stub__label {
  margin-bottom: 7px;
  font-size: 10.5px;
  font-weight: 640;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.stub__url {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink);
  word-break: break-all;
  max-height: 5.1em;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.btn--copy {
  width: 100%;
  min-height: 56px;
  font-size: 16px;
  letter-spacing: .1em;
  animation: rise .34s var(--ease) .12s both;
}
.btn--copy .btn__check { display: none; }
.btn--copy .btn__check::after {
  content: "";
  display: block;
  width: 14px; height: 8px;
  border-left: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: rotate(-45deg) translateY(-1px);
  animation: pop .3s var(--ease) both;
}
.btn--copy.is-copied { background: var(--ok); color: var(--bg); }
.btn--copy.is-copied .btn__check { display: block; }
.btn--copy.is-copied::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  animation: sweep-once .6s var(--ease);
}
@keyframes sweep-once {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}
@keyframes pop {
  from { opacity: 0; transform: rotate(-45deg) scale(.5); }
  to   { opacity: 1; transform: rotate(-45deg) scale(1); }
}

/* ---------- 历史 ---------- */

.history__title {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 640;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.history__list {
  display: flex;
  flex-direction: column;
  margin: 0; padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}

.history__item + .history__item { border-top: 1px solid var(--line); }

.history__btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color .15s var(--ease);
}
.history__btn:hover { background: var(--surface-2); }
.history__btn:active { background: var(--surface-2); }
.history__btn:disabled { opacity: .55; cursor: default; }

.history__dot {
  flex: 0 0 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3);
}
.history__dot--ok { background: var(--ok); }
.history__dot--fail { background: var(--err); }

.history__main { flex: 1 1 auto; min-width: 0; }
.history__anchor {
  display: block;
  font-size: 14px;
  font-weight: 560;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history__meta {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

.history__redo {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: .04em;
}

/* ---------- 提示消息 ---------- */

.msg {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--err);
  min-height: 0;
}
.msg:empty { display: none; }

.msg--inline {
  padding: 10px 13px;
  border: 1px solid var(--err);
  border-radius: var(--r-sm);
  background: var(--surface);
  animation: rise .3s var(--ease) both;
}

/* ---------- 动效 ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (min-width: 560px) {
  :root { --pad: 26px; }
  .brand__name { font-size: 28px; }
  .keycard__input { font-size: 21px; }
}
