:root {
  color-scheme: dark;
  --bg: #18191d;
  --bg-deep: #101114;
  --surface: #292a30;
  --surface-high: #383940;
  --surface-soft: #222329;
  --text: #f7f8f6;
  --muted: #b0b1b6;
  --faint: #7b7d84;
  --accent: #9368ed;
  --accent-start: #8f54de;
  --accent-end: #6952df;
  --accent-pressed: #7659e2;
  --accent-soft: rgba(147, 104, 237, .12);
  --on-accent: #ffffff;
  --line: rgba(255, 255, 255, .08);
  --danger: #ff6254;
  --radius-surface: 18px;
  --radius-control: 13px;
  --ease: cubic-bezier(.2,.8,.2,1);
  font-family: "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", "Microsoft YaHei UI", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; }
button { color: inherit; }
button, [role="button"] { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(147,104,237,.72); outline-offset: 2px; }
#app { min-height: 100dvh; }

.app-shell { width: min(100%, 520px); min-height: 100dvh; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(88px + env(safe-area-inset-bottom)); }
.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.brand-name { font-size: 30px; line-height: 1; font-weight: 900; letter-spacing: -.06em; }
.brand-sub { margin-top: 7px; color: var(--faint); font-size: 11px; font-weight: 600; }
.topbar-status, .topbar-action { min-height: 44px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 999px; font-size: 12px; font-weight: 850; }
.topbar-status { min-height: auto; padding: 8px 11px; color: var(--muted); background: var(--surface-soft); }
.topbar-action { color: var(--on-accent); background: linear-gradient(100deg, var(--accent-start), var(--accent-end)); }
.topbar-action { cursor: pointer; }

.page { padding-bottom: 18px; }
.page-head { padding: 27px 2px 22px; }
.page-head h1 { margin: 0; font-size: clamp(29px, 8.6vw, 38px); line-height: 1.14; font-weight: 900; letter-spacing: -.055em; }
.page-head p { max-width: 31em; margin: 9px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.home-head { padding-bottom: 30px; }
.section-head { margin: 0 2px 13px; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.section-head h2 { margin: 0; font-size: 24px; font-weight: 900; letter-spacing: -.045em; }
.section-head span { color: var(--faint); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }

.primary-btn, .secondary-btn, .new-board-btn, .small-btn, .icon-btn, .text-btn { min-height: 50px; border-radius: var(--radius-control); font-weight: 800; cursor: pointer; transition: transform .16s var(--ease), background-color .16s var(--ease), opacity .16s var(--ease); }
.primary-btn { width: 100%; padding: 0 18px; border: 0; color: var(--on-accent); background: linear-gradient(100deg, var(--accent-start), var(--accent-end)); font-size: 16px; box-shadow: inset 0 1px 0 rgba(255,255,255,.13); }
.primary-btn:hover { filter: brightness(1.06); }
.secondary-btn { width: 100%; padding: 0 14px; border: 0; color: var(--text); background: var(--surface-high); font-size: 14px; }
.new-board-btn { width: 100%; margin-top: 12px; padding: 0 16px; border: 0; color: var(--muted); background: var(--surface-soft); }
.small-btn, .icon-btn, .text-btn { min-width: 48px; padding: 0 12px; border: 0; background: var(--surface); }
.danger-text { color: #ff9b92; }
.primary-btn:active, .secondary-btn:active, .new-board-btn:active, .small-btn:active, .icon-btn:active, .physical-card:active, .rule-card:active, .track-btn:active { transform: scale(.98); }
.primary-btn:disabled, .secondary-btn:disabled, .new-board-btn:disabled { opacity: .35; cursor: not-allowed; }

.board-list { display: grid; gap: 14px; }
.board-card { padding: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-surface); background: var(--surface-soft); }
.board-card-top { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: start; gap: 14px; }
.board-heading { min-width: 0; }
.board-title { margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 20px; line-height: 1.25; font-weight: 900; letter-spacing: -.035em; }
.board-meta { margin-top: 5px; color: var(--muted); font-size: 12px; }
.board-tools { display: flex; gap: 8px; }
.board-tool { min-width: 48px; min-height: 44px; padding: 0 8px; border: 0; border-radius: 11px; color: var(--muted); background: var(--surface-high); font-size: 12px; font-weight: 800; cursor: pointer; }
.board-tool:active { opacity: .72; }
.role-scroller { margin: 16px -18px 17px; padding: 0 18px 3px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.role-scroller::-webkit-scrollbar { display: none; }
.role-preview { width: 86px; min-width: 86px; height: 112px; padding: 8px; display: flex; flex-direction: column; overflow: hidden; scroll-snap-align: start; border: 1px solid var(--line); border-radius: 13px; background: var(--bg); }
.role-preview strong { position: relative; z-index: 1; font-size: 11px; font-weight: 850; }
.role-preview img { width: calc(100% + 16px); height: 88px; margin: 1px -8px -8px; object-fit: cover; object-position: 50% 23%; filter: saturate(.85) contrast(1.02); }
.role-more { align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.role-more span { color: var(--accent); font-size: 24px; font-weight: 900; }

.empty-state { padding: 24px; border-radius: var(--radius-surface); background: var(--surface-soft); }
.empty-state h2 { margin: 0; font-size: 21px; font-weight: 900; }
.empty-state p { margin: 7px 0 20px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.install-note { margin: 16px 0 0; color: var(--faint); text-align: center; font-size: 11px; }

.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%,520px); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; border-top: 1px solid var(--line); background: rgba(24,25,29,.97); }
.nav-btn { min-height: 58px; padding: 5px 0 3px; display: grid; place-items: center; gap: 2px; border: 0; border-radius: 12px; color: var(--faint); background: transparent; font-size: 11px; font-weight: 750; cursor: pointer; }
.nav-btn.active { color: #b993ff; background: var(--accent-soft); }
.nav-icon, .back-icon { width: 21px; height: 21px; display: block; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.back-icon { --icon: url("./assets/icons/back.svg"); }

.editor-head { min-height: 76px; display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 10px; margin-bottom: 23px; }
.editor-head h1 { margin: 0; text-align: center; font-size: 21px; font-weight: 900; letter-spacing: -.035em; }
.icon-btn { padding: 0; display: grid; place-items: center; color: var(--text); background: transparent; }
.editor-head-spacer { width: 48px; }
.field { display: grid; gap: 8px; margin-bottom: 14px; }
.field label, .field-label { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field select { width: 100%; min-height: 54px; padding: 0 15px; border: 0; border-radius: var(--radius-control); color: var(--text); background: var(--surface); font-size: 16px; }
.field input::placeholder { color: var(--faint); }
.player-panel { min-height: 82px; margin-bottom: 30px; padding: 13px 15px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-radius: var(--radius-control); background: var(--surface); }
.player-panel strong { display: block; margin-top: 2px; font-size: 20px; font-weight: 900; }
.player-panel small { display: block; color: var(--faint); font-size: 11px; }
.counter { display: flex; align-items: center; gap: 6px; }
.counter button { width: 48px; height: 48px; border: 0; border-radius: 12px; color: var(--text); background: var(--surface-high); font-size: 20px; font-weight: 700; }
.counter output { min-width: 28px; text-align: center; font-weight: 900; font-variant-numeric: tabular-nums; }
.deck-heading { margin: 0 2px 14px; display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.deck-heading h2 { margin: 0; font-size: 23px; font-weight: 900; letter-spacing: -.04em; }
.deck-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.selection-status { min-width: 70px; display: flex; align-items: baseline; justify-content: flex-end; color: var(--danger); font-variant-numeric: tabular-nums; }
.selection-status strong { font-size: 25px; line-height: 1; font-weight: 950; }
.selection-status span { margin-left: 3px; font-size: 12px; font-weight: 800; }
.selection-status.complete { color: #b993ff; }
.deck-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; }
.physical-card { min-width: 0; padding: 0; overflow: hidden; text-align: left; border: 2px solid transparent; border-radius: 15px; color: var(--text); background: var(--surface-soft); cursor: pointer; transition: transform .16s var(--ease), border-color .16s var(--ease), background-color .16s var(--ease); }
.card-art { position: relative; display: block; aspect-ratio: .78; overflow: hidden; background: var(--bg-deep); }
.physical-card img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: 50% 23%; filter: saturate(.55) brightness(.72); transition: filter .16s var(--ease); }
.card-check { position: absolute; top: 7px; right: 7px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; color: transparent; background: rgba(14,15,18,.82); font-size: 14px; font-weight: 900; }
.card-caption { min-height: 47px; padding: 7px 8px; display: flex; align-items: center; justify-content: space-between; gap: 5px; }
.card-caption strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; font-weight: 900; }
.card-caption small { flex: none; color: var(--faint); font-size: 9px; }
.physical-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.physical-card.selected img { filter: saturate(1) brightness(.96); }
.physical-card.selected .card-check { color: var(--on-accent); background: var(--accent); }
.editor-footer { position: sticky; z-index: 8; bottom: 0; margin: 18px -16px -18px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: .72fr 1.28fr; gap: 10px; border-top: 1px solid var(--line); background: rgba(24,25,29,.98); }

.rule-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.rule-card { padding: 0; overflow: hidden; text-align: left; border: 0; border-radius: 16px; color: var(--text); background: var(--surface-soft); cursor: pointer; }
.rule-card img { width: 100%; aspect-ratio: 1.02; display: block; object-fit: cover; object-position: 50% 23%; filter: saturate(.82); }
.rule-card-copy { padding: 11px 12px 13px; }
.rule-card-copy strong { display: block; font-size: 15px; font-weight: 900; }
.rule-card-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }

.settings-group { margin-bottom: 18px; overflow: hidden; border-radius: var(--radius-surface); background: var(--surface-soft); }
.settings-title { padding: 18px 16px 4px; font-size: 18px; font-weight: 900; letter-spacing: -.025em; }
.settings-help { padding: 0 16px 15px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.setting-row { min-height: 64px; padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); }
.setting-copy strong { display: block; font-size: 14px; font-weight: 800; }
.setting-copy span { color: var(--faint); font-size: 9px; }
.setting-control { display: flex; align-items: center; gap: 5px; }
.setting-control button { width: 48px; height: 48px; border: 0; border-radius: 12px; color: var(--text); background: var(--surface-high); font-size: 18px; }
.setting-control output { min-width: 45px; text-align: center; font-size: 12px; font-weight: 850; font-variant-numeric: tabular-nums; }
.range-row { width: 100%; display: grid; grid-template-columns: 1fr 46px; gap: 10px; align-items: center; }
.range-row input { min-height: 30px; accent-color: var(--accent); }
.range-row output { color: #b993ff; text-align: right; font-size: 12px; font-weight: 850; }
.track-list { border-top: 1px solid var(--line); }
.track-btn { width: 100%; min-height: 58px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; border: 0; border-bottom: 1px solid var(--line); color: var(--text); background: transparent; cursor: pointer; }
.track-btn:last-child { border-bottom: 0; }
.track-btn strong { font-size: 14px; font-weight: 800; }
.track-btn span { color: var(--faint); font-size: 10px; }
.track-btn.active { box-shadow: inset 4px 0 var(--accent); background: var(--accent-soft); }
.preview-row { padding: 11px 14px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; border-top: 1px solid var(--line); }
.preview-row #bgm-state { color: var(--faint); font-size: 11px; }
.preview-dot { width: 8px; height: 8px; margin-right: 7px; display: inline-block; border-radius: 50%; background: var(--faint); }
.preview-row button.playing .preview-dot { background: var(--accent); }

.sheet-backdrop { position: fixed; z-index: 50; inset: 0; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.72); }
.sheet { width: min(100%,520px); max-height: 88dvh; overflow: auto; padding: 15px 18px calc(22px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: var(--surface); animation: sheet-in .2s var(--ease); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: .7; } }
.sheet-grip { width: 38px; height: 4px; margin: 0 auto 17px; border-radius: 9px; background: #64666d; }
.sheet h2 { margin: 0 0 7px; font-size: 23px; font-weight: 900; letter-spacing: -.035em; }
.sheet p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.sheet-actions { margin-top: 18px; display: grid; gap: 9px; }
.rule-detail { display: grid; grid-template-columns: 100px 1fr; gap: 14px; align-items: start; }
.rule-detail img { width: 100px; height: 136px; object-fit: cover; border-radius: 15px; }
.detail-block { margin-top: 17px; padding-top: 15px; border-top: 1px solid var(--line); }
.detail-block h3 { margin: 0 0 5px; color: #b993ff; font-size: 12px; }
.detail-block p { margin: 0; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 28px); padding: 12px 15px; border-radius: 12px; color: var(--text); background: #404148; font-size: 12px; font-weight: 700; animation: toast-in .16s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%,8px); } }

.game-shell { min-height: 100dvh; padding: calc(18px + env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; color: var(--muted); background: var(--bg-deep); }
.game-top { width: min(100%,460px); min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--faint); font-size: 12px; font-weight: 700; }
.game-center { width: min(100%,420px); flex: 1; padding: 25px 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.phase-label { color: #b993ff; font-size: 12px; font-weight: 850; }
.game-title { margin: 10px 0 0; color: var(--text); font-size: clamp(29px,9vw,38px); line-height: 1.15; font-weight: 900; letter-spacing: -.05em; }
.game-sub { margin-top: 8px; color: var(--faint); font-size: 13px; }
.progress-ring { --progress:0%; width: 184px; height: 184px; margin: 34px auto 18px; display: grid; place-items: center; position: relative; border-radius: 50%; background: conic-gradient(var(--accent) var(--progress), var(--surface-soft) 0); }
.progress-ring::before { content:""; position:absolute; inset: 10px; border-radius:50%; background: var(--bg-deep); }
.time-number { position:relative; z-index:1; color:var(--text); font-size:58px; font-weight:900; font-variant-numeric:tabular-nums; }
.game-controls { width:min(100%,420px); display:grid; grid-template-columns:1.2fr 1fr; gap:10px; }
.game-controls button { min-height:56px; }
.game-controls .pause-btn { color:var(--on-accent); background:linear-gradient(100deg,var(--accent-start),var(--accent-end)); }
.game-danger { width:min(100%,420px); min-height:48px; margin-top:8px; border:0; color:#9e625c; background:transparent; }
.hold-progress { position:relative; overflow:hidden; }
.hold-progress::after { content:""; position:absolute; inset:0; transform:scaleX(var(--hold,0)); transform-origin:left; background:rgba(255,98,84,.18); pointer-events:none; }
.hold-progress.holding::after { transform:scaleX(1); transition:transform .9s linear; }

@media (max-width: 360px) {
  .app-shell { padding-left: 11px; padding-right: 11px; }
  .board-card { padding: 16px; }
  .role-scroller { margin-inline: -16px; padding-inline: 16px; }
  .deck-grid { gap: 6px; }
  .card-caption { padding-inline: 6px; }
  .editor-footer { margin-inline: -11px; padding-inline: 11px; }
}
@media (min-width: 700px) {
  .app-shell { padding-left: 22px; padding-right: 22px; }
  .role-preview { width: 94px; min-width: 94px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; scroll-behavior:auto !important; }
}
