:root {
  --bg: #0d1412;
  --panel: #151e1b;
  --panel-2: #1c2723;
  --line: #2b3833;
  --ink: #eee8da;
  --muted: #a4ada2;
  --felt: #12573f;
  --felt-deep: #0b3d2c;
  --rail: #2c1a10;
  --rail-hi: #4a2c1a;
  --brass: #dcb765;
  --card: #fbf6ea;
  --card-ink: #1b1a18;
  --red: #a3211b;
  --good: #6fcf97;
  --bad: #f08a7c;
  --close: #e8c469;
  --cw: clamp(58px, 6.6vw, 84px);
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; max-width: 1360px; margin: 0 auto; }
.top h1 { margin: 0; font: 600 22px/1 var(--serif); letter-spacing: .01em; color: var(--brass); }
.top-actions { display: flex; gap: 6px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.ghost:hover:not(:disabled) { background: var(--panel-2); }
.ghost[aria-pressed="true"] { border-color: var(--brass); color: var(--brass); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; padding: 0 20px 20px; max-width: 1360px; margin: 0 auto; align-items: start; }
.play { min-width: 0; }

/* table */
.rail { padding: 12px; background: linear-gradient(180deg, var(--rail-hi), var(--rail)); border-radius: 30px 30px 50% 50% / 30px 30px 36% 36%; box-shadow: 0 14px 30px rgba(0,0,0,.45); }
.felt { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: space-between; min-height: clamp(470px, calc(100vh - 210px), 640px); padding: 18px 16px 44px; border-radius: 20px 20px 50% 50% / 20px 20px 35% 35%; background: radial-gradient(ellipse at 50% 42%, var(--felt) 0%, var(--felt-deep) 92%); box-shadow: inset 0 0 40px rgba(0,0,0,.4); overflow: hidden; }
.arc { position: absolute; left: 50%; top: 40%; width: min(74%, 560px); transform: translate(-50%, -50%); pointer-events: none; }
.arc-main { font: 600 25px var(--serif); letter-spacing: .1em; fill: var(--brass); opacity: .62; }
.arc-sub { font: 500 14px var(--serif); letter-spacing: .14em; fill: var(--ink); opacity: .42; }

.zone { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: calc(var(--cw) * 1.4 + 30px); width: 100%; }
.player { flex-direction: row; justify-content: center; align-items: flex-end; gap: clamp(10px, 2.5vw, 30px); min-height: calc(var(--cw) * 1.4 + 74px); }

.tray, .shoe { position: absolute; top: 16px; z-index: 2; font-size: 12px; color: rgba(238,232,218,.8); }
.tray { left: 18px; width: 46px; }
.shoe { right: 18px; text-align: right; font: 600 13px var(--serif); }
.tray-box { position: relative; height: 84px; border: 1px solid rgba(238,232,218,.35); border-radius: 4px; background: rgba(0,0,0,.25); overflow: hidden; }
.tray-fill { position: absolute; left: 0; right: 0; bottom: 0; background: repeating-linear-gradient(0deg, #e9e2d0 0 1px, #bfb7a4 1px 2px); transition: height .3s; }
.tray-tick { position: absolute; left: 0; right: 0; height: 1px; background: var(--brass); }
.tray span { display: block; margin-top: 4px; text-align: center; font-size: 11px; }

.countchip { position: absolute; top: 112px; right: 18px; z-index: 2; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.42); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.countchip b { color: var(--brass); }

.hand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px; border-radius: 12px; border: 1px solid transparent; }
.hand.active { border-color: var(--brass); background: rgba(220,183,101,.08); }
.cards { display: flex; justify-content: center; min-height: calc(var(--cw) * 1.4); }
.total { min-height: 22px; padding: 1px 9px; border-radius: 11px; background: rgba(0,0,0,.42); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.total:empty { visibility: hidden; }
.meta { display: flex; align-items: center; gap: 6px; }
.spot { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--brass); color: #2a1c08; font-weight: 700; font-size: 13px; border: 2px dashed rgba(44,26,16,.55); }
.result { padding: 2px 8px; border-radius: 6px; background: rgba(0,0,0,.5); font-size: 13px; font-weight: 600; white-space: nowrap; }
.result.win { color: var(--good); }
.result.lose { color: var(--bad); }
.late { animation: fade .2s both; animation-delay: var(--late, 0ms); }
.empty-note { font: 500 17px var(--serif); color: rgba(238,232,218,.7); margin: auto; }

.card { position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: calc(var(--cw) * .08); background: var(--card); color: var(--card-ink); box-shadow: 0 2px 5px rgba(0,0,0,.4); font-family: var(--serif); }
.card + .card { margin-left: calc(var(--cw) * -.6); }
.card.red { color: var(--red); }
.corner { position: absolute; top: 5%; left: 7%; display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: calc(var(--cw) * .26); line-height: 1; }
.corner i { font-style: normal; font-size: calc(var(--cw) * .22); margin-top: 1px; }
.corner.flip { top: auto; left: auto; bottom: 5%; right: 7%; transform: rotate(180deg); }
.pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cw) * .5); }
.card.back { background: repeating-linear-gradient(45deg, #7c1e1a 0 4px, #94302a 4px 8px); border: calc(var(--cw) * .05) solid var(--card); }
.card.new { animation: deal .26s cubic-bezier(.2,.8,.3,1) both; animation-delay: var(--d, 0ms); }
.card.flipup { animation: flipup .3s both; animation-delay: var(--d, 0ms); }
@keyframes deal { from { opacity: 0; transform: translate(50px, -80px) rotate(6deg); } to { opacity: 1; transform: none; } }
@keyframes flipup { from { transform: rotateY(90deg); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* controls */
.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; min-height: 70px; padding: 14px 0 4px; }
.act { min-width: 96px; padding: 12px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; font-size: 16px; }
.act:hover:not(:disabled) { border-color: var(--brass); }
.act.primary { background: var(--brass); border-color: var(--brass); color: #2a1c08; }
.act kbd { margin-left: 6px; font: 500 12px var(--sans); opacity: .55; }
.chips { display: flex; gap: 8px; }
.chip { width: 48px; height: 48px; border-radius: 50%; border: 3px dashed rgba(255,255,255,.45); background: #6a2a22; font-weight: 700; }
.chip:nth-child(2) { background: #27547a; } .chip:nth-child(3) { background: #2c6b45; } .chip:nth-child(4) { background: #2b2b33; } .chip:nth-child(5) { background: #5c3f8a; }
.chip[aria-pressed="true"] { outline: 3px solid var(--brass); outline-offset: 2px; }
.label { font-weight: 600; }
.check { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
.check input { width: 84px; padding: 11px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: 600 18px var(--sans); text-align: center; }
.step { width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-size: 20px; }

/* coach */
.coach { display: flex; flex-direction: column; gap: 10px; min-width: 0; position: sticky; top: 10px; max-height: calc(100vh - 20px); }
.scores { flex-shrink: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.score { padding: 8px 4px; background: var(--panel); text-align: center; }
.score b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.score span { font-size: 11px; color: var(--muted); }
.feed { flex: 1 1 auto; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; }
.feed > * { flex-shrink: 0; }
.note { padding: 10px 12px; border-radius: 10px; background: var(--panel); border-left: 3px solid var(--line); }
.note.good { border-left-color: var(--good); }
.note.bad { border-left-color: var(--bad); }
.note.close { border-left-color: var(--close); }
.note.big { background: var(--panel-2); }
.note .tag { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.note.big .tag { color: var(--brass); }
.note h3 { margin: 1px 0 3px; font-size: 15px; }
.note p { margin: 3px 0 0; font-size: 14px; color: #d4d2c6; }

/* dialogs */
.sheet { width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); }
.sheet.wide { width: min(760px, calc(100vw - 24px)); }
.sheet::backdrop { background: rgba(0,0,0,.65); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet h2 { margin: 0; font: 600 22px var(--serif); color: var(--brass); }
.sheet h3 { margin: 20px 0 6px; font: 600 17px var(--serif); }
.sheet p { margin: 6px 0; }
.values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.values div { padding: 10px; border-radius: 10px; background: var(--panel-2); text-align: center; }
.values b { display: block; font: 600 24px var(--serif); color: var(--brass); }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); font: inherit; }
.field input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brass); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.summary { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 10px 0 16px; font-variant-numeric: tabular-nums; }

/* drill */
.sheet-head .drill-score { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }
.drill-felt { margin-top: 6px; padding: 16px; border-radius: 14px; background: radial-gradient(ellipse at 50% 40%, var(--felt) 0%, var(--felt-deep) 95%); }
.drill-count { display: flex; justify-content: center; gap: 10px; }
.stat { min-width: 110px; padding: 8px 12px; border-radius: 10px; background: rgba(0,0,0,.35); text-align: center; }
.stat b { display: block; font: 600 28px var(--serif); color: var(--brass); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--ink); opacity: .8; }
.drill-hands { display: flex; justify-content: center; gap: clamp(24px, 8vw, 70px); margin-top: 14px; }
.drill-hand { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.drill-hand > span { font: 600 13px var(--serif); letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.act.right { border-color: var(--good); color: var(--good); opacity: 1; }
.act.wrong { border-color: var(--bad); color: var(--bad); opacity: 1; }
.drill-next { display: flex; justify-content: center; margin-top: 10px; }
.drill-foot { margin-top: 10px; }
.drill-weak { font-size: 13px; color: var(--muted); }

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 16px; gap: 10px; }
  .coach { position: static; max-height: none; }
  .top { padding: 10px 16px; }
  .felt { min-height: clamp(400px, 56vh, 560px); }
}
@media (max-width: 560px) {
  :root { --cw: 52px; }
  .top h1 { font-size: 18px; }
  .ghost { padding: 5px 8px; font-size: 13px; }
  .rail { padding: 7px; border-radius: 20px 20px 42% 42% / 20px 20px 22% 22%; }
  .felt { padding: 12px 6px 26px; border-radius: 14px 14px 42% 42% / 14px 14px 21% 21%; }
  .tray { left: 10px; top: 10px; width: 34px; }
  .tray-box { height: 58px; }
  .shoe { right: 10px; top: 10px; }
  .countchip { top: 34px; right: 10px; font-size: 12px; padding: 4px 7px; }
  .arc { width: 92%; top: 42%; }
  .act { min-width: 0; flex: 1 1 21%; padding: 12px 6px; font-size: 15px; }
  .act kbd { display: none; }
  .chip { width: 44px; height: 44px; }
  .score span { font-size: 10px; }
  .hands-3, .hands-4 { --cw: 36px; }
  .stat { min-width: 0; flex: 1; }
  .stat b { font-size: 22px; }
  .hands-3 .hand, .hands-4 .hand { padding: 3px; }
}
@media (hover: none) { .act kbd { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .card.new, .card.flipup, .late { animation: none; }
  .tray-fill { transition: none; }
}
