:root {
  --paper: #f2ede3;
  --ink: #2a2926;
  --soft: #716b60;
  --hair: rgba(42, 41, 38, .15);
  --card: rgba(250, 247, 240, .9);
  --accent: #c9563c;
  --gold: #d1a54a;
  --panel-w: 316px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Songti SC", "Noto Serif CJK SC", Georgia, serif;
  --sans: -apple-system, "Helvetica Neue", "PingFang SC", "Hiragino Sans", "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 12px; -webkit-font-smoothing: antialiased; }
#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }
body.photo #ui, body.photo #labels { display: none; }
#photoExit { position: fixed; right: 14px; top: 14px; opacity: .55; z-index: 5; }
button { font: inherit; color: inherit; }

/* ---------- title */
#title { position: absolute; left: 28px; top: 22px; max-width: 310px; pointer-events: none !important; }
.kicker, .kick { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--soft); }
.kicker { margin-bottom: 7px; }
#title h1 { font-family: var(--serif); font-weight: 500; font-size: 29px; line-height: 1.06; margin: 0 0 8px; letter-spacing: -.01em; }
#title p { margin: 0; color: var(--soft); font-size: 12px; line-height: 1.5; border-top: 1px solid var(--hair); padding-top: 8px; }

/* ---------- scorecard */
#score { position: absolute; right: 16px; top: 16px; width: var(--panel-w); background: var(--card); border: 1px solid var(--hair); border-radius: 14px; padding: 9px 14px 8px; backdrop-filter: blur(6px); }
.sc-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.sc-row .chip, .chip { display: inline-block; width: 10px; height: 14px; border-radius: 2px; border: 2px solid transparent; flex: none; margin-right: 4px; vertical-align: -2px; }
.sc-row .nm { flex: 1; font-family: var(--serif); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-row.poss .nm::after { content: " ◂"; color: var(--accent); font-size: 11px; }
.sc-row .meta { font-size: 9px; color: var(--soft); letter-spacing: .05em; white-space: nowrap; }
.sc-row .meta .to { color: var(--gold); letter-spacing: 0; }
.sc-row .meta .bonus { color: #fff; background: var(--accent); border-radius: 999px; padding: 0 5px; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.sc-row .pts { font-family: var(--serif); font-size: 22px; font-weight: 500; min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.sc-clock { display: flex; align-items: baseline; gap: 10px; border-top: 1px solid var(--hair); margin-top: 5px; padding-top: 5px; font-variant-numeric: tabular-nums; }
.sc-clock .per { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--soft); }
.sc-clock .clk { font-size: 15px; font-weight: 600; flex: 1; }
.sc-clock .shot em { font-style: normal; font-size: 9px; letter-spacing: .14em; text-transform: uppercase; color: var(--soft); margin-right: 5px; }
.sc-clock .shot b { display: inline-block; min-width: 24px; text-align: center; color: #fff; background: #3a3631; border-radius: 6px; padding: 1px 5px; font-size: 13px; }
.sc-clock .shot b:empty { background: transparent; }
.sc-clock .shot b.low { background: #d8452f; }

#badge { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); background: var(--ink); color: var(--paper); border-radius: 999px; padding: 5px 14px; font-size: 10px; letter-spacing: .2em; text-transform: uppercase; pointer-events: none !important; }

/* ---------- ticker */
#ticker { position: absolute; left: 28px; bottom: 72px; width: 320px; pointer-events: none !important; }
#ticker .tl { padding: 4px 0; border-top: 1px solid var(--hair); color: var(--soft); font-size: 11.5px; line-height: 1.38; transition: opacity .4s; }
#ticker .tl:last-child { color: var(--ink); font-family: var(--serif); font-size: 14.5px; }
#ticker .tt { font-family: var(--sans); font-size: 9.5px; letter-spacing: .06em; color: var(--soft); margin-right: 7px; font-variant-numeric: tabular-nums; }

/* ---------- pills, switches and controls */
.pills { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 8px; }
.pills.grid .pill { flex: 0 1 auto; }
.pills.big .pill { font-size: 12.5px; padding: 6px 13px; font-family: var(--serif); }
.pill { font-size: 11px; color: var(--ink); background: var(--card); border: 1px solid var(--hair); border-radius: 999px; padding: 5px 11px; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s, border-color .15s; }
.pill:hover { border-color: var(--ink); }
.pill.on, .pill.solid { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pill.round { width: 26px; height: 26px; padding: 0; text-align: center; }
.pill:disabled { opacity: .4; cursor: default; }
.pill.sit:active { background: var(--accent); color: #fff; }
.ctl { display: flex; align-items: center; flex-wrap: wrap; gap: 3px 8px; margin: 8px 0; }
.ctl .lab { flex: 1; color: var(--soft); font-size: 11px; }
.ctl .val { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink); }
.ctl input[type=range] { flex: 0 0 100%; accent-color: var(--ink); height: 16px; margin: 0; }
.ctl input.text { flex: 0 0 100%; font: inherit; border: 0; border-bottom: 1px solid var(--hair); background: transparent; padding: 3px 0; color: var(--ink); font-family: var(--serif); font-size: 15px; }
.ctl.col input[type=color] { width: 30px; height: 22px; padding: 0; border: 1px solid var(--hair); border-radius: 6px; background: none; cursor: pointer; }
.ctl.tog .val { order: 2; }
.switch { order: 3; width: 32px; height: 18px; border-radius: 999px; border: 1px solid var(--hair); background: #ddd6c9; position: relative; cursor: pointer; padding: 0; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--ink); }
.switch.on::after { left: 16px; }
.lab { color: var(--soft); font-size: 10.5px; margin: 6px 0 2px; }
.hint { color: var(--soft); font-size: 11px; line-height: 1.5; margin: 4px 0 8px; }
.warn { color: var(--accent); font-size: 11px; line-height: 1.45; margin: 6px 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
h4.sec { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--soft); font-weight: 500; margin: 14px 0 6px; padding-top: 9px; border-top: 1px solid var(--hair); }
.swatches { display: flex; gap: 6px; margin: -2px 0 8px; }
.sw { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--hair); cursor: pointer; padding: 0; }
.score-set { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-family: var(--serif); font-size: 13px; }
.score-set .num { width: 48px; font: inherit; text-align: center; border: 0; border-bottom: 1px solid var(--hair); background: transparent; color: var(--ink); }

/* ---------- bottom bar */
#bar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 4px; align-items: center; background: var(--card); border: 1px solid var(--hair); border-radius: 999px; padding: 5px 8px; backdrop-filter: blur(6px); max-width: calc(100vw - 24px); overflow-x: auto; scrollbar-width: none; }
body:not(.panel-closed) #bar { left: calc(50% - var(--panel-w) / 2 - 8px); max-width: calc(100vw - var(--panel-w) - 48px); }
#bar .grp { display: flex; gap: 3px; align-items: center; padding: 0 5px; border-left: 1px solid var(--hair); }
#bar .grp:first-child { border-left: 0; }
#bar .pills { margin: 0; flex-wrap: nowrap; gap: 2px; }
#bar .pill { border-color: transparent; background: transparent; padding: 5px 8px; }
#bar .pill:hover { border-color: var(--hair); }
#bar .pill.on, #bar .pill.solid { background: var(--ink); color: var(--paper); }
#bar .ctl.mini { margin: 0; width: 86px; flex-wrap: nowrap; gap: 4px; }
#bar .ctl.mini .lab { display: none; }
#bar .ctl.mini input { flex: 1; min-width: 0; }
#bar .ctl.mini .val { order: 2; font-size: 10px; color: var(--soft); width: 28px; }

/* ---------- panel */
#panel { position: absolute; right: 16px; top: 142px; bottom: 16px; width: var(--panel-w); background: var(--card); border: 1px solid var(--hair); border-radius: 16px; display: flex; flex-direction: column; backdrop-filter: blur(6px); transition: transform .25s; }
#panel.closed { transform: translateX(calc(100% + 16px)); }
#panelToggle { position: absolute; right: calc(100% + 8px); top: 0; }
#panel.closed #panelToggle { right: calc(100% + 24px); }
#tabs { display: flex; flex-wrap: wrap; gap: 3px; padding: 10px 12px 8px; border-bottom: 1px solid var(--hair); }
.tab { font-size: 10.5px; border: 1px solid transparent; background: transparent; border-radius: 999px; padding: 3px 9px; cursor: pointer; color: var(--soft); }
.tab:hover { color: var(--ink); border-color: var(--hair); }
.tab.on { background: var(--ink); color: var(--paper); }
#tabBody { flex: 1; overflow-y: auto; padding: 10px 16px 18px; scrollbar-width: thin; }
.roster { display: flex; flex-direction: column; }
.rp { display: flex; align-items: center; gap: 8px; border: 0; border-top: 1px solid var(--hair); background: transparent; text-align: left; padding: 5px 0; cursor: pointer; font-family: var(--serif); font-size: 13px; }
.rp .n { width: 24px; height: 18px; border-radius: 4px; font-family: var(--sans); font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.rp span:nth-child(2) { flex: 1; }
.rp em { font-style: normal; font-family: var(--sans); font-size: 10px; color: var(--soft); }
.rp.oncourt span:nth-child(2)::after { content: " ●"; color: #3f9b5a; font-size: 8px; vertical-align: 2px; }
.rp.gone { opacity: .45; }

/* stats */
.stats table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 11px; }
.stats th { font-weight: 500; color: var(--soft); font-size: 9.5px; letter-spacing: .05em; text-align: right; padding: 3px 4px; }
.stats td { text-align: right; padding: 3px 4px; border-top: 1px solid var(--hair); white-space: nowrap; }
.stats td:first-child, .stats th:first-child { text-align: left; }
.stats small { color: var(--soft); }
.stats .box tr.oc td:first-child { font-weight: 600; }
.scroll-x { overflow-x: auto; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-top: 1px solid var(--hair); padding: 4px 0; font-size: 11px; line-height: 1.4; }
.timeline li .tt { color: var(--soft); font-size: 9.5px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.timeline li.score { font-family: var(--serif); font-size: 12.5px; }
.timeline li.rp { cursor: pointer; }
.timeline li.rp:hover { color: var(--accent); }
.timeline li.foul, .timeline li.viol { color: var(--soft); }

/* ---------- cards */
#rulecard { position: absolute; left: 28px; top: 190px; width: 330px; background: var(--card); border: 1px solid var(--hair); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(6px); box-shadow: 0 6px 24px rgba(60,45,25,.08); }
.rc-body { display: flex; gap: 10px; }
.rc-sig { flex: 0 0 64px; }
.rc-text h3 { font-family: var(--serif); font-weight: 500; font-size: 18px; margin: 3px 0 5px; }
.rc-text .what { margin: 0 0 6px; color: var(--soft); font-style: italic; font-family: var(--serif); font-size: 13px; line-height: 1.4; }
.rc-text .rule { margin: 0; font-size: 12px; line-height: 1.5; }
.sets { border-top: 1px solid var(--hair); margin-top: 8px; padding-top: 4px; }
.sets p { margin: 4px 0; font-size: 11px; line-height: 1.45; color: var(--soft); }
.sets p.now { color: var(--ink); }
.sets b { font-weight: 600; font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; margin-right: 4px; }
.x { position: absolute; right: 8px; top: 6px; border: 0; background: transparent; font-size: 16px; cursor: pointer; color: var(--soft); }
svg.sig { width: 64px; height: 90px; }
svg.sig .sk { fill: #d9a47c; } svg.sig .shr { fill: #2a1d16; } svg.sig .st { fill: #a8a8a3; } svg.sig .ss { fill: #24242a; }
svg.sig .sl { fill: #24242a; }
svg.sig .sa, svg.sig .sf { stroke: #a8a8a3; stroke-width: 5.5; stroke-linecap: square; }
svg.sig .sf { stroke: #d9a47c; stroke-width: 5; }
svg.sig .sh { fill: #d9a47c; }
svg.sig .sg { font: 700 14px var(--sans); fill: var(--accent); text-anchor: middle; }
svg.sig .sx { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 3 2; }

#pcard { position: absolute; right: calc(var(--panel-w) + 40px); bottom: 72px; width: 290px; background: var(--card); border: 1px solid var(--hair); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(6px); box-shadow: 0 6px 24px rgba(60,45,25,.08); }
body.panel-closed #pcard { right: 16px; }
.pc-head { display: flex; gap: 10px; align-items: center; }
.pc-head .num { width: 38px; height: 38px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; }
.pc-head h3 { font-family: var(--serif); font-weight: 500; font-size: 17px; margin: 0 0 2px; }
.pc-stats { display: grid; grid-template-columns: repeat(4, 1fr); margin: 10px 0 6px; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.pc-stats div { text-align: center; padding: 6px 0; }
.pc-stats b { display: block; font-family: var(--serif); font-size: 19px; font-weight: 500; }
.pc-stats span { font-size: 9.5px; color: var(--soft); letter-spacing: .06em; }

#help { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); width: 300px; background: var(--card); border: 1px solid var(--hair); border-radius: 14px; padding: 12px 16px; backdrop-filter: blur(6px); }
#help h3 { font-family: var(--serif); font-weight: 500; margin: 0 0 6px; font-size: 16px; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
#help dt { font-family: ui-monospace, Menlo, monospace; font-size: 10.5px; background: rgba(42,41,38,.07); border-radius: 4px; padding: 1px 5px; text-align: center; }
#help dd { margin: 0; color: var(--soft); font-size: 11px; }
#langMenu { position: absolute; left: 50%; bottom: 64px; transform: translateX(40px); background: var(--card); border: 1px solid var(--hair); border-radius: 12px; padding: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; backdrop-filter: blur(6px); }
#langMenu a { color: var(--ink); text-decoration: none; padding: 5px 10px; border-radius: 8px; font-size: 12px; }
#langMenu a:hover { background: rgba(42,41,38,.07); }
#langMenu a.on { background: var(--ink); color: var(--paper); }

#summary { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); width: 360px; max-height: calc(100vh - 120px); overflow-y: auto; background: var(--card); border: 1px solid var(--hair); border-radius: 16px; padding: 16px 18px; backdrop-filter: blur(8px); box-shadow: 0 10px 40px rgba(60,45,25,.12); }
#summary h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 4px 0; }
#summary .big { font-family: var(--serif); font-size: 44px; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
#summary .big span { color: var(--soft); }
#summary table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; margin-bottom: 8px; }
#summary th { color: var(--soft); font-weight: 500; font-size: 9.5px; text-align: right; padding: 3px; }
#summary td { text-align: right; padding: 3px; border-top: 1px solid var(--hair); }
#summary td:first-child, #summary th:first-child { text-align: left; }
.sum-box { display: grid; grid-template-columns: 1fr; gap: 4px; }

/* ---------- labels in the scene */
.tag { position: absolute; left: 0; top: 0; white-space: nowrap; pointer-events: none; will-change: transform; }
.tag.ball { --c: #2a2926; font-size: 10.5px; background: var(--card); border: 1px solid var(--hair); border-left: 3px solid var(--c); border-radius: 6px; padding: 1px 6px; color: var(--ink); box-shadow: 0 1px 4px rgba(60,45,25,.12); }
.tag.name { font-size: 9.5px; background: rgba(250,247,240,.85); border-bottom: 2px solid #888; border-radius: 3px; padding: 0 4px; color: var(--ink); }
.tag.zone { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); background: rgba(250,247,240,.78); border-radius: 999px; padding: 1px 7px; }
.tag.key { font-size: 10px; font-weight: 700; color: #fff; background: #e0a63a; border-radius: 4px; padding: 0 4px; }
.tag.key.hot { background: #d8452f; }

/* ---------- small screens */
@media (max-width: 760px) {
  :root { --panel-w: min(316px, calc(100vw - 32px)); }
  #title { left: 16px; top: 14px; max-width: 58vw; }
  #title h1 { font-size: 19px; }
  #title p, .kicker { display: none; }
  #score { width: auto; min-width: 190px; right: 12px; top: 12px; padding: 7px 10px; }
  .sc-row .nm { font-size: 13px; max-width: 110px; }
  #ticker { left: 16px; bottom: 64px; width: 62vw; }
  #ticker .tl:not(:last-child) { display: none; }
  #panel { top: auto; height: 52vh; right: 12px; bottom: 64px; }
  #panelToggle { right: 0; top: -36px; }
  #panel.closed #panelToggle { right: calc(100% + 12px); }
  body:not(.panel-closed) #bar { left: 50%; max-width: calc(100vw - 24px); }
  #rulecard { left: 12px; right: 12px; top: auto; bottom: 110px; width: auto; }
  #pcard { right: 12px; left: 12px; width: auto; bottom: 64px; }
  #summary { left: 12px; right: 12px; width: auto; }
}
