/* ════════════════════════════════════════════════════════════════
 * 荆棘之径 Thorn Path — 沉浸舞台样式（融入 cyane279 淡蓝紫文艺体系）
 * 保持画布素纸高对比，桌面端严格单屏（100dvh）不出现滚动条
 * ════════════════════════════════════════════════════════════════ */

:root {
  --tp-bg: var(--c-surface, #ffffff);
  --tp-page: var(--c-bg, #f6f7fb);
  --tp-canvas-bg: #ffffff;
  --tp-line-color: #101010;
  --tp-head: #0a84ff;
  --tp-tail: #ff3b30;
  --tp-text: var(--c-text, #1e2235);
  --tp-dim: var(--c-text-muted, #686f8c);
  --tp-panel: var(--c-surface, #ffffff);
  --tp-surface: var(--c-surface-soft, #f0f2fa);
  --tp-line: var(--c-border, #e2e5f2);
  --tp-line-soft: var(--c-border, #e2e5f2);
  --tp-accent: var(--c-accent, #5b5ea6);
  --tp-accent-soft: var(--c-accent-soft, #eef0fa);
  --tp-on-accent: var(--c-on-accent, #ffffff);

  --tp-radius: 14px;
  --tp-radius-sm: 10px;
  --tp-font: var(--font-sans, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif);
  --tp-serif: var(--font-serif, "Newsreader", "Noto Serif SC", serif);
  --tp-mono: var(--font-mono, ui-monospace, Menlo, Consolas, monospace);
}

[data-theme="dark"] {
  --tp-canvas-bg: #eef0fa;
}

/* ─────────────────────────── 顶部返回壳层栏 ─────────────────────────── */

.tp-shell-bar {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tp-back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--tp-line);
  border-radius: 999px;
  background: var(--tp-panel);
  color: var(--tp-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease,
    transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.tp-back-link svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.tp-back-link:hover {
  color: var(--tp-accent);
  border-color: var(--c-accent-soft-border, var(--tp-accent));
  background: var(--tp-accent-soft);
}

.tp-back-link:hover svg {
  transform: translateX(-2px);
}

.tp-shell-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.tp-shell-hint {
  font-size: 12px;
  color: var(--tp-dim);
  letter-spacing: 0.04em;
}

/* ─────────────────────────── 主舞台容器 ─────────────────────────── */

#thorn-path-root,
#thorn-path-root *,
#thorn-path-root *::before,
#thorn-path-root *::after {
  box-sizing: border-box;
}

#thorn-path-root,
.tp-root {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px 20px;
  color: var(--tp-text);
  font-family: var(--tp-font);
  font-size: 14px;
  line-height: 1.5;
}

/* ─────────────────────────── 顶部信息栏 ─────────────────────────── */

.tp-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 18px;
  margin-bottom: 12px;
}

.tp-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.tp-brand h1,
.tp-brand .tp-title {
  margin: 0;
  font-family: var(--tp-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--tp-text);
}

.tp-brand .tp-sub {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tp-dim);
}

.tp-meta {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-family: var(--tp-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--tp-dim);
}

.tp-meta b {
  font-weight: 600;
  color: var(--tp-text);
}

/* 档位按钮组 */
.tp-tiers {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--tp-line);
  border-radius: 999px;
  background: var(--tp-panel);
}

.tp-tiers button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 13px;
  background: transparent;
  color: var(--tp-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.16s ease, background-color 0.16s ease, transform 0.16s ease;
}

.tp-tiers button:hover {
  color: var(--tp-text);
}

.tp-tiers button:active {
  transform: translateY(1px);
}

.tp-tiers button.is-active,
.tp-tiers button[aria-pressed="true"],
.tp-tiers button[aria-selected="true"] {
  background: var(--tp-accent);
  color: var(--tp-on-accent);
  font-weight: 600;
}

/* 声音开关 */
#tp-sound {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--tp-line);
  border-radius: 999px;
  padding: 8px 14px;
  background: var(--tp-panel);
  color: var(--tp-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}

#tp-sound::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tp-line-color);
  opacity: 0.22;
  transition: background-color 0.16s ease, opacity 0.16s ease;
}

#tp-sound:hover {
  color: var(--tp-text);
  border-color: var(--c-border-strong, var(--tp-accent));
}

#tp-sound.is-on,
#tp-sound[aria-pressed="true"] {
  color: var(--tp-accent);
  border-color: var(--c-accent-soft-border, var(--tp-accent));
  background: var(--tp-accent-soft);
}

#tp-sound.is-on::before,
#tp-sound[aria-pressed="true"]::before {
  background: var(--tp-accent);
  opacity: 1;
}

/* ─────────────────────────── 主布局 ─────────────────────────── */

.tp-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  align-items: start;
}

/* 桌面端：严格锁定单屏不出现竖向滚动条 */
@media (min-width: 901px) {
  body.tp-stage-page {
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #thorn-path-root,
  .tp-root {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 10px 24px 16px;
  }

  .tp-layout {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }

  .tp-stage {
    height: 100%;
    min-height: 0;
  }

  #tp-canvas {
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
  }

  .tp-sidebar {
    height: 100%;
    min-height: 0;
    justify-content: space-between;
    gap: 10px;
  }
}

/* 画布容器 */
.tp-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

#tp-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: var(--tp-radius);
  background: var(--tp-canvas-bg);
  border: 1px solid var(--tp-line);
  box-shadow: var(--c-shadow-sm, 0 2px 8px rgba(30, 34, 53, 0.035));
  touch-action: none;
}

/* ─────────────────────────── 侧栏 ─────────────────────────── */

.tp-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.tp-panel {
  padding: 12px 14px;
  border: 1px solid var(--tp-line);
  border-radius: var(--tp-radius);
  background: var(--tp-panel);
  box-shadow: var(--c-shadow-sm, none);
}

.tp-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.tp-panel-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tp-dim);
}

.tp-panel-head .tp-panel-title {
  margin-bottom: 0;
}

/* 罗盘 */
.tp-compass-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#tp-compass {
  display: block;
  width: min(176px, 100%);
  aspect-ratio: 1 / 1;
  height: auto;
  background: var(--tp-canvas-bg);
  border: 1px solid var(--tp-line);
  border-radius: 50%;
}

.tp-legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--tp-dim);
}

.tp-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tp-legend i {
  width: 8px;
  height: 3px;
  border-radius: 2px;
  background: var(--tp-head);
}

.tp-legend .is-neg i {
  background: var(--tp-tail);
}

/* 统计区 */
.tp-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.tp-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--tp-line-soft);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface);
  min-width: 0;
}

.tp-stat.is-wide {
  grid-column: 1 / -1;
}

.tp-stat dt,
.tp-stat .tp-stat-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tp-dim);
  margin: 0;
}

.tp-stat dd,
.tp-stat .tp-stat-value {
  margin: 0;
  font-family: var(--tp-mono);
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--tp-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#tp-timer {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--tp-mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--tp-text);
}

#tp-timer .tp-t-main {
  color: var(--tp-text);
}

#tp-timer .tp-t-dot {
  color: var(--tp-dim);
  margin: 0 1px;
}

#tp-timer .tp-t-ms {
  font-size: 0.58em;
  font-weight: 550;
  color: var(--tp-accent);
  min-width: 2.2em;
  display: inline-block;
}

#tp-best,
#tp-attempts,
#tp-clears {
  font-family: var(--tp-mono);
  font-variant-numeric: tabular-nums;
}

/* 键位提示 */
.tp-keys {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--tp-dim);
}

.tp-keys div {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tp-keys kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--tp-line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--tp-surface);
  color: var(--tp-text);
  font-family: var(--tp-mono);
  font-size: 11px;
}

/* ─────────────────────────── 结算浮层 ─────────────────────────── */

#tp-overlay,
.tp-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--c-backdrop, rgba(24, 27, 42, 0.28));
  backdrop-filter: blur(6px);
  animation: tp-fade 0.2s ease-out both;
}

#tp-overlay[hidden],
#tp-overlay.is-hidden {
  display: none;
}

#tp-overlay .tp-card {
  width: min(420px, 100%);
  padding: 28px 24px 24px;
  border: 1px solid var(--tp-line);
  border-radius: 18px;
  background: var(--tp-panel);
  box-shadow: var(--c-shadow-md, 0 12px 30px rgba(30, 34, 53, 0.08));
  text-align: center;
}

#tp-overlay .tp-card h2 {
  margin: 0 0 6px;
  font-family: var(--tp-serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--tp-text);
}

#tp-overlay .tp-card .tp-result {
  margin: 14px 0 4px;
  font-family: var(--tp-mono);
  font-variant-numeric: tabular-nums;
  font-size: 36px;
  font-weight: 700;
  color: var(--tp-accent);
}

#tp-overlay .tp-card .tp-result-sub {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--tp-dim);
}

#tp-overlay .tp-card .tp-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

#tp-overlay .tp-card button {
  appearance: none;
  border: 1px solid var(--tp-accent);
  border-radius: 999px;
  padding: 9px 22px;
  background: var(--tp-accent);
  color: var(--tp-on-accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.16s ease, transform 0.16s ease;
}

#tp-overlay .tp-card button:hover {
  background: var(--c-accent-hover, #4a4d94);
}

#tp-overlay .tp-card button:active {
  transform: translateY(1px);
}

@keyframes tp-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.tp-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;
}

@media (prefers-reduced-motion: reduce) {
  #tp-overlay,
  #tp-overlay .tp-card {
    animation: none;
  }
  .tp-tiers button,
  #tp-sound,
  .tp-back-link,
  .tp-back-link svg {
    transition: none;
  }
}

/* ─────────────────────────── 平板/手机响应式 ─────────────────────────── */

@media (max-width: 900px) {
  .tp-shell-bar {
    padding: 12px 14px 0;
  }

  #thorn-path-root,
  .tp-root {
    padding: 12px 14px 26px;
  }

  .tp-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .tp-sidebar {
    display: grid;
    grid-template-columns: 164px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
  }

  .tp-sidebar .tp-panel.is-compass {
    grid-row: span 2;
  }

  .tp-sidebar .tp-panel.is-keys {
    grid-column: 2;
  }

  #tp-sound {
    grid-column: 1 / -1;
  }

  #tp-timer {
    font-size: 24px;
  }

  .tp-tiers {
    order: 3;
    display: flex;
    width: 100%;
  }

  .tp-tiers button {
    flex: 1;
    padding: 6px 11px;
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .tp-shell-hint {
    display: none;
  }

  .tp-sidebar {
    grid-template-columns: minmax(0, 1fr);
  }

  .tp-sidebar .tp-panel.is-compass {
    grid-row: auto;
  }

  .tp-sidebar .tp-panel.is-keys {
    grid-column: 1;
  }

  .tp-compass-wrap {
    max-width: 190px;
    margin: 0 auto;
  }

  #tp-overlay .tp-card .tp-result {
    font-size: 30px;
  }
}
