  @font-face { font-family: "DM Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/dmmono-400.woff2) format("woff2"); }
  @font-face { font-family: "DM Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/dmmono-500.woff2) format("woff2"); }
  :root { --ink: #fbf3e4; --muted: #b7a690; --page: #17130f; --paper: rgba(255,249,238,0.94); --dark: #2b2118;
    --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --sheet: #fbf6ea; --line: rgba(80,60,35,0.14); --upper: #7c9a86; --lower: #b9825a; --accent: #c47a22; }
  * { box-sizing: border-box; }
  html, body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.4 var(--ui); }
  #game { position: relative; overflow: hidden; height: calc(100vh - 44px); height: calc(100svh - 44px); min-height: 520px; background: #1b1510; -webkit-user-select: none; user-select: none; }
  header { position: absolute; top: 0; left: 0; right: 0; height: 52px; z-index: 4; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px;
    background: linear-gradient(rgba(20,14,9,0.75), rgba(20,14,9,0.4)); border-bottom: 1px solid rgba(255,240,220,0.08); }
  h1 { font-size: 17px; margin: 0 4px 0 0; font-weight: 800; white-space: nowrap; letter-spacing: -0.2px; }
  .grow { flex: 1; }
  button, select { font: 600 14px var(--ui); border: 1px solid rgba(255,240,220,0.22); background: rgba(255,240,220,0.1); color: var(--ink); border-radius: 10px; padding: 7px 12px; cursor: pointer; }
  button:hover:not(:disabled) { background: rgba(255,240,220,0.2); }
  button:disabled { opacity: 0.4; cursor: default; }
  header button { white-space: nowrap; }
  .short { display: none; }
  /* current mode next to the title; opens New game */
  .lvl { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 13px; }
  .lvl i { width: 8px; height: 8px; border-radius: 50%; background: #e0a24c; }
  .lvl b { font-weight: 700; }
  .lvl span { opacity: 0.6; font-size: 10px; }
  .lvl[data-l=solo] i { background: #c9b79a; }
  .lvl[data-l=easy] i { background: #6cc070; }
  .lvl[data-l=hard] i { background: #e5573f; }
  .lvl[data-l^=p] i { background: #7fb2e5; }
  .lvl[data-l=daily] i { background: #f2c94c; box-shadow: 0 0 0 3px rgba(242,201,76,0.25); }
  #gl { position: absolute; inset: 0; touch-action: none; display: block; }
  #vig { position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background: radial-gradient(ellipse 70% 72% at 40% 47%, rgba(0,0,0,0) 55%, rgba(0,0,0,0.3) 100%); }
  #fx { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

  /* ---- score card ---- */
  #card { position: absolute; z-index: 3; right: 16px; top: 64px; width: 316px; max-height: calc(100% - 80px); overflow: auto; padding: 10px 12px 12px;
    background: var(--sheet); color: var(--dark); border-radius: 16px; box-shadow: 0 14px 40px rgba(0,0,0,0.38);
    font-variant-numeric: tabular-nums; }
  #card.wide { width: 380px; }
  #card .sec { width: 100%; border-collapse: collapse; }
  #card .sec + .sec { margin-top: 8px; }
  #card th, #card td { padding: 0 6px; height: 27px; text-align: right; font-size: 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
  #card th { text-align: left; font-weight: 600; font-size: 13.5px; }
  #card thead th { font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: #8a7558; height: 24px; border-bottom: 2px solid var(--line); text-align: right; }
  #card thead th:first-child { text-align: left; }
  #card .sec.up thead th:first-child { color: var(--upper); }
  #card .sec.lo thead th:first-child { color: var(--lower); }
  #card thead th.me { color: var(--dark); }
  #card td { font: 500 14.5px var(--mono); min-width: 44px; }
  #card td.now { background: rgba(196,122,34,0.07); }
  #card td.open { color: rgba(43,33,24,0.34); cursor: pointer; font-weight: 500; }
  #card td.open.zero { color: rgba(43,33,24,0.2); }
  #card td.open:hover, #card td.open.kbd { background: rgba(196,122,34,0.18); color: var(--dark); box-shadow: inset 0 0 0 2px rgba(196,122,34,0.55); border-radius: 6px; }
  #card td.best { position: relative; }
  #card td.best::after { content: ""; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: #d9a441; }
  #card td.just { animation: ink 0.7s ease-out; color: var(--dark); }
  @keyframes ink { 0% { background: rgba(242,201,76,0.6); transform: scale(1.18); } 100% { background: transparent; transform: none; } }
  #card tr.sum th, #card tr.sum td { font-weight: 800; color: #4a3a28; }
  #card tr.sum th { font-size: 12.5px; }
  #card tr.tot th, #card tr.tot td { height: 32px; font-size: 16px; font-weight: 800; border-bottom: none; color: var(--dark); }
  #card .par { font: 500 10.5px var(--mono); margin-left: 4px; }
  #card .par.plus { color: #3f8f5a; } #card .par.minus { color: #b2552f; }
  #card .bar { display: block; height: 3px; margin-top: 2px; border-radius: 2px; background: rgba(124,154,134,0.25); overflow: hidden; }
  #card .bar i { display: block; height: 100%; background: var(--upper); }
  #card tr:hover th { color: #000; }
  .tip-row { font-size: 11px; color: #8a7558; }

  /* ---- bottom bar ---- */
  #bar { position: absolute; z-index: 3; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px;
    padding: 8px 8px 8px 18px; background: var(--paper); color: var(--dark); border-radius: 999px; box-shadow: 0 8px 30px rgba(0,0,0,0.4); max-width: calc(100vw - 16px); }
  #status { font-size: 14px; max-width: 380px; line-height: 1.25; }
  #rolls { display: flex; gap: 4px; }
  #rolls i { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
  #rolls i.used { background: rgba(80,55,30,0.18); }
  #bar button { background: #fff; color: var(--dark); border-color: rgba(80,55,30,0.2); }
  #bar button.go { background: linear-gradient(#e0a24c, #c47a22); color: #fff; border-color: #a5631a; min-width: 96px; }
  #bar button:disabled { opacity: 0.35; }

  /* the coach's note */
  #coach { position: absolute; z-index: 3; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 66px); transform: translate(-50%, 8px); width: max-content; max-width: min(520px, calc(100vw - 24px));
    padding: 10px 16px; border-radius: 14px; background: rgba(251,246,236,0.96); color: var(--dark); box-shadow: 0 10px 30px rgba(0,0,0,0.35);
    font-size: 14px; line-height: 1.35; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; border-left: 4px solid #3f8f5a; }
  #coach.show { opacity: 1; transform: translate(-50%, 0); }
  #coach.good { border-left-color: #c9a22b; } #coach.tip { border-left-color: #e0a24c; } #coach.hint { border-left-color: #d9a441; }
  #coach b { margin-right: 6px; }

  /* theme picker */
  #themes { position: absolute; z-index: 6; top: 58px; right: 12px; width: 330px; max-width: calc(100vw - 24px); padding: 12px; border-radius: 16px;
    background: rgba(251,246,236,0.97); color: var(--dark); box-shadow: 0 18px 50px rgba(0,0,0,0.35); opacity: 0; transform: translateY(-6px); pointer-events: none; transition: opacity 0.18s, transform 0.18s; }
  #themes.show { opacity: 1; transform: none; pointer-events: auto; }
  #themes .ph { font-weight: 800; font-size: 15px; margin: 2px 4px 10px; }
  #themes .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  #themes .sw { display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: 12px; background: #fff; border: 2px solid transparent; color: var(--dark); text-align: left; font-size: 12.5px; font-weight: 700; }
  #themes .sw:hover { background: #fff; border-color: rgba(80,55,30,0.18); }
  #themes .sw.on { border-color: var(--accent); }
  #themes .sw svg { width: 100%; height: auto; display: block; border-radius: 7px; }

  /* dialogs */
  .dlg { position: absolute; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; background: rgba(10,7,4,0.55); }
  .dlg.show { display: flex; }
  .card { background: #fbf4e6; color: var(--dark); border-radius: 18px; padding: 22px 24px; min-width: 280px; max-width: calc(100vw - 32px); max-height: calc(100% - 24px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5); text-align: center; }
  .card .dh { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
  .card p { margin: 0 0 16px; color: #6b5640; }
  .card select { background: #fff; color: var(--dark); border-color: rgba(80,55,30,0.25); width: 100%; margin: 4px 0 16px; }
  .card button { background: #fff; color: var(--dark); border-color: rgba(80,55,30,0.25); margin: 0 4px; }
  .card button.go { background: linear-gradient(#e0a24c, #c47a22); color: #fff; border-color: #a5631a; }
  .chk { display: flex; gap: 8px; align-items: center; justify-content: center; margin: -6px 0 16px; font-size: 14px; color: #6b5640; cursor: pointer; }
  #overBig { font: 500 46px/1 var(--mono); margin: 4px 0 6px; color: var(--dark); }
  #overRows { margin: 0 auto 14px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  #overRows td { padding: 3px 10px; text-align: left; color: #4a3c2c; }
  #overRows td:last-child { text-align: right; font: 500 15px var(--mono); }
  #overRows tr.win td { color: var(--dark); font-weight: 800; }
  #overCoach { text-align: left; margin: 0 0 16px; font-size: 14px; color: #4a3c2c; max-width: 380px; }
  #overCoach p { margin: 0 0 6px; color: inherit; }
  #overCoach .tip { color: #8a5a1a; }

  #more { display: flex; align-items: center; justify-content: center; height: 44px; color: var(--muted); text-decoration: none; font-size: 14px; border-top: 1px solid rgba(255,240,220,0.08); }
  article { padding: 8px 16px 48px; }
  article > div { max-width: 720px; margin: 0 auto; }
  article h2 { font-size: 22px; margin: 32px 0 10px; }
  article h3 { font-size: 17px; margin: 22px 0 6px; }
  article p, article li { font-size: 16px; line-height: 1.6; color: #cfc3b3; }
  article strong { color: #f1e7d6; }
  article a { color: #e9c58a; }
  .boxes { width: 100%; border-collapse: collapse; font-size: 15px; color: #cfc3b3; margin: 8px 0; }
  .boxes th, .boxes td { text-align: left; padding: 7px 10px; border-bottom: 1px solid rgba(255,240,220,0.1); vertical-align: top; }
  .boxes th { color: #f1e7d6; font-weight: 700; }
  .boxes td:first-child { white-space: nowrap; color: #f1e7d6; }
  .boxes td.d { white-space: nowrap; letter-spacing: 1px; }
  .note { font-size: 13px !important; color: var(--muted) !important; }
  footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 40px; }
  footer a { color: #e9c58a; }

  /* phones and portrait: card along the bottom, upper and lower sections side by side */
  body.stack #card { left: 8px; right: 8px; top: auto; bottom: max(8px, env(safe-area-inset-bottom)); width: auto; max-height: none; display: flex; gap: 10px; padding: 6px 8px 8px; border-radius: 14px; }
  body.stack #card .sec { flex: 1; }
  body.stack #card .sec + .sec { margin-top: 0; }
  body.stack #card th, body.stack #card td { height: 23px; font-size: 12.5px; padding: 0 3px; }
  body.stack #card td { font-size: 13px; min-width: 30px; }
  body.stack #card thead th { height: 20px; font-size: 9.5px; }
  body.stack #card .par { display: none; }
  body.stack #card tr.tot th, body.stack #card tr.tot td { height: 26px; font-size: 14px; }
  body.stack #bar { bottom: auto; left: 8px; right: 8px; transform: none; border-radius: 16px; padding: 6px 6px 6px 14px; }
  body.stack #status { flex: 1; max-width: none; }
  body.stack #coach { bottom: auto; }
  @media (max-width: 560px) {
    h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    header { gap: 6px; padding: 0 8px 0 10px; }
    header button { padding: 7px 9px; }
    .long { display: none; } .short { display: inline; }
    #bar { padding: 6px 6px 6px 14px; gap: 8px; }
    #status { font-size: 13px; max-width: 200px; }
    #coach { font-size: 13px; }
  }
  /* big moment text: Yatzy!, upper bonus */
  #flash { position: absolute; z-index: 5; left: 50%; top: 40%; transform: translate(-50%, -50%); font: 800 34px var(--ui); color: #fff7e6; letter-spacing: -0.5px;
    text-shadow: 0 3px 18px rgba(0,0,0,0.55); opacity: 0; pointer-events: none; white-space: nowrap; }
  #flash.show { animation: flash 1.7s ease-out forwards; }
  @keyframes flash { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
    70% { opacity: 1; transform: translate(-50%, -60%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -75%) scale(1); } }

  /* the card's own instruction line, and the open boxes when it's time to pick */
  #cardTip { height: 26px; margin: -2px -4px 6px; padding: 0 10px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
    font-size: 12.5px; font-weight: 700; color: #8a7558; background: rgba(80,60,35,0.06); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #cardTip.go { color: #fff; background: linear-gradient(#e0a24c, #c47a22); }
  #card.pick td.open { color: rgba(43,33,24,0.62); background: rgba(196,122,34,0.12); box-shadow: inset 0 0 0 1px rgba(196,122,34,0.35); border-radius: 6px; }
  #card.pick td.open.zero { color: rgba(43,33,24,0.38); background: rgba(196,122,34,0.05); box-shadow: inset 0 0 0 1px rgba(196,122,34,0.18); }
  #card.nudge td.open { animation: nudge 0.55s ease-in-out 2; }
  @keyframes nudge { 50% { background: rgba(224,162,76,0.45); box-shadow: inset 0 0 0 2px #c47a22; } }
  #card .secs { display: block; }
  body.stack #card { flex-direction: column; gap: 0; }
  body.stack #card .secs { display: flex; gap: 10px; }
  body.stack #cardTip { height: 22px; margin: 0 0 4px; font-size: 11.5px; }
