:root {
  --bg: #f3eee4;
  --paper: rgba(250, 247, 240, 0.92);
  --ink: #2a2723;
  --muted: #7b7468;
  --line: rgba(42, 39, 35, 0.16);
  --accent: #b5523b;
  --gold: #c99a3f;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Songti SC', 'Noto Serif CJK SC', 'Hiragino Mincho ProN', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Segoe UI', 'PingFang SC', 'Hiragino Sans', 'Noto Sans CJK SC', Arial, sans-serif;
  --panelW: 336px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#stage canvas:active { cursor: grabbing; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
body.photo #ui, body.photo #labels { display: none; }
.hidden { display: none !important; }

/* title */
#title { position: absolute; top: 22px; left: 26px; max-width: 360px; pointer-events: none; }
.kicker { font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
#title h1 { font-family: var(--serif); font-weight: 500; font-size: 28px; line-height: 1.12; margin: 0 0 8px; letter-spacing: -0.01em; }
#title p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); max-width: 330px; }

/* scorecard */
#score { position: absolute; top: 18px; right: 22px; width: var(--panelW); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 9px; backdrop-filter: blur(6px); font-variant-numeric: tabular-nums; }
.srow { display: grid; grid-template-columns: 14px 14px 1fr auto 36px; align-items: center; gap: 8px; height: 28px; }
.srow .arrow { color: var(--accent); font-size: 12px; }
.srow .chip { width: 12px; height: 12px; border-radius: 3px; border: 2px solid; }
.srow .tn { font-family: var(--serif); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srow b { font-family: var(--serif); font-size: 22px; font-weight: 600; text-align: right; }
.srow .to { display: flex; gap: 3px; }
.srow .to i { width: 7px; height: 3px; border-radius: 2px; background: var(--line); }
.srow .to i.on { background: var(--gold); }
.sfoot, .sfoot2 { display: flex; justify-content: space-between; font-size: 12px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; color: var(--ink); }
.sfoot2 { color: var(--muted); border-top: none; margin-top: 0; padding-top: 2px; }
.sfoot .pc { display: inline-block; min-width: 26px; text-align: center; border-radius: 6px; background: #2a2723; color: #f3d36a; font-weight: 700; font-size: 11px; padding: 1px 4px; }

/* ticker */
#ticker { position: absolute; left: 22px; bottom: 66px; width: min(430px, calc(100vw - 44px)); display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.tk { font-size: 12.5px; line-height: 1.35; padding: 5px 10px; border-radius: 9px; background: rgba(250, 247, 240, 0.7); color: var(--muted); border-left: 2px solid transparent; }
.tk.new { background: var(--paper); color: var(--ink); }
.tk.score { border-left-color: var(--gold); color: var(--ink); }
.tk.pen { border-left-color: #e2b62e; }
.tk.big { border-left-color: var(--accent); }
.tk.clock { border-left-color: #6f8fb0; }
.tkq { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }

/* cards */
.card { position: absolute; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(60, 45, 25, 0.08); }
.card h3 { font-family: var(--serif); font-weight: 500; font-size: 19px; margin: 2px 0 6px; line-height: 1.2; }
.card h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 2px 0 10px; }
.card p { margin: 0 0 8px; font-size: 13px; line-height: 1.5; }
.card .x { position: absolute; top: 8px; right: 8px; padding: 2px 9px; }
.rc-k { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.rc-v, .rc-o { font-size: 12.5px !important; color: var(--ink); }
.rc-o { color: var(--muted) !important; }
.rc-v span, .rc-o span { display: inline-block; font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 9px; padding: 1px 7px; margin-right: 6px; }
.rc-v span { background: #2a2723; color: #f3eee4; border-color: #2a2723; }
.rc-vis { display: flex; align-items: center; gap: 10px; }
.rc-vis em { font-size: 11px; color: var(--muted); font-style: normal; }
svg.sig { width: 74px; height: 86px; flex: none; }
svg.sig .a1, svg.sig .a2 { stroke: #2b2b2b; stroke-width: 7; stroke-linecap: square; }
svg.sig .a2 { stroke: #e7c4a0; stroke-width: 6; }
svg.sig .hand { fill: #e7c4a0; }
svg.sig .leg { fill: #222; }
svg.sig .head { fill: #e7c4a0; }
svg.sig .cap { fill: #f7f5ef; stroke: #222; stroke-width: 1; }
svg.diag { width: 180px; height: 90px; border-radius: 6px; }
#rulecard { top: 150px; left: 22px; width: 318px; }
#pcard { left: 22px; bottom: 250px; width: 318px; display: flex; gap: 12px; }
.pc-num { width: 50px; height: 50px; border-radius: 10px; display: grid; place-items: center; font-family: var(--serif); font-size: 24px; font-weight: 700; flex: none; }
.pc-main { flex: 1; min-width: 0; }
.pc-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.pc-stats { font-size: 12.5px; line-height: 1.5; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.pc-btns { display: flex; flex-wrap: wrap; gap: 5px; }
#summary { top: 140px; left: 22px; width: 380px; max-height: calc(100vh - 230px); overflow: auto; }

/* pills & controls */
.pill { font: inherit; font-size: 12px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 6px 12px; cursor: pointer; line-height: 1.1; transition: background 0.15s, border-color 0.15s; white-space: nowrap; }
.pill:hover { border-color: rgba(42, 39, 35, 0.4); }
.pill.on { background: var(--ink); color: #f6f1e7; border-color: var(--ink); }
.pill.icon { padding: 6px 10px; }
.pop { position: absolute; z-index: 6; right: 22px; bottom: 64px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(60, 45, 25, 0.08); }
#help { width: 320px; max-height: calc(100vh - 160px); overflow: auto; }
#help h3 { font-family: var(--serif); font-weight: 500; margin: 0 0 8px; font-size: 17px; }
#help dl { display: grid; grid-template-columns: 52px 1fr; gap: 4px 10px; margin: 0 0 10px; font-size: 12px; }
#help dt { font-weight: 700; font-family: ui-monospace, Menlo, monospace; font-size: 11px; background: rgba(42, 39, 35, 0.06); border-radius: 5px; text-align: center; padding: 1px 0; }
#help dd { margin: 0; }
#help p { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin: 0; }
#langMenu { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; padding: 10px 14px; }
#langMenu a { color: var(--ink); text-decoration: none; font-size: 13px; padding: 3px 0; }
#langMenu a.cur { color: var(--accent); font-weight: 600; }

/* bottom bar */
#bar { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 0 16px; pointer-events: none; }
#bar .grp { display: flex; gap: 5px; align-items: center; pointer-events: auto; padding: 4px; border-radius: 999px; background: rgba(243, 238, 228, 0.6); border: 1px solid var(--line); backdrop-filter: blur(6px); }
.vol { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); padding: 0 6px; }
.vol input { width: 70px; accent-color: var(--ink); }
.vol b { font-weight: 500; min-width: 30px; font-variant-numeric: tabular-nums; }

/* panel */
#panel { position: absolute; top: 152px; right: 22px; bottom: 64px; width: var(--panelW); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; backdrop-filter: blur(6px); transition: transform 0.3s ease; }
#panel.closed { transform: translateX(calc(100% + 30px)); }
#panelToggle { position: absolute; left: -14px; top: 12px; transform: translateX(-100%); padding: 5px 10px; }
#panel.closed #panelToggle { left: -16px; }
#tabs { display: flex; flex-wrap: wrap; gap: 2px 10px; padding: 10px 14px 8px; border-bottom: 1px solid var(--line); }
.tab { font: inherit; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; background: none; border: none; padding: 4px 0; color: var(--muted); cursor: pointer; border-bottom: 1.5px solid transparent; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
#tabBody { flex: 1; overflow-y: auto; padding: 8px 14px 16px; font-size: 12.5px; }
#tabBody h4 { font-family: var(--serif); font-weight: 500; font-size: 15px; margin: 16px 0 6px; padding-top: 10px; border-top: 1px solid var(--line); }
#tabBody h4:first-child { border-top: none; padding-top: 0; margin-top: 6px; }
.note { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 6px 0 8px; }
.warn { color: #9c3a2f; font-size: 12px; line-height: 1.45; background: rgba(181, 82, 59, 0.08); border-radius: 8px; padding: 6px 9px; }
.row { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid rgba(42, 39, 35, 0.06); }
.row .lab { flex: 0 0 104px; font-size: 12px; color: var(--ink); }
.row .ctl { flex: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 0; }
.row input[type=text] { flex: 1; font: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fffdf8; color: var(--ink); min-width: 0; }
.row input[type=number] { width: 52px; font: inherit; font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; background: #fffdf8; }
.row input[type=color] { width: 34px; height: 24px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; cursor: pointer; }
.row code { font-size: 11px; color: var(--muted); }
.mini { font-size: 11px; color: var(--muted); }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg .pill { padding: 4px 9px; font-size: 11.5px; }
.sl { display: flex; align-items: center; gap: 8px; flex: 1; }
.sl input { flex: 1; accent-color: var(--ink); min-width: 0; }
.sl b { font-weight: 500; font-size: 11.5px; min-width: 52px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.sw { display: inline-flex; align-items: center; gap: 7px; background: none; border: none; font: inherit; font-size: 12px; cursor: pointer; color: var(--muted); padding: 2px 0; }
.sw i { width: 28px; height: 16px; border-radius: 9px; background: rgba(42, 39, 35, 0.18); position: relative; transition: background 0.15s; }
.sw i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.sw.on { color: var(--ink); }
.sw.on i { background: var(--ink); }
.sw.on i::after { left: 14px; }
.grid { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 6px; }
.grid .pill { font-size: 11.5px; padding: 5px 10px; }
.gloss { display: flex; flex-direction: column; gap: 2px; }
.gl { text-align: left; font: inherit; background: none; border: none; border-bottom: 1px solid rgba(42, 39, 35, 0.07); padding: 7px 2px; cursor: pointer; color: var(--ink); }
.gl b { display: block; font-family: var(--serif); font-weight: 500; font-size: 14px; }
.gl span { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.4; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gl i { font-style: normal; font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.gl i::before { content: '● '; }
.gl:hover b { color: var(--accent); }
.roster { display: flex; flex-wrap: wrap; gap: 3px 4px; align-items: baseline; margin: 4px 0; }
.rp { flex: 0 0 100%; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.rn { font: inherit; font-size: 11.5px; border: 1px solid var(--line); background: #fffdf8; border-radius: 7px; padding: 2px 6px; cursor: pointer; color: var(--ink); }
.rn b { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; margin-right: 2px; }
.rn.inj { text-decoration: line-through; opacity: 0.6; }
table.bx { width: 100%; border-collapse: collapse; font-size: 11.5px; font-variant-numeric: tabular-nums; margin: 4px 0 8px; }
table.bx th { font-weight: 600; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); text-align: right; padding: 3px 4px; border-bottom: 1px solid var(--line); }
table.bx th:first-child, table.bx td:first-child { text-align: left; }
table.bx td { text-align: right; padding: 3px 4px; border-bottom: 1px solid rgba(42, 39, 35, 0.06); }
table.box tr.t1 td:first-child { border-left: 2px solid #9c3a3f; padding-left: 5px; }
table.box tr.t0 td:first-child { border-left: 2px solid #2f4c78; padding-left: 5px; }
.lnk { font: inherit; background: none; border: none; padding: 0; color: var(--ink); cursor: pointer; text-align: left; }
.lnk:hover { color: var(--accent); }
svg.drives { width: 100%; height: auto; display: block; border-radius: 6px; }
.tl { display: flex; flex-direction: column; gap: 2px; }
.tli { display: flex; gap: 8px; font-size: 11.5px; line-height: 1.4; padding: 3px 0; border-bottom: 1px solid rgba(42, 39, 35, 0.05); }
.tli em { flex: 0 0 64px; font-style: normal; color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.tlb { font: inherit; text-align: left; background: rgba(201, 154, 63, 0.12); border: 1px solid rgba(201, 154, 63, 0.4); border-radius: 7px; padding: 3px 7px; cursor: pointer; color: var(--ink); }
.tlb:hover { background: rgba(201, 154, 63, 0.25); }
.tlb b { margin-right: 4px; }

/* floating labels */
.lbl { position: absolute; left: 0; top: 0; font-size: 10.5px; padding: 2px 7px; border-radius: 9px; background: rgba(250, 247, 240, 0.86); color: var(--ink); white-space: nowrap; border: 1px solid var(--line); will-change: transform; }
.lbl.nm { font-size: 9.5px; padding: 1px 5px; opacity: 0.92; }
.lbl.nm.t0 { border-left: 2px solid #2f4c78; }
.lbl.nm.t1 { border-left: 2px solid #9c3a3f; }
.lbl.carrier { font-weight: 600; background: var(--ink); color: #f6f1e7; border-color: var(--ink); font-size: 11px; }
.lbl.fm { font-family: var(--serif); font-size: 12px; font-style: italic; background: rgba(42, 39, 35, 0.65); color: #f6f1e7; border: none; }
#photoExit { position: fixed; top: 16px; right: 16px; z-index: 5; }
body.replaying #score::after { content: 'REPLAY'; position: absolute; top: -9px; left: 14px; font-size: 9px; letter-spacing: 0.16em; background: var(--accent); color: #fff; padding: 2px 7px; border-radius: 6px; }

/* small screens */
@media (max-width: 760px) {
  :root { --panelW: calc(100vw - 24px); }
  #title { top: 12px; left: 14px; max-width: calc(100vw - 236px); }
  #title h1 { font-size: 18px; }
  #title p { display: none; }
  .kicker { font-size: 9px; }
  #score { top: 10px; right: 12px; width: 190px; padding: 6px 9px; }
  .srow { height: 22px; grid-template-columns: 10px 10px 1fr auto 26px; gap: 5px; }
  .srow .tn { font-size: 13px; }
  .srow b { font-size: 17px; }
  .srow .to { display: none; }
  .sfoot, .sfoot2 { font-size: 10.5px; }
  #panel { top: auto; height: 42vh; right: 12px; left: 12px; width: auto; bottom: 60px; }
  #panel.closed { transform: translateY(calc(100% + 70px)); }
  #panelToggle { left: auto; right: 0; top: -12px; transform: translateY(-100%); }
  #panel.closed #panelToggle { left: auto; right: 0; top: -62px; } /* clear of the bottom bar */
  #ticker { bottom: 60px; left: 12px; width: calc(100vw - 24px); }
  body.panel-open #ticker { bottom: calc(42vh + 68px); }
  body:not(.panel-open) #ticker { width: calc(100vw - 130px); }
  #ticker .tk:not(.new) { display: none; }
  #rulecard, #pcard, #summary { left: 12px; right: 12px; width: auto; top: 108px; bottom: auto; }
  #bar { bottom: 8px; gap: 5px; padding: 0 8px; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
  #bar::-webkit-scrollbar { display: none; }
  #bar .grp { flex: none; }
  #bar .pill { padding: 5px 8px; font-size: 11px; }
  .vol input { width: 46px; }
  .vol span { display: none; }
}
