/* Cribbage, baize, cream cards and a brass peg. Fixed palette (the same in light and dark OS modes). */
:root {
  --bg: #eef0e8;
  --surface: #fffefa;
  --surface2: #dfe3d6;
  --line: rgba(40, 52, 38, .14);
  --ink: #22291e;
  --muted: #6b7563;
  --accent: #8a5a2b;           /* you */
  --rival: #41624a;            /* your rival */
  --brass: #b08d3a;
  --baize: #cfd8c6;
  --red: #a8322c;              /* diamonds and hearts */
  --black: #23291f;            /* clubs and spades */
  /* tutorial kit (tutorial.css) */
  --tut-accent: #b08d3a;
  --tut-accent-ink: #22291e;
  --tut-bubble: #fffefa;
  --tut-ink: #22291e;
  --tut-muted: #6b7563;
  --tut-dim: rgba(24, 30, 20, .58);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; touch-action: manipulation; min-height: 100vh; overflow-x: hidden; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { position: relative; max-width: 760px; margin: 0 auto; padding: 0 10px 20px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }

/* ---------- top bar + menu ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 50px; }
.back, .iconbtn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 0; }
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface2); }
.brand { flex: 1; text-align: center; font: 700 21px/1 Georgia, "Times New Roman", serif; letter-spacing: .06em; }
.menu { position: absolute; right: 10px; top: 46px; z-index: 45; min-width: 208px; padding: 6px; background: var(--surface); border-radius: 14px; box-shadow: 0 14px 36px rgba(40, 52, 38, .25); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.menu button { min-height: 46px; text-align: left; padding: 0 14px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 600; }
.menu button:hover, .menu button:focus-visible { background: var(--surface2); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- buttons ---------- */
.btn { min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 0; background: var(--surface2); color: var(--ink); cursor: pointer; font-weight: 650; transition: background .15s, transform .1s, opacity .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { background: #d2d8c7; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #714415; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

/* ---------- status ---------- */
.status { min-height: 36px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 4px 4px; font-size: 15px; color: var(--muted); text-align: center; position: relative; }
.status.mine { color: var(--ink); font-weight: 600; }
.status .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--rival); }
.status.mine .dot { background: var(--accent); }
.status .net-note { position: absolute; left: 50%; top: calc(100% - 6px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: calc(100% - 24px); background: var(--ink); color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 8px; }

/* ---------- the score: numbers and a race to the target ---------- */
.scores { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.score { display: flex; align-items: center; gap: 8px; position: relative; }
.score .who { min-width: 92px; font-size: 13px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--rival); display: flex; align-items: center; gap: 5px; }
.score.me .who { color: var(--accent); }
.score .deal { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--brass); color: #fff; font-size: 10px; font-weight: 800; letter-spacing: 0; }
.score .bar { flex: 1; height: 9px; border-radius: 5px; background: var(--surface2); overflow: hidden; }
.score .bar i { display: block; height: 100%; background: var(--rival); transition: width .35s ease-out; }
.score.me .bar i { background: var(--accent); }
.score .pts { min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; font-size: 17px; }
/* the points just pegged, beside that player's own score: above the row it clipped, and it was not
   obvious which of the two lines had earned it */
.score .bump { position: absolute; right: 42px; top: 50%; font-size: 12px; font-weight: 800; color: var(--brass); animation: rise 1.1s ease-out; }
@keyframes rise { from { transform: translateY(-50%) translateX(8px); opacity: 0; } 25% { opacity: 1; } to { transform: translateY(-50%) translateX(-2px); opacity: 0; } }

/* ---------- the table ---------- */
.board { background: var(--baize); border-radius: 16px; padding: 8px; box-shadow: inset 0 0 0 1px var(--line); display: flex; flex-direction: column; gap: 8px; min-height: 268px; }
.rival { display: flex; align-items: center; gap: 8px; min-height: 42px; }
.rival .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--rival); }
.rival .backs { display: flex; gap: 3px; }
.middle { display: flex; align-items: flex-start; justify-content: center; gap: 18px; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.pile .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.pile .crib { display: flex; gap: 2px; }
.play-row { display: flex; align-items: center; gap: 8px; min-height: 74px; }
.play-row .count { display: grid; place-items: center; min-width: 48px; height: 48px; border-radius: 12px; background: var(--surface); box-shadow: 0 1px 4px rgba(40, 52, 38, .2); }
.play-row .count b { font-size: 20px; line-height: 1; font-variant-numeric: tabular-nums; }
.play-row .count small { font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.play-row .laid { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; flex: 1; }
.play-row .laid-card { position: relative; display: inline-flex; padding-top: 10px; }
.play-row .laid-card.mine { padding-top: 0; padding-bottom: 10px; }
.play-row .waiting, .play-row .over-note { flex: 1; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- the show ---------- */
.show { flex: 1; background: var(--surface); border-radius: 12px; padding: 8px 10px; box-shadow: 0 1px 4px rgba(40, 52, 38, .16); }
.show-head { display: flex; align-items: baseline; justify-content: space-between; font-weight: 700; font-size: 14px; }
.show-head b { font-size: 20px; color: var(--brass); font-variant-numeric: tabular-nums; }
.show-cards { display: flex; align-items: center; gap: 3px; margin: 6px 0; }
.show-cards .plus { color: var(--muted); font-size: 13px; padding: 0 2px; }
.show-cards .starter { box-shadow: 0 0 0 2px var(--brass); }
.show-parts { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.show-parts .part b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- cards ---------- */
.pc { position: relative; width: 34px; height: 48px; border-radius: 5px; background: var(--surface); border: 0; padding: 0; display: grid; place-items: center; line-height: 1;
  box-shadow: 0 1px 3px rgba(34, 41, 30, .3), inset 0 0 0 1px rgba(34, 41, 30, .12); font: 700 15px/1 system-ui, sans-serif; color: var(--black); }
.pc b { font-size: 15px; font-weight: 800; }
.pc i { font-style: normal; font-size: 12px; line-height: 1; }
.pc.s1, .pc.s3 { color: var(--red); }
.pc.back { background: repeating-linear-gradient(45deg, #6d7f68 0 4px, #5d6e59 4px 8px); box-shadow: 0 1px 3px rgba(34, 41, 30, .3), inset 0 0 0 1px rgba(34, 41, 30, .2); }
.pc.slot { background: none; box-shadow: inset 0 0 0 1.5px rgba(34, 41, 30, .18); }
.pc.big { width: 44px; height: 62px; }
.pc.big b { font-size: 19px; }
.pc.big i { font-size: 15px; }

/* ---------- your hand ---------- */
.you { margin-top: 10px; }
.hand { display: flex; gap: 6px; justify-content: center; align-items: flex-end; min-height: 78px; flex-wrap: wrap; }
.hand .pc { width: 46px; height: 66px; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.hand .pc b { font-size: 20px; }
.hand .pc i { font-size: 15px; }
.hand .pc.on { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--brass), 0 6px 14px rgba(34, 41, 30, .3); }
.hand .pc:disabled { opacity: .45; cursor: default; }
.controls { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 46px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }

/* ---------- sheets and modals ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(24, 30, 20, .45); }
.sheet { position: relative; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; box-shadow: 0 -10px 40px rgba(34, 41, 30, .2); }
@keyframes up { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3 { font-size: 18px; margin-bottom: 6px; }
.sheet .lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 6px; }
.sheet .row { display: flex; align-items: center; gap: 8px; min-height: 38px; }
.sheet .row .who { font-weight: 700; min-width: 84px; }
.sheet .row .cards { color: var(--muted); font-size: 13px; }
.sheet .kind { margin-left: auto; font-weight: 700; color: var(--brass); font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.field-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.field-row .label { font-weight: 600; min-width: 64px; }
.seg { display: flex; gap: 4px; flex: 1; background: var(--surface2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 4px rgba(34, 41, 30, .2); }

.modal-wrap { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 14px; background: rgba(24, 30, 20, .45); }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(34, 41, 30, .3); }
.over-modal { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font: 700 19px/1.2 Georgia, "Times New Roman", serif; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.rules h3 { font-size: 15px; margin: 14px 0 4px; }
.rules ul, .rules ol { margin: 0; padding-left: 20px; }
.rules li { margin: 3px 0; }
.result-line { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.result-line .who { min-width: 76px; font-weight: 600; }
.result-line .bar { height: 10px; border-radius: 5px; background: var(--surface2); flex: 1; overflow: hidden; }
.result-line .bar i { display: block; height: 100%; }
.result-line .bar i.me { background: var(--accent); }
.result-line .bar i.them { background: var(--rival); }

/* ---------- online ---------- */
body.is-online .hand .pc:disabled { opacity: .5; }

@media (max-width: 400px) {
  .app { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .hand { gap: 4px; }
  .hand .pc { width: 43px; height: 62px; }
  .middle { gap: 12px; }
}
@media (max-height: 720px) {
  .board { min-height: 232px; }
  .pc.big { width: 40px; height: 56px; }
  .hand .pc { height: 60px; }
  .hand { min-height: 70px; }
}
@media (min-width: 620px) {
  .pc { width: 40px; height: 56px; }
  .hand .pc { width: 58px; height: 82px; }
  .hand .pc b { font-size: 24px; }
  .board { min-height: 320px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
