/* ==============================================================
   火柴棒等式 · 游戏专属样式
   选择器统一以 .g-matchstick / .ms-* 前缀限定
   ============================================================== */

.g-matchstick { gap: 10px; }

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

.ms-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}
.ms-hud .badge { font-size: 11px; padding: 4px 10px; }
.ms-hints,
.ms-attempts {
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ms-time {
  margin-left: auto;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* ------------------------------ 等式舞台 ------------------------------ */

.ms-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.ms-stage::before {
  content: "";
  position: absolute;
  width: 72%;
  height: 60%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 209, 102, 0.09), transparent 68%);
  pointer-events: none;
}
.ms-stage.bad::before { background: radial-gradient(ellipse, rgba(255, 92, 108, 0.12), transparent 68%); }

.ms-eq {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u, 42px) * 0.16);
  padding: 12px 10px;
  touch-action: manipulation;
  --t: clamp(6px, calc(var(--u, 42px) * 0.15), 8px);
}
.ms-ch {
  position: relative;
  flex: none;
  height: calc(var(--u, 42px) * 1.7);
}
.ms-ch-d { width: var(--u, 42px); }
.ms-ch-o,
.ms-ch-e { width: calc(var(--u, 42px) * 0.72); }

.ms-seg {
  position: absolute;
  display: block;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  background: transparent;
  color: transparent;
  font-size: 0;
  line-height: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

/* 七段位置（数字） */
.ms-s0,
.ms-s3,
.ms-s6 {
  left: calc(var(--u, 42px) * 0.08);
  width: calc(var(--u, 42px) * 0.84);
  height: var(--t);
}
.ms-s0 { top: 0; }
.ms-s6 { top: calc(var(--u, 42px) * 0.775); }
.ms-s3 { bottom: 0; }
.ms-s1,
.ms-s2,
.ms-s4,
.ms-s5 {
  width: var(--t);
  height: calc(var(--u, 42px) * 0.7);
}
.ms-s1 { right: 0; top: calc(var(--u, 42px) * 0.15); }
.ms-s2 { right: 0; bottom: calc(var(--u, 42px) * 0.15); }
.ms-s5 { left: 0; top: calc(var(--u, 42px) * 0.15); }
.ms-s4 { left: 0; bottom: calc(var(--u, 42px) * 0.15); }

/* 运算符：+ 横竖；− 只有横 */
.ms-oh {
  z-index: 1;
  left: 0;
  width: 100%;
  height: var(--t);
  top: calc((var(--u, 42px) * 1.7 - var(--t)) / 2);
}
.ms-ov {
  z-index: 2;
  width: var(--t);
  height: calc(var(--u, 42px) * 0.65);
  left: calc((var(--u, 42px) * 0.72 - var(--t)) / 2);
  top: calc((var(--u, 42px) * 1.7 - var(--u, 42px) * 0.65) / 2);
}

/* 等号两根固定横棒 */
.ms-e0,
.ms-e1 {
  left: 0;
  width: 100%;
  height: var(--t);
}
.ms-e0 { top: calc(var(--u, 42px) * 1.7 * 0.32); }
.ms-e1 { top: calc(var(--u, 42px) * 1.7 * 0.58); }

/* 木色火柴 */
.ms-seg.on {
  pointer-events: auto;
  cursor: pointer;
  background: linear-gradient(180deg, #fff0b8 0%, #f2cd68 34%, #c79a3e 72%, #8c6426 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 3px rgba(0, 0, 0, 0.45);
}
.ms-s1,
.ms-s2,
.ms-s4,
.ms-s5,
.ms-ov {
  background: linear-gradient(90deg, #fff0b8 0%, #f2cd68 34%, #c79a3e 72%, #8c6426 100%);
}
.ms-seg.on.locked { pointer-events: none; cursor: default; }
.ms-seg.on::after {
  content: "";
  position: absolute;
  inset: -5px;
}
.ms-seg.off { opacity: 0; pointer-events: none; }
.ms-eq.picking .ms-seg.off.slot {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.055);
  outline: 1px dashed rgba(255, 209, 102, 0.55);
  outline-offset: -1px;
}
.ms-seg.picked {
  filter: brightness(1.2);
  box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(255, 209, 102, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.ms-seg.hint {
  animation: msHint 0.7s ease-in-out infinite alternate;
}
.ms-eq.bad .ms-seg.on {
  box-shadow: 0 0 0 1px rgba(255, 92, 108, 0.4), 0 0 12px rgba(255, 92, 108, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.ms-tip {
  flex: none;
  min-height: 20px;
  font-size: 11.5px;
  color: var(--faint);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ------------------------------ 操作按钮 ------------------------------ */

.ms-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  flex: none;
}
.ms-controls .btn {
  min-height: 44px;
  padding: 8px 4px;
  font-size: 12.5px;
  font-weight: 600;
}
.ms-foot {
  flex: none;
  min-height: 18px;
  text-align: center;
  font-size: 10.5px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------ 开始页 ------------------------------ */

.ms-start { gap: 12px; }
.ms-startp { display: flex; flex-direction: column; }
.ms-progress-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.ms-progress-k { font-size: 11px; color: var(--faint); letter-spacing: 0.03em; }
.ms-progress-v {
  margin-top: 3px;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ms-progress-v b { font-size: 22px; color: var(--accent); font-weight: 800; margin: 0 1px; }
.ms-next { font-size: 10.5px; color: var(--faint); text-align: right; line-height: 1.6; }
.ms-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 12px;
}
.ms-dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: transparent;
  display: block;
}
.ms-dots i.done {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 45%, transparent);
}
.ms-dots i.cur {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}
.ms-progress-bar { margin-top: 10px; }
.ms-best {
  margin-top: 10px;
  text-align: center;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.ms-best b { color: var(--text); font-weight: 700; }
.ms-start-btn { margin-top: 14px; min-height: 48px; }
.ms-foot.hint { margin-top: auto; padding-top: 8px; text-align: center; font-size: 11px; }

/* ------------------------------ 结算 ------------------------------ */

.ms-resultwrap { gap: 12px; }
.ms-result {
  flex: none;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--ok) 32%, var(--line));
  background: linear-gradient(165deg,
      color-mix(in srgb, var(--ok) 11%, transparent),
      rgba(255, 255, 255, 0.02));
  padding: 13px var(--pad) 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  animation: msUp 0.32s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}
.ms-result-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.ms-result-k {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.04em;
}
.ms-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  flex: none;
}
.ms-result-time {
  margin-top: 3px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.ms-result-meta {
  text-align: right;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.ms-best-t { color: var(--dim); }
.ms-best-t.new { color: var(--ok); font-weight: 700; }
.ms-result-eq {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.ms-req-old {
  font-size: 18px;
  font-weight: 700;
  color: var(--faint);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--faint) 70%, transparent);
}
.ms-req-arrow { font-size: 14px; color: var(--faint); }
.ms-req-new { font-size: 22px; font-weight: 800; color: var(--ok); letter-spacing: 0.01em; }
.ms-result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.ms-rstat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
}
.ms-rstat b {
  display: block;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.ms-rstat span { font-size: 9.5px; color: var(--faint); }
.ms-result-count {
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.ms-result-count b { color: var(--accent); font-size: 17px; font-weight: 800; margin: 0 1px; }
.ms-result-bar .progress { height: 5px; }
.ms-result .btn-row .btn { min-height: 44px; }
.ms-result-sub { display: flex; }
.ms-result-sub .btn { flex: 1; }

/* ------------------------------ 动画 ------------------------------ */

@keyframes msHint {
  from { box-shadow: 0 0 0 1px var(--accent), 0 0 8px rgba(255, 209, 102, 0.3); }
  to { box-shadow: 0 0 0 2px var(--accent), 0 0 20px rgba(255, 209, 102, 0.65); }
}
@keyframes msUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------ 小屏 / 矮屏适配 ------------------------------ */

@media (max-height: 710px) {
  .g-matchstick { gap: 8px; }
  .ms-hud { min-height: 26px; }
  .ms-controls .btn { min-height: 42px; }
  .ms-start { gap: 10px; }
  .ms-start .panel { padding: 12px; }
  .ms-start-btn { margin-top: 10px; }
  .ms-foot.hint { display: none; }
  .ms-dots { margin-top: 9px; }
  .ms-result { padding: 11px var(--pad) 12px; gap: 9px; }
  .ms-result-time { font-size: 26px; }
}

@media (max-width: 365px) {
  .g-matchstick { gap: 8px; }
  .ms-controls .btn { font-size: 12px; }
  .ms-hints,
  .ms-attempts { font-size: 10.5px; }
  .ms-dots { gap: 3px; }
  .ms-dots i { width: 7px; height: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .ms-seg.hint { animation: none; box-shadow: 0 0 0 2px var(--accent); }
  .ms-result { animation: none; }
}
