/* ui.css — 主题 tokens 与界面组件（纯代码绘制：运动场记分牌 + 手机通知条） */
:root {
  --c-ink: #12161c;
  --c-panel: rgba(18, 22, 28, .74);
  --c-line: rgba(255, 255, 255, .14);
  --c-text: #f3f5f7;
  --c-dim: #aab3bd;
  --c-accent: #e23b2e;
  --c-accent2: #f6c445;
  --c-ok: #3fbf7f;
  --radius: 6px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --ease: 140ms ease-out;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #0c0f13; color: var(--c-text);
  font-family: var(--yoroll-font-body, sans-serif); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
[hidden] { display: none !important; }
.layer { position: fixed; inset: 0; }
.title-font { font-family: var(--yoroll-font-title, sans-serif); font-weight: 700; }

/* ---- 按钮 ---- */
.btn { appearance: none; border: 1px solid var(--c-line); background: rgba(255, 255, 255, .04); color: var(--c-text);
  font: inherit; font-size: 16px; line-height: 1; min-height: 46px; min-width: 132px; padding: 0 20px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; white-space: nowrap;
  transition: transform var(--ease), background var(--ease), border-color var(--ease); }
.btn:hover { background: rgba(255, 255, 255, .1); }
.btn:active { transform: translateY(2px) scale(.98); }
.btn:focus-visible { outline: 2px solid var(--c-accent2); outline-offset: 2px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--c-accent); border-color: transparent; font-family: var(--yoroll-font-title, sans-serif); font-weight: 700; font-size: 18px; letter-spacing: .06em; }
.btn-primary:hover { background: #f04a3c; }
.btn-icon { min-width: 46px; width: 46px; padding: 0; }
/* 图标用代码绘制，避免特殊字符在不同字体下溢出 */
.ico-pause { display: block; width: 12px; height: 14px; border-left: 4px solid currentColor; border-right: 4px solid currentColor; box-sizing: border-box; pointer-events: none; }
.ico-close { display: block; width: 16px; height: 16px; position: relative; pointer-events: none; }
.ico-close::before, .ico-close::after { content: ''; position: absolute; left: 7px; top: -2px; width: 2px; height: 20px; background: currentColor; transform: rotate(45deg); }
.ico-close::after { transform: rotate(-45deg); }

/* ---- 面板 ---- */
.panel { background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.modal { display: flex; align-items: center; justify-content: center; background: rgba(6, 8, 10, .55); z-index: 40; padding: 16px; box-sizing: border-box; }
.modal > .panel { position: relative; width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.modal .panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--c-line); }
.modal .panel-head h2 { margin: 0; font-size: 20px; letter-spacing: .08em; }
.modal .panel-body { padding: 16px 20px; overflow: auto; line-height: 1.7; font-size: 15px; color: var(--c-text); }
.modal .panel-body h3 { margin: 12px 0 4px; font-size: 14px; color: var(--c-accent2); font-weight: 500; }
.modal .panel-body p { margin: 0 0 6px; color: var(--c-dim); }
.modal .panel-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 16px 16px; flex-wrap: wrap; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.keys dt { color: var(--c-text); white-space: nowrap; }
.keys dd { margin: 0; color: var(--c-dim); }

/* ---- 加载 ---- */
#loading { z-index: 60; background: #0c0f13; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
#loading .bar { width: min(320px, 70vw); height: 4px; background: rgba(255, 255, 255, .12); border-radius: 2px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0%; background: var(--c-accent); transition: width 200ms ease-out; }
#loading .msg { color: var(--c-dim); font-size: 14px; min-height: 20px; text-align: center; padding: 0 20px; }
#loading h1 { margin: 0; font-size: 30px; letter-spacing: .1em; }

/* ---- 标题页：左下大标题 + 右侧竖排按钮 ---- */
#title { z-index: 30; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 24px; box-sizing: border-box;
  padding: calc(28px + var(--safe-t)) calc(40px + var(--safe-r)) calc(36px + var(--safe-b)) calc(44px + var(--safe-l));
  background: linear-gradient(90deg, rgba(8, 10, 12, .62) 0%, rgba(8, 10, 12, .12) 55%, rgba(8, 10, 12, .5) 100%); }
#title .brand h1 { margin: 0; font-size: clamp(38px, 7vw, 84px); line-height: 1.05; letter-spacing: .04em; text-shadow: 0 4px 24px rgba(0, 0, 0, .5); }
#title .brand h1 em { font-style: normal; color: var(--c-accent); }
#title .brand p { margin: 12px 0 0; color: var(--c-text); opacity: .86; font-size: clamp(14px, 1.6vw, 18px); max-width: 30em; line-height: 1.6; }
#title .menu { display: flex; flex-direction: column; gap: 10px; min-width: 200px; }
#title .times { display: flex; gap: 6px; margin-bottom: 6px; }
#title .times .btn { min-width: 0; flex: 1; min-height: 44px; padding: 0 8px; font-size: 14px; }
#title .times .btn.on { border-color: var(--c-accent2); color: var(--c-accent2); background: rgba(246, 196, 69, .1); }
#title .best { color: var(--c-dim); font-size: 13px; text-align: right; min-height: 18px; }

/* ---- HUD ---- */
#hud { z-index: 20; pointer-events: none; }
#hud .chip { background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius); padding: 6px 12px; font-family: var(--yoroll-font-hud, sans-serif);
  font-size: 15px; font-variant-numeric: tabular-nums; display: inline-flex; gap: 8px; align-items: baseline; }
#hud .chip b { font-weight: 500; color: var(--c-accent2); min-width: 2.2em; text-align: right; display: inline-block; }
#hud .tl { position: absolute; left: calc(14px + var(--safe-l)); top: calc(12px + var(--safe-t)); display: flex; gap: 8px; flex-wrap: wrap; }
#hud .tr { position: absolute; right: calc(14px + var(--safe-r)); top: calc(12px + var(--safe-t)); display: flex; gap: 8px; pointer-events: auto; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid rgba(255, 255, 255, .85); border-radius: 50%; box-sizing: border-box; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
#crosshair::after { content: ''; position: absolute; left: 50%; top: 50%; width: 3px; height: 3px; margin: -1.5px; background: #fff; border-radius: 50%; }
#hud .tc { position: absolute; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%); white-space: nowrap; }
#hud .chip.warn { border-color: var(--c-accent); }
#hud .chip.warn b { color: #ff8a7d; }
#dist-arrow { display: inline-block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 11px solid var(--c-accent); align-self: center; }
#hint { position: absolute; left: 50%; bottom: calc(104px + var(--safe-b)); transform: translateX(-50%); max-width: 86vw; text-align: center; }
#pop { position: absolute; left: 50%; top: 34%; transform: translate(-50%, 0) scale(.8); opacity: 0; font-size: clamp(28px, 5vw, 52px); color: #fff; letter-spacing: .06em;
  text-shadow: 0 3px 0 var(--c-accent), 0 6px 22px rgba(0, 0, 0, .55); pointer-events: none; white-space: nowrap; }
#pop.show { animation: pop 1100ms ease-out both; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.7); } 14% { opacity: 1; transform: translate(-50%, 0) scale(1.12); } 28% { transform: translate(-50%, 0) scale(1); } 78% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -22px) scale(1); } }
#crosshair.charging { transform: scale(.55); border-color: var(--c-accent2); transition: transform 600ms linear; }
#crosshair { transition: transform 120ms ease-out; }
#crosshair.lock { border-color: #ff5a4a; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35), 0 0 10px rgba(255, 90, 74, .8); }
#crosshair.lock::after { background: #ff5a4a; }

/* 投掷物栏位 */
#slots { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 6px; pointer-events: auto; }
.slot { appearance: none; position: relative; width: 58px; height: 62px; padding: 6px 0 0; border-radius: var(--radius); border: 1px solid var(--c-line); background: var(--c-panel); color: var(--c-text);
  font: inherit; font-size: 11px; line-height: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; transition: transform var(--ease), border-color var(--ease), opacity var(--ease); }
.slot svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.slot span { white-space: nowrap; pointer-events: none; }
.slot kbd { position: absolute; left: 4px; top: 3px; font: inherit; font-size: 10px; color: var(--c-dim); pointer-events: none; }
.slot[data-count]:not([data-count=""])::before { content: attr(data-count); position: absolute; right: 3px; top: 2px; font-size: 11px; font-weight: 700; color: var(--c-accent2); pointer-events: none; }
.slot.none { opacity: .38; border-style: dashed; }
.slot.used { opacity: .3; }
.slot.used svg { stroke: var(--c-dim); }
.slot.used::after { content: ''; position: absolute; left: 8px; right: 8px; top: 26px; height: 2px; background: var(--c-accent); transform: rotate(-24deg); }
.slot.sel { border-color: var(--c-accent2); color: var(--c-accent2); transform: translateY(-5px); box-shadow: 0 6px 16px rgba(0, 0, 0, .35); }
.slot.flash { animation: slotflash 520ms ease-out; }
@keyframes slotflash { 0% { background: rgba(246, 196, 69, .75); transform: translateY(-10px) scale(1.12); } 100% { background: var(--c-panel); } }
.meters { position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); display: flex; flex-direction: column; gap: 6px; }
.meters .meter { position: static; }
.meter-charge i { background: var(--c-accent2) !important; transform: scaleX(0); }

/* 开场演出 */
#intro { z-index: 24; pointer-events: none; }
#intro::before, #intro::after { content: ''; position: absolute; left: 0; right: 0; height: 9vh; background: #000; }
#intro::before { top: 0; } #intro::after { bottom: 0; }
#caption { position: absolute; left: 50%; bottom: calc(13vh + var(--safe-b)); transform: translateX(-50%); max-width: 88vw; text-align: center; font-size: clamp(16px, 2.4vw, 24px);
  text-shadow: 0 2px 10px rgba(0, 0, 0, .8); z-index: 1; }
#caption.big { font-family: var(--yoroll-font-title, sans-serif); font-weight: 700; font-size: clamp(30px, 6vw, 64px); color: #fff; text-shadow: 0 3px 0 var(--c-accent), 0 6px 22px rgba(0, 0, 0, .6); }
#btn-skip { position: absolute; right: calc(16px + var(--safe-r)); top: calc(12vh + var(--safe-t)); min-width: 132px; line-height: 1.3; pointer-events: auto; z-index: 1; background: rgba(18, 22, 28, .6); }

/* 结算 */
#result .score { display: flex; align-items: baseline; gap: 12px; margin: 6px 0 12px; }
#result .score span { color: var(--c-dim); font-size: 14px; }
#result .score b { font-size: 44px; color: var(--c-accent2); line-height: 1; font-variant-numeric: tabular-nums; }
#result .score em { font-style: normal; color: var(--c-dim); font-size: 13px; }
#result .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
#result .stats div { border: 1px solid var(--c-line); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
#result .stats span { color: var(--c-dim); font-size: 12px; }
#result .stats b { font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
#result-note { color: var(--c-accent2) !important; min-height: 1.4em; }
#result.lose #result-h { color: var(--c-dim); }
#result.win #result-h { color: var(--c-accent2); }
.modal .panel-foot .btn { min-width: 104px; flex: 1 1 auto; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0; }
.opt .btn { min-width: 88px; }
.opt input[type=range] { width: min(220px, 46vw); height: 44px; accent-color: var(--c-accent); }
#title .row2 { display: flex; gap: 8px; }
#title .row2 .btn { flex: 1; min-width: 0; }
#title .times .btn.locked { opacity: .45; }
canvas#view { transition: filter 600ms ease-out; }
canvas#view.lost { filter: saturate(.2) brightness(.85); }
#toast { position: absolute; left: 50%; top: calc(58px + var(--safe-t)); transform: translate(-50%, -12px); opacity: 0; transition: transform 220ms ease-out, opacity 220ms ease-out;
  background: rgba(245, 246, 248, .94); color: #14181d; border-radius: 12px; padding: 9px 16px; font-size: 15px; box-shadow: var(--shadow); max-width: 86vw; text-align: center; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
.meter { position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); width: 150px; height: 6px; background: rgba(0, 0, 0, .45); border-radius: 3px; overflow: hidden; border: 1px solid var(--c-line); }
.meter i { display: block; height: 100%; width: 100%; background: var(--c-ok); transform-origin: left center; }

/* ---- 触屏控件 ---- */
#touch { z-index: 22; pointer-events: none; display: none; }
body.touch #touch { display: block; }
body.touch .meters { bottom: auto; right: auto; left: calc(16px + var(--safe-l)); top: calc(54px + var(--safe-t)); }
body.touch .meters .meter { width: 110px; }
body.touch #toast { top: calc(84px + var(--safe-t)); }
body.touch #hud .chip { font-size: 13px; padding: 5px 9px; }
body.touch #hud .chip-time { display: none; }
body.touch #hud .tc { top: calc(46px + var(--safe-t)); }
body.touch .slot { width: 44px; height: 50px; font-size: 10px; padding-top: 5px; gap: 2px; }
body.touch .slot svg { width: 22px; height: 22px; }
body.touch .slot kbd { display: none; }
body.touch #slots { gap: 4px; bottom: calc(8px + var(--safe-b)); }
body.touch #hint { bottom: calc(70px + var(--safe-b)); }
#btn-throw { right: calc(20px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); width: 80px; height: 80px; background: rgba(226, 59, 46, .55); font-size: 20px; }
#btn-pick { right: calc(112px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); width: 60px; height: 60px; font-size: 14px; border-color: var(--c-accent2); color: var(--c-accent2); }
@media (orientation: portrait) {
  body.touch #slots { bottom: calc(176px + var(--safe-b)); }
  body.touch #hint { bottom: calc(236px + var(--safe-b)); }
}
#stick { position: absolute; left: calc(22px + var(--safe-l)); bottom: calc(22px + var(--safe-b)); width: 132px; height: 132px; border-radius: 50%;
  background: rgba(18, 22, 28, .42); border: 1px solid var(--c-line); pointer-events: auto; }
#stick i { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(255, 255, 255, .32); }
.tbtn { position: absolute; width: 68px; height: 68px; border-radius: 50%; border: 1px solid var(--c-line); background: rgba(18, 22, 28, .5); color: var(--c-text);
  font: inherit; font-size: 17px; pointer-events: auto; display: flex; align-items: center; justify-content: center; }
.tbtn:active { background: rgba(255, 255, 255, .22); }
#btn-jump { right: calc(26px + var(--safe-r)); bottom: calc(112px + var(--safe-b)); }

@media (max-height: 460px) {
  #title { padding-top: calc(12px + var(--safe-t)); padding-bottom: calc(14px + var(--safe-b)); }
  #title .menu { gap: 6px; }
  .btn { min-height: 44px; }
  #title .brand p { display: none; }
}
@media (max-width: 620px) and (orientation: portrait) {
  #title { grid-template-columns: 1fr; align-content: end; padding-left: calc(22px + var(--safe-l)); padding-right: calc(22px + var(--safe-r)); }
  #title .best { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
