:root {
  --ink: #2c2340;
  --muted: #756d83;
  --cream: #fffaf0;
  --yellow: #ffc94a;
  --coral: #ff6d6a;
  --violet: #745be8;
  --mint: #83dfc2;
  --panel: rgba(255, 255, 255, 0.82);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  background: #efe9ff;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button, select { font: inherit; }
button { border: 0; cursor: pointer; touch-action: manipulation; }
.app {
  width: 100%;
  max-width: 540px;
  height: 100%;
  min-height: 560px;
  margin: 0 auto;
  padding: 12px 14px 10px;
  padding-top: calc(12px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  padding-right: 14px;
  padding-bottom: calc(10px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  padding-left: 14px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 88% 8%, rgba(255, 201, 74, .7), transparent 22%),
    radial-gradient(circle at 12% 52%, rgba(131, 223, 194, .45), transparent 26%),
    linear-gradient(160deg, #fff8e7 0%, #eee8ff 54%, #ffe9ed 100%);
}
.topbar { height: 58px; display: flex; align-items: center; justify-content: space-between; }
.eyebrow { font-size: 10px; letter-spacing: 2.4px; color: var(--violet); font-weight: 800; }
h1 { font-size: 24px; line-height: 1.1; letter-spacing: -.5px; }
.score-box { min-width: 78px; padding: 7px 12px; border: 1px solid rgba(44, 35, 64, .1); border-radius: 16px; background: var(--panel); text-align: right; box-shadow: 0 8px 24px rgba(83, 62, 121, .1); }
.score-box span { display: block; font-size: 10px; color: var(--muted); }
.score-box strong { font-size: 21px; }
.divination-hud { min-height: 80px; display: grid; grid-template-columns: 1fr 190px; grid-gap: 10px; align-items: center; padding: 5px 0 7px; }
.line-status { display: grid; grid-gap: 2px; }
.line-status > b { font-size: 14px; }
.line-status > span { color: var(--muted); font-size: 11px; }
.ball-tray { height: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-gap: 3px; margin-top: 3px; }
.ball-tray i { width: auto; min-width: 0; height: 22px; border: 0; outline: 0; border-radius: 7px; box-shadow: none; color: var(--ink); font-size: 8px; font-style: normal; font-weight: 900; display: grid; align-items: center; justify-items: center; opacity: .38; transition: transform .18s ease, opacity .18s ease; }
.ball-tray i.active { opacity: .72; transform: translateY(-1px); }
.ball-tray i.done { opacity: 1; box-shadow: inset 0 0 0 1px rgba(44,35,64,.15); }
.line-stack { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 3px; }
.line-stack li { min-height: 27px; padding: 3px 5px; border-left: 3px solid transparent; border-radius: 7px; background: rgba(255,255,255,.52); display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 9px; }
.line-stack li > * + * { margin-left: 4px; }
.line-stack li b { color: var(--ink); font-size: 10px; white-space: nowrap; }
.line-stack li.active { box-shadow: inset 0 0 0 1px var(--violet); background: rgba(116,91,232,.09); }
.line-stack li.done { background: rgba(131,223,194,.18); }
.board-shell { position: relative; flex: 1; min-height: 390px; overflow: hidden; border-radius: 28px; border: 1px solid rgba(255,255,255,.9); background: rgba(255,255,255,.46); box-shadow: 0 18px 50px rgba(83, 62, 121, .15), inset 0 0 0 1px rgba(44,35,64,.05); touch-action: none; }
#gameCanvas { display: block; width: 100%; height: 100%; }
.drop-rail { position: absolute; left: 7px; right: 7px; top: 22px; height: 4px; border-radius: 4px; background: transparent; pointer-events: none; }
.drop-rail i { position: absolute; top: -6px; left: 50%; width: 16px; height: 16px; margin-left: -8px; border: 0; outline: 0; border-radius: 50%; background: var(--coral); box-shadow: none; }
.primary { color: white; background: linear-gradient(135deg, #745be8, #9b6bf0); box-shadow: 0 8px 18px rgba(116,91,232,.28); }
.secondary { color: var(--ink); background: rgba(255,255,255,.78); border: 1px solid rgba(44,35,64,.1); }
button:disabled { opacity: .55; box-shadow: none; }
.physics-panel { position: fixed; z-index: 4; right: 12px; top: 12px; top: calc(12px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px))); width: 300px; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow-y: auto; border: 1px solid rgba(44,35,64,.16); border-radius: 14px; background: rgba(255,250,240,.94); box-shadow: 0 10px 30px rgba(44,35,64,.18); color: var(--ink); font-size: 12px; }
.physics-panel summary { padding: 9px 12px; cursor: pointer; font-weight: 800; }
.physics-panel:not([open]) { width: auto; max-width: 120px; overflow: hidden; }
.physics-fields { padding: 0 12px 12px; display: grid; grid-gap: 10px; }
.physics-fields label { display: grid; grid-template-columns: 1fr 58px; grid-gap: 4px 8px; align-items: center; }
.physics-fields label span { grid-column: 1 / -1; }
.physics-fields input[type="range"] { width: 100%; }
.physics-fields input[type="number"] { width: 58px; height: 28px; border: 1px solid rgba(44,35,64,.18); border-radius: 7px; background: white; color: var(--ink); text-align: center; }
.geometry-readout, .batch-readout { display: grid; grid-gap: 4px; padding: 8px; border-radius: 8px; background: rgba(116,91,232,.07); }
.geometry-readout div, .batch-readout div { display: flex; justify-content: space-between; }
.geometry-readout dt, .batch-readout dt { color: var(--muted); }
.geometry-readout dd, .batch-readout dd { margin: 0 0 0 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.physics-fields button { height: 30px; border-radius: 8px; color: var(--ink); background: rgba(116,91,232,.1); font-weight: 700; }
.modal { position: fixed; z-index: 5; top: 0; right: 0; bottom: 0; left: 0; padding: 18px; padding-top: calc(18px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px))); padding-bottom: calc(18px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); background: rgba(31,24,46,.62); display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card { position: relative; width: 100%; max-width: 410px; max-height: 100%; overflow: auto; padding: 20px; border-radius: 26px; background: var(--cream); box-shadow: 0 28px 80px rgba(20,12,40,.35); }
.modal-card h2 { margin: 0 34px 12px 0; font-size: 20px; }
.close { position: absolute; right: 15px; top: 14px; width: 34px; height: 34px; border-radius: 50%; color: var(--ink); background: rgba(44,35,64,.08); font-size: 24px; line-height: 30px; }
#shareCanvas { display: block; width: 100%; height: auto; border-radius: 18px; box-shadow: 0 8px 24px rgba(83,62,121,.14); }
.classic-text { display: grid; grid-gap: 7px; margin-bottom: 12px; -webkit-user-select: text; user-select: text; }
.classic-text details { border: 1px solid rgba(44,35,64,.1); border-radius: 10px; background: rgba(255,255,255,.56); }
.classic-text summary { padding: 8px 10px; cursor: pointer; font-size: 12px; font-weight: 800; }
.classic-text p, .classic-text ol { margin: 0; padding: 0 11px 10px; color: #554b65; font-size: 12px; line-height: 1.65; }
.classic-text ol { padding-left: 30px; }
.classic-text li { margin-bottom: 5px; }
.classic-text li b { margin-right: 7px; color: var(--violet); }
.classic-text .no-moving { padding: 9px 11px; border-radius: 10px; background: rgba(131,223,194,.16); color: var(--ink); font-weight: 800; }
.classic-text .source-note { margin-top: 2px; padding: 9px 10px; border-radius: 9px; background: rgba(116,91,232,.06); color: #655b74; font-size: 11.5px; line-height: 1.65; }
.hexagram-summary { display: grid; grid-template-columns: 1fr auto 1fr; grid-gap: 8px; align-items: center; margin: 0 0 12px; padding: 12px; border-radius: 14px; background: rgba(116,91,232,.08); text-align: center; }
.hexagram-summary b { display: block; font-size: 17px; }
.hexagram-summary span { color: var(--muted); font-size: 11px; }
.hexagram-summary .arrow { color: var(--violet); font-size: 20px; }
.hexagram-summary p { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; grid-gap: 9px; margin-top: 12px; }
.modal-actions button { height: 48px; border-radius: 16px; font-weight: 750; }
@media (max-width: 600px) {
  .physics-panel { display: none; }
  .divination-hud { grid-template-columns: 1fr 176px; }
}
@media (max-height: 650px) {
  .app { min-height: 0; }
  .topbar { height: 48px; }
  h1 { font-size: 20px; }
  .board-shell { min-height: 0; }
}
