/* ==========================================================================
   音程计算器 · Apple HIG 风格移动端样式
   ========================================================================== */

:root {
  --bg-page: #f2f2f7;
  --bg-surface: #ffffff;
  --bg-surface-secondary: #f5f5f7;
  --bg-sheet: rgba(255, 255, 255, 0.94);
  --bg-backdrop: rgba(0, 0, 0, 0.34);

  --text-primary: #1c1c1e;
  --text-secondary: #8e8e93;
  --text-tertiary: #aeaeb2;

  --accent: #007aff;
  --accent-end: #5856d6;
  --accent-soft: rgba(0, 122, 255, 0.09);
  --accent-border: rgba(0, 122, 255, 0.34);
  --danger: #ff3b30;

  --separator: rgba(60, 60, 67, 0.12);
  --card-border: rgba(0, 0, 0, 0.05);
  --wheel-bar: rgba(118, 118, 128, 0.12);
  --segment-bg: rgba(118, 118, 128, 0.12);

  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.045), 0 0.5px 1px rgba(0, 0, 0, 0.06);
  --shadow-card-active: 0 6px 20px rgba(0, 122, 255, 0.14), 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-sheet: 0 -10px 40px rgba(0, 0, 0, 0.16);

  --axis-line: #c7c7cc;
  --axis-tick-major: #8e8e93;
  --axis-tick-minor: #d1d1d6;
  --axis-label-muted: #8e8e93;
  --axis-label-active: #1c1c1e;
  --axis-dot-ring: #ffffff;
  --axis-chip-bg: #ffffff;
  --axis-chip-stroke: rgba(0, 122, 255, 0.28);

  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #000000;
    --bg-surface: #1c1c1e;
    --bg-surface-secondary: #2c2c2e;
    --bg-sheet: rgba(28, 28, 30, 0.94);
    --bg-backdrop: rgba(0, 0, 0, 0.62);

    --text-primary: #f5f5f7;
    --text-secondary: #98989f;
    --text-tertiary: #636366;

    --accent: #0a84ff;
    --accent-end: #5e5ce6;
    --accent-soft: rgba(10, 132, 255, 0.16);
    --accent-border: rgba(10, 132, 255, 0.45);
    --danger: #ff453a;

    --separator: rgba(255, 255, 255, 0.12);
    --card-border: rgba(255, 255, 255, 0.08);
    --wheel-bar: rgba(118, 118, 128, 0.28);
    --segment-bg: rgba(118, 118, 128, 0.24);

    --shadow-card: 0 2px 14px rgba(0, 0, 0, 0.35), inset 0 0.5px 0 rgba(255, 255, 255, 0.06);
    --shadow-card-active: 0 6px 24px rgba(10, 132, 255, 0.22), inset 0 0.5px 0 rgba(255, 255, 255, 0.1);
    --shadow-sheet: 0 -12px 44px rgba(0, 0, 0, 0.6);

    --axis-line: #48484a;
    --axis-tick-major: #8e8e93;
    --axis-tick-minor: #3a3a3c;
    --axis-label-muted: #8e8e93;
    --axis-label-active: #ffffff;
    --axis-dot-ring: #1c1c1e;
    --axis-chip-bg: #2c2c2e;
    --axis-chip-stroke: rgba(10, 132, 255, 0.45);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  overflow-x: hidden;
}

body.sheet-open {
  overflow: hidden;
}

/* ==========================================================================
   主布局：初始极简居中，有结果后丝滑过渡呈现坐标轴
   ========================================================================== */

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: padding-top 0.42s var(--spring);
}

.app-shell[data-state="solved"],
.app-shell[data-state="error"] {
  justify-content: flex-start;
  padding-top: max(16px, env(safe-area-inset-top));
}

/* 顶部极简栏：初始完全透明不占视觉重量 */
.top-bar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  padding: 0 20px;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
  z-index: 10;
}

.reset-btn {
  appearance: none;
  border: none;
  background: var(--bg-surface);
  color: var(--accent);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  border: 0.5px solid var(--card-border);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-6px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.3s var(--spring), background-color 0.15s ease;
}

.app-shell[data-has-input="true"] .reset-btn {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.reset-btn:active {
  transform: scale(0.94);
  background: var(--bg-surface-secondary);
}

/* ==========================================================================
   核心算式区：？ - ？ = ？
   ========================================================================== */

.equation-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 0;
  transition: margin-top 0.45s var(--spring);
}

.app-shell[data-state="solved"] .equation-stage,
.app-shell[data-state="error"] .equation-stage {
  margin-top: 46px;
}

.equation-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
}

.slot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 0 1 88px;
  min-width: 74px;
}

.slot-wrap--interval {
  flex: 1 1 124px;
  max-width: 146px;
  min-width: 104px;
}

.slot-card {
  position: relative;
  width: 100%;
  height: 76px;
  padding: 0 10px;
  border-radius: 22px;
  border: 1.5px solid var(--card-border);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.22s var(--spring),
    border-color 0.22s ease,
    background-color 0.22s ease,
    box-shadow 0.22s ease;
  user-select: none;
}

.slot-card:active {
  transform: scale(0.95);
}

.slot-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 空状态：优雅居中的 ? */
.slot-card[data-status="empty"] .slot-value {
  color: var(--text-tertiary);
  font-weight: 400;
  font-size: 30px;
}

/* 已手动填写状态 */
.slot-card[data-status="input"] {
  border-color: var(--card-border);
  background: var(--bg-surface);
}

.slot-card[data-status="input"] .slot-value {
  color: var(--text-primary);
  font-weight: 600;
}

/* 自动计算得出状态 */
.slot-card[data-status="computed"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  box-shadow: var(--shadow-card-active);
}

.slot-card[data-status="computed"] .slot-value {
  color: var(--accent);
  font-weight: 700;
}

/* 正在编辑高亮 */
.slot-card.is-editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 轻微弹出动效 */
@keyframes popValue {
  0% {
    transform: scale(0.86);
    opacity: 0.5;
  }
  60% {
    transform: scale(1.04);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.slot-card.is-popping .slot-value {
  animation: popValue 0.32s var(--spring);
}

.slot-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: rgba(0, 122, 255, 0.12);
  padding: 1.5px 5.5px;
  border-radius: 999px;
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.25s var(--spring);
}

@media (prefers-color-scheme: dark) {
  .slot-badge {
    background: rgba(10, 132, 255, 0.22);
  }
}

.slot-card[data-status="computed"] .slot-badge {
  opacity: 1;
  transform: scale(1);
}

.slot-value {
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.slot-card--interval .slot-value {
  font-size: 23px;
  letter-spacing: -0.01em;
}

.slot-card--interval[data-status="empty"] .slot-value {
  font-size: 28px;
}

.slot-card--interval.is-long-text .slot-value {
  font-size: 20px;
}

.slot-value .acc-sym {
  font-size: 0.78em;
  vertical-align: 0.12em;
  margin-right: 0.5px;
  font-weight: 600;
}

.slot-value .oct-prime {
  font-size: 0.72em;
  vertical-align: 0.24em;
  opacity: 0.8;
  margin-left: 1px;
}

.slot-caption {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.eq-operator {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 400;
  color: var(--text-secondary);
  user-select: none;
  flex-shrink: 0;
  padding: 0 2px;
}

.hint-text {
  margin: 22px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: 0.01em;
  min-height: 19px;
  transition: opacity 0.25s ease;
}

.app-shell[data-state="solved"] .hint-text {
  margin-top: 12px;
  font-size: 12px;
  opacity: 0.78;
}

/* 特殊/超限提示卡 */
.notice-card {
  width: 100%;
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--bg-surface);
  border: 0.5px solid var(--card-border);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-primary);
}

.notice-card[hidden] {
  display: none;
}

.notice-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 149, 0, 0.16);
  color: #ff9500;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ==========================================================================
   音符坐标轴卡片区
   ========================================================================== */

.axis-section {
  width: 100%;
  margin-top: 18px;
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
  transition:
    opacity 0.36s var(--spring),
    transform 0.44s var(--spring),
    max-height 0.44s var(--spring);
}

.app-shell[data-state="solved"] .axis-section {
  opacity: 1;
  transform: translateY(0) scale(1);
  max-height: 520px;
  pointer-events: auto;
}

.axis-card {
  background: var(--bg-surface);
  border-radius: 24px;
  padding: 16px 16px 15px;
  border: 0.5px solid var(--card-border);
  box-shadow: var(--shadow-card);
}

.axis-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.axis-title-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.axis-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.axis-scale-hint {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.axis-card-header.has-octave-toggle .axis-scale-hint {
  display: none;
}

.axis-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* iOS Segmented Control for 1度 / 8度 */
.octave-segment {
  display: inline-flex;
  background: var(--segment-bg);
  padding: 2px;
  border-radius: 9px;
  gap: 1px;
}

.octave-segment[hidden] {
  display: none;
}

.segment-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.segment-btn.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* 试听按钮 */
.play-btn {
  appearance: none;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.16s var(--spring), background-color 0.16s ease;
}

.play-btn:active {
  transform: scale(0.93);
}

.play-btn.is-playing {
  background: var(--accent);
  color: #ffffff;
}

/* SVG 坐标轴容器 */
.axis-canvas-wrap {
  width: 100%;
  padding: 4px 0 2px;
}

.axis-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
  user-select: none;
}

/* 底部紧凑笔记信息 */
.axis-meta {
  margin-top: 10px;
  padding-top: 11px;
  border-top: 0.5px solid var(--separator);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.meta-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.meta-chip {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-surface-secondary);
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.derivation-tip {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ==========================================================================
   iOS 风格底部滑动选择器 Bottom Sheet
   ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  z-index: 90;
  transition: opacity 0.28s ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.picker-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: var(--bg-sheet);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-radius: 28px 28px 0 0;
  box-shadow: var(--shadow-sheet);
  border-top: 0.5px solid var(--card-border);
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 100;
  transform: translate(-50%, 105%);
  transition: transform 0.36s var(--spring);
  will-change: transform;
}

.picker-sheet.is-open {
  transform: translate(-50%, 0);
}

.sheet-handle-bar {
  display: flex;
  justify-content: center;
  padding: 9px 0 4px;
}

.sheet-handle {
  width: 36px;
  height: 4.5px;
  border-radius: 999px;
  background: var(--separator);
}

.sheet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 18px 12px;
  border-bottom: 0.5px solid var(--separator);
}

.sheet-action {
  appearance: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  padding: 6px 4px;
  min-width: 48px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.sheet-action:active {
  opacity: 0.45;
}

.sheet-action--left {
  text-align: left;
  color: var(--text-secondary);
  font-weight: 400;
}

.sheet-action--left.is-clear {
  color: var(--danger);
}

.sheet-action--done {
  text-align: right;
  color: var(--accent);
  font-weight: 600;
}

.sheet-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheet-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.sheet-preview {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2.5px 10px;
  border-radius: 999px;
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.wheel-headers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 10px 24px 2px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

/* 3D 滚轮核心舞台 */
.wheel-stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 220px; /* 5 * 44px */
  padding: 0 18px;
  overflow: hidden;
  user-select: none;
}

.wheel-highlight-bar {
  position: absolute;
  left: 18px;
  right: 18px;
  top: 88px; /* 2 * 44px */
  height: 44px;
  border-radius: 12px;
  background: var(--wheel-bar);
  pointer-events: none;
  z-index: 1;
}

.wheel-column {
  position: relative;
  height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  perspective: 900px;
  z-index: 2;
  cursor: grab;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.85) 24%,
    #000000 42%,
    #000000 58%,
    rgba(0, 0, 0, 0.85) 76%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.85) 24%,
    #000000 42%,
    #000000 58%,
    rgba(0, 0, 0, 0.85) 76%,
    transparent 100%
  );
}

.wheel-column:active {
  cursor: grabbing;
}

.wheel-column::-webkit-scrollbar {
  display: none;
}

.wheel-column:focus-visible {
  outline: none;
}

.wheel-spacer {
  height: 88px; /* 2 * 44px */
  flex-shrink: 0;
}

.wheel-item {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  scroll-snap-align: center;
  scroll-snap-stop: normal;
  font-size: 20px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transform-origin: center center;
  will-change: transform, opacity;
  transition: color 0.12s ease;
}

.wheel-item.is-selected {
  font-weight: 600;
  color: var(--text-primary);
}

.wheel-item-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

.sheet-footnote {
  min-height: 20px;
  padding: 6px 20px 2px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ==========================================================================
   极窄屏（iPhone SE 等 320px-375px）适配
   ========================================================================== */

@media (max-width: 374px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .equation-row {
    gap: 5px;
  }

  .slot-wrap {
    min-width: 66px;
  }

  .slot-wrap--interval {
    min-width: 96px;
  }

  .slot-card {
    height: 70px;
    border-radius: 18px;
  }

  .slot-value {
    font-size: 24px;
  }

  .slot-card--interval .slot-value {
    font-size: 20px;
  }

  .slot-card--interval.is-long-text .slot-value {
    font-size: 18px;
  }

  .eq-operator {
    height: 70px;
    font-size: 22px;
  }
}
