.ball-solver-page {
  --ball-accent: #7c3aed;
  --ball-accent-strong: #5b21b6;
  --ball-warm: #f59e0b;
}
.ball-solver-page .page-hero { position: relative; padding-bottom: 30px; }
.ball-solver-page .page-hero h1 { max-width: 820px; }
.ball-rule-note {
  max-width: 860px;
  margin: 18px 0 0;
  border: 1px solid rgba(124, 58, 237, .2);
  border-left: 5px solid var(--ball-accent);
  border-radius: 14px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(245, 241, 255, .96), rgba(255, 248, 235, .94));
  color: #45365f;
  box-shadow: 0 10px 28px rgba(76, 48, 137, .08);
}
.ball-rule-note strong,
.ball-rule-note a { color: var(--ball-accent-strong); font-weight: 800; }
.ball-solver-layout {
  display: grid;
  grid-template-columns: minmax(0, .92fr) minmax(420px, 1.08fr);
  gap: 22px;
  align-items: start;
}
.ball-solver-page .tool-section {
  border-color: rgba(124, 58, 237, .16);
  border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(63, 45, 112, .09);
}
.ball-solver-page .solver-textarea {
  min-height: 250px;
  border-color: #d8cdf7;
  background: #fdfcff;
  line-height: 1.55;
  resize: vertical;
}
.ball-solver-page .solver-textarea:focus { outline: 3px solid rgba(124, 58, 237, .16); border-color: var(--ball-accent); }
.ball-solver-page .tool-actions { margin-top: 14px; }
.ball-solver-page .tool-actions .button,
.ball-solver-page #ball-play-btn {
  background: linear-gradient(135deg, var(--ball-accent), var(--ball-accent-strong));
  color: #fff;
  border: 0;
}
.ball-solver-page #ball-cancel-btn { border-color: #f1b7ae; background: #fff2f0; color: #a43a2b; }
.ball-solver-page [hidden] { display: none !important; }
.ball-tube-preview {
  min-height: 310px;
  overflow: hidden;
  border: 1px solid rgba(124, 58, 237, .18);
  border-radius: 18px;
  padding: 20px 16px 26px;
  background: radial-gradient(circle at 12% 10%, rgba(245, 158, 11, .13), transparent 14rem), linear-gradient(180deg, #fbfaff, #f2eeff);
}
.ball-tube-rack {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: end;
  gap: 18px 14px;
  padding: 8px 8px 22px;
}
.ball-tube-rack::after {
  content: "";
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: 7px;
  height: 12px;
  border-radius: 8px;
  background: linear-gradient(180deg, #d7c3a5, #a98559);
  box-shadow: 0 8px 13px rgba(91, 61, 30, .18);
}
.ball-tube-card { position: relative; z-index: 1; width: 76px; display: grid; justify-items: center; gap: 8px; }
.ball-tube {
  position: relative;
  width: 68px;
  height: 224px;
  border: 3px solid rgba(80, 66, 125, .72);
  border-top: 0;
  border-radius: 0 0 25px 25px;
  padding: 13px 8px 10px;
  background: linear-gradient(90deg, rgba(255,255,255,.7), rgba(255,255,255,.2) 45%, rgba(124,58,237,.04));
  box-shadow: inset 8px 0 12px rgba(255,255,255,.68), 0 12px 22px rgba(55, 42, 96, .11);
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.ball-tube::before {
  content: "";
  position: absolute;
  left: -7px;
  right: -7px;
  top: -5px;
  height: 10px;
  border: 3px solid rgba(80, 66, 125, .72);
  border-radius: 50%;
  background: rgba(255,255,255,.72);
}
.ball-tube-slots { height: 100%; display: flex; flex-direction: column-reverse; justify-content: flex-start; gap: 4px; }
.ball-slot { min-height: 43px; display: grid; place-items: center; }
.sort-ball {
  position: relative;
  width: 43px;
  height: 43px;
  display: block;
  border: 2px solid rgba(35, 31, 55, .18);
  border-radius: 50%;
  background: radial-gradient(circle at 31% 23%, rgba(255,255,255,.95) 0 7%, rgba(255,255,255,.32) 8% 20%, transparent 21%), var(--ball-color);
  box-shadow: inset -6px -8px 11px rgba(38, 24, 68, .18), 0 3px 5px rgba(48, 32, 80, .22);
}
.ball-solver-page button.sort-ball {
  min-width: 0;
  padding: 0;
  display: block;
  border: 2px solid rgba(35, 31, 55, .18);
  border-radius: 50%;
  background: radial-gradient(circle at 31% 23%, rgba(255,255,255,.95) 0 7%, rgba(255,255,255,.32) 8% 20%, transparent 21%), var(--ball-color) !important;
  color: transparent;
  cursor: pointer;
  appearance: none;
}
.ball-solver-page button.sort-ball:hover { transform: scale(1.06); }
.ball-solver-page button.sort-ball:focus-visible {
  outline: 3px solid rgba(124, 58, 237, .42);
  outline-offset: 2px;
}
.sort-ball.is-selected-color {
  box-shadow: inset -6px -8px 11px rgba(38, 24, 68, .18), 0 3px 5px rgba(48, 32, 80, .22), 0 0 0 5px rgba(124, 58, 237, .26);
}
.ball-tube-label { color: #55496c; font-size: .86rem; white-space: nowrap; }
.ball-tube-card.is-source .ball-tube {
  border-color: var(--ball-accent);
  box-shadow: 0 0 0 5px rgba(124, 58, 237, .12), 0 13px 24px rgba(77, 45, 139, .14);
  transform: translateY(-3px);
}
.ball-tube-card.is-source .ball-tube::before { border-color: var(--ball-accent); }
.ball-tube-card.is-target .ball-tube {
  border-color: var(--ball-warm);
  box-shadow: 0 0 0 5px rgba(245, 158, 11, .15), 0 13px 24px rgba(125, 78, 20, .14);
}
.ball-tube-card.is-target .ball-tube::before { border-color: var(--ball-warm); }
.sort-ball.is-current-ball { outline: 4px solid rgba(245, 158, 11, .28); animation: ball-arrive .36s ease-out; }
@keyframes ball-arrive {
  from { transform: translateY(-18px) scale(.9); opacity: .35; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.ball-palette-help { margin: -6px 0 12px; color: #655779; font-size: .9rem; }
.ball-color-ids-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ball-color-id,
.ball-count-row span { display: inline-flex; gap: 8px; align-items: center; }
.ball-color-id {
  border: 1px solid #ded6f2;
  border-radius: 999px;
  padding: 7px 10px;
  background: #fff;
  color: #4f4267;
  font-size: .9rem;
  font-weight: 750;
}
.ball-solver-page button.ball-color-id {
  width: auto;
  background: #fff;
  color: #4f4267;
  border: 1px solid #ded6f2;
  cursor: pointer;
}
.ball-solver-page button.ball-color-id:hover,
.ball-solver-page button.ball-color-id:focus-visible {
  border-color: var(--ball-accent);
  background: #f7f3ff;
  outline: none;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .12);
}
.ball-color-id i,
.ball-count-row i {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex: 0 0 18px;
  border: 1px solid rgba(35, 31, 55, .2);
  border-radius: 50%;
  box-shadow: inset -2px -3px 4px rgba(35,31,55,.14);
}
.ball-solver-page details { margin-top: 14px; border: 1px solid #e1daf2; border-radius: 13px; padding: 11px 13px; background: rgba(255,255,255,.78); }
.ball-solver-page summary { cursor: pointer; color: #4a3b68; font-weight: 800; }
.ball-count-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; border-radius: 10px; padding: 9px 10px; background: #f5f7fb; }
.ball-count-row.is-valid strong { color: #087b69; }
.ball-count-row.is-invalid { background: #fff2f0; }
.ball-count-row.is-invalid strong { color: #ae3526; }
.ball-solver-page .solver-message { min-height: 1.6em; white-space: pre-line; }
.ball-solver-page .solver-message.is-success { color: #087b69; }
.ball-solver-page .solver-message.is-error { color: #b03225; }
.ball-solver-page .solver-message.is-warning { color: #9a5b07; }
.ball-solver-page .solver-message.is-working { color: var(--ball-accent-strong); }
.ball-color-popover {
  position: fixed;
  z-index: 1000;
  width: min(276px, calc(100vw - 24px));
  border: 1px solid #d9cff3;
  border-radius: 16px;
  padding: 15px;
  background: #fff;
  color: #302544;
  box-shadow: 0 20px 55px rgba(45, 28, 83, .24);
}
.ball-color-popover h3 { margin: 0; font-size: 1rem; }
.ball-color-popover p { margin: 3px 0 12px; color: #6d607f; font-size: .84rem; }
.ball-color-popover-input {
  width: 100%;
  height: 38px;
  margin-bottom: 12px;
  border: 1px solid #ded6f2;
  border-radius: 9px;
  padding: 3px;
  background: #fff;
  cursor: pointer;
}
.ball-color-popover-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
button.ball-color-swatch {
  width: 32px;
  height: 32px;
  min-width: 0;
  padding: 0 !important;
  border: 2px solid #fff !important;
  border-radius: 50% !important;
  box-shadow: 0 0 0 1px rgba(45, 35, 68, .22);
}
button.ball-color-swatch:hover,
button.ball-color-swatch:focus-visible {
  outline: 3px solid rgba(124, 58, 237, .28);
  outline-offset: 1px;
}
.ball-share-popover {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 13, 38, .58);
  backdrop-filter: blur(3px);
}
.ball-share-popover[hidden] { display: none; }
.ball-share-panel {
  width: min(610px, 100%);
  border: 1px solid #d9cff3;
  border-radius: 20px;
  padding: 22px;
  background: #fff;
  color: #302544;
  box-shadow: 0 28px 80px rgba(24, 15, 47, .34);
}
.ball-share-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.ball-share-head h3 { margin: 0; font-size: 1.35rem; }
.ball-share-head p { margin: 5px 0 0; color: #655779; font-size: .92rem; }
button.ball-share-close {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0 !important;
  border-radius: 50% !important;
  font-size: 1.35rem;
  line-height: 1;
}
.ball-share-label { display: block; margin-bottom: 7px; font-size: .88rem; font-weight: 800; }
.ball-share-input {
  width: 100%;
  min-width: 0;
  border: 1px solid #cabeea;
  border-radius: 11px;
  padding: 12px 13px;
  background: #faf8ff;
  color: #493a64;
  font: inherit;
}
.ball-share-input:focus { outline: 3px solid rgba(124, 58, 237, .2); border-color: var(--ball-accent); }
.ball-share-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.ball-share-actions > * {
  min-height: 44px;
  flex: 1 1 130px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.ball-share-status { min-height: 1.35em; margin: 12px 0 0; color: #087b69; font-size: .9rem; }
.ball-solution-section {
  border-top: 4px solid rgba(124, 58, 237, .72) !important;
  padding: clamp(24px, 3vw, 34px) !important;
  overflow: hidden;
}
.ball-step-player { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(260px, .8fr); gap: 18px; align-items: start; }
.ball-step-player,
.ball-replay-preview,
.ball-move-list { overflow-anchor: none; }
.ball-step-main,
.ball-step-list-panel { min-width: 0; }
.ball-step-list-panel {
  border-left: 1px solid #e5def4;
  padding-left: 18px;
}
.ball-player-status { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 10px; }
.ball-step-progress { color: var(--ball-accent-strong); font-weight: 850; }
.ball-current-move { min-height: 58px; margin: 12px 0; border-radius: 13px; padding: 12px 14px; background: #f5f1ff; color: #493a64; font-weight: 750; }
.ball-player-controls { display: flex; flex-wrap: wrap; gap: 9px; }
.ball-player-controls button { flex: 1 1 110px; }
.ball-move-list {
  max-height: 500px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 7px;
  padding: 2px;
}
.ball-move-row {
  width: 100%;
  min-height: 0;
  display: block;
  border: 1px solid #e1daf2 !important;
  border-radius: 11px !important;
  padding: 10px 11px !important;
  background: #fff !important;
  color: #4b4162 !important;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: .01em;
}
.ball-move-row.is-active { border-color: var(--ball-accent) !important; background: #f5f1ff !important; box-shadow: 0 0 0 3px rgba(124, 58, 237, .12); }
.ball-solution-output {
  min-height: 112px;
  max-height: 270px;
  margin-bottom: 16px;
  overflow: auto;
  white-space: pre-wrap;
  border-color: rgba(124, 58, 237, .22);
  background: #fdfcff;
}
.ball-direction-note { display: flex; gap: 12px; align-items: center; margin: 10px 0 16px; color: #5e5075; font-size: .92rem; }
.ball-direction-note::before {
  content: "↑";
  width: 34px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  border: 2px solid #9a86cb;
  border-top: 0;
  border-radius: 0 0 12px 12px;
  color: var(--ball-accent);
  font-size: 1.4rem;
  font-weight: 900;
}
@media (max-width: 940px) {
  .ball-solver-layout,
  .ball-step-player { grid-template-columns: 1fr; }
  .ball-step-list-panel {
    border-left: 0;
    border-top: 1px solid #e5def4;
    padding: 18px 0 0;
  }
  .ball-move-list { max-height: 320px; }
}
@media (max-width: 560px) {
  .ball-solver-page .page-hero { padding-top: 30px; }
  .ball-solution-section { padding: 18px 14px !important; }
  .ball-share-popover { padding: 12px; }
  .ball-share-panel { border-radius: 16px; padding: 17px; }
  .ball-solver-page .page-hero h1 { font-size: clamp(2.25rem, 13vw, 3rem); }
  .ball-rule-note { padding: 12px 13px; }
  .ball-solver-page .tool-actions > * { flex: 1 1 145px; }
  .ball-tube-preview { min-height: 250px; padding-inline: 7px; }
  .ball-tube-rack { gap: 14px 6px; padding-inline: 2px; }
  .ball-tube-card { width: 61px; }
  .ball-tube { width: 55px; height: 188px; padding: 11px 6px 8px; border-width: 2px; }
  .ball-tube::before { left: -6px; right: -6px; border-width: 2px; }
  .ball-slot { min-height: 37px; }
  .sort-ball { width: 37px; height: 37px; }
  .ball-tube-label { font-size: .75rem; }
  .ball-player-status { align-items: start; flex-direction: column; }
  .ball-current-move { font-size: .92rem; }
}
@media (prefers-reduced-motion: reduce) {
  .ball-tube,
  .sort-ball.is-current-ball { transition: none; animation: none; }
}


