:root {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #5d6878;
  --paper: #f3efe6;
  --card: #fffdf8;
  --brass: #a56b2a;
  --brass-deep: #6e4314;
  --pine: #1f4d45;
  --ball: #f4e2b0;
  --line: rgba(28, 36, 48, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  background:
    radial-gradient(ellipse at top, #fff 0%, transparent 42%),
    var(--paper);
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 8px;
}

.eyebrow {
  margin: 0;
  color: var(--brass-deep);
  letter-spacing: 0.16em;
  font-size: 12px;
}

h1, h2 { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.03em; }
h2 { font-size: 18px; }

.back {
  color: var(--pine);
  font-weight: 700;
  text-decoration: none;
}

.clock {
  min-width: 96px;
  padding: 8px 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(240px, 0.7fr);
  gap: 22px;
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px 0 48px;
}

.play, aside section, .dlg {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.play { padding: 22px 22px 28px; }

.rule, .hint, .mine {
  color: var(--muted);
  line-height: 1.6;
}

.status {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.chances {
  margin: 4px 0 14px;
  color: var(--pine);
  font-weight: 700;
}

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 64px;
  padding: 12px;
  background: #f7f1e4;
  border-radius: 16px;
}

.ball, .choices button, .actions button, .dlg button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.ball {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: var(--brass-deep);
  font-weight: 800;
  background:
    radial-gradient(circle at 35% 30%, #fff 0%, var(--ball) 42%, #d7b56a 100%);
  box-shadow: inset 0 -4px 6px rgba(110, 67, 20, 0.25), 0 4px 8px rgba(80, 50, 10, 0.12);
}

.ball.selected {
  outline: 3px solid var(--pine);
  outline-offset: 2px;
}

.ball.on-pan { width: 36px; height: 36px; font-size: 14px; }

.scale-wrap {
  position: relative;
  height: 280px;
  margin-top: 8px;
}

.scale { width: 100%; height: 250px; overflow: visible; }
.beam, .string, .post { stroke: var(--brass-deep); stroke-width: 4; stroke-linecap: round; }
#beam, #panL, #panR, #strL1, #strL2, #strR1, #strR2 { transition: transform 0.45s ease; }
.scale-wrap.gt #beam { transform: rotate(-8deg); transform-origin: 320px 78px; }
.scale-wrap.gt #panL, .scale-wrap.gt #strL1, .scale-wrap.gt #strL2 { transform: translateY(22px); }
.scale-wrap.gt #panR, .scale-wrap.gt #strR1, .scale-wrap.gt #strR2 { transform: translateY(-18px); }
.scale-wrap.lt #beam { transform: rotate(8deg); transform-origin: 320px 78px; }
.scale-wrap.lt #panL, .scale-wrap.lt #strL1, .scale-wrap.lt #strL2 { transform: translateY(-18px); }
.scale-wrap.lt #panR, .scale-wrap.lt #strR1, .scale-wrap.lt #strR2 { transform: translateY(22px); }
.fulcrum, .pivot { fill: var(--brass); }
.pan { fill: #efe6d4; stroke: var(--brass-deep); stroke-width: 3; }
.beam { transition: transform 0.45s ease; transform-origin: 320px 78px; }
.pan, .string { transition: transform 0.45s ease; }

.pan-hit {
  position: absolute;
  top: 96px;
  width: 28%;
  height: 70px;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.pan-hit.left { left: 6%; }
.pan-hit.right { right: 6%; }

.pan-balls {
  position: absolute;
  top: 78px;
  display: flex;
  gap: 4px;
  width: 26%;
  min-height: 40px;
  pointer-events: none;
}
.pan-balls.left { left: 7%; justify-content: center; }
.pan-balls.right { right: 7%; justify-content: center; }
.pan-balls .ball { pointer-events: auto; }

.scale-wrap.gt .beam { transform: rotate(-8deg); }
.scale-wrap.lt .beam { transform: rotate(8deg); }
.scale-wrap.gt .pan-balls.left,
.scale-wrap.lt .pan-balls.right { transform: translateY(22px); }
.scale-wrap.gt .pan-balls.right,
.scale-wrap.lt .pan-balls.left { transform: translateY(-18px); }

.result {
  min-height: 1.4em;
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--pine);
}

.actions { display: flex; justify-content: center; gap: 10px; margin: 8px 0 16px; }

.actions button, .choices button, .dlg button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: #efe8da;
  color: var(--ink);
}

.primary {
  background: var(--pine);
  color: #fff;
  font-weight: 700;
}

.primary:disabled,
button:disabled {
  opacity: 0.45;
  cursor: default;
}

.history {
  margin: 0;
  padding-left: 1.2em;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

.quiz {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.choices { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.choices button.picked { background: var(--brass); color: #fff; }
.ans { min-height: 1.2em; font-weight: 700; }

aside { display: flex; flex-direction: column; gap: 14px; }
aside section { padding: 16px 18px 18px; }
aside ol { margin: 8px 0 0; padding-left: 1.2em; line-height: 1.7; }
aside li span { color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(28, 36, 48, 0.35);
}
.modal[hidden] { display: none; }
.dlg { width: min(440px, 100%); padding: 22px; }
.dlg p { line-height: 1.6; }
.dlg label { display: block; font-weight: 700; }
.dlg input {
  width: 100%;
  height: 44px;
  margin-top: 6px;
  padding: 0 12px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.dlg-actions { display: flex; gap: 8px; margin-top: 14px; }

@media (max-width: 800px) {
  .top, main { width: min(100% - 20px, 1100px); }
  .top { align-items: flex-start; flex-wrap: wrap; }
  main { grid-template-columns: 1fr; }
  .pan-hit { height: 64px; }
}
