:root {
  --bg: #0a1640; --bg2: #13297e; --card: rgba(255,255,255,.07); --card2: rgba(255,255,255,.12);
  --line: rgba(255,255,255,.16); --ink: #fff; --muted: #b8c2ea; --gold: #f7c948; --flame: #ff7a30;
  --n: #7cc8ff; --g: #ffb347; --h: #c9b6ff; --s: #ff7d94; --bad: #ff8a8a;
  --heb: "Frank Ruehl CLM", "David", "Times New Roman", serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100vh; color: var(--ink); background-color: var(--bg); background-repeat: no-repeat;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(120% 60% at 50% -10%, rgba(255,122,48,.28), transparent 60%),
              linear-gradient(180deg, var(--bg2), var(--bg) 900px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.wrap { max-width: 560px; margin: 0 auto; padding: 12px 14px 40px; }

/* top bar */
.top { display: flex; align-items: center; gap: 8px; padding: 6px 0 10px; }
.top .title { flex: 1; min-width: 0; font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.icon-btn.back { font-size: 26px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--ink); }
.icon-btn { min-width: 44px; height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 15px; }
.brand { display: flex; align-items: center; gap: 12px; margin: 18px 0 22px; }
.brand h1 { margin: 0; font-size: 28px; letter-spacing: .3px; }
.brand p { margin: 2px 0 0; color: var(--muted); }
.flames { display: flex; gap: 5px; justify-content: center; margin: 4px 0 18px; }
.flames i { width: 8px; height: 14px; border-radius: 50% 50% 45% 45%; background: radial-gradient(circle at 50% 70%, #fff3b0, var(--flame) 70%); box-shadow: 0 0 10px rgba(255,170,60,.7); }
.flames i.shamash { transform: translateY(-6px); }

/* cards and buttons */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 0 0 12px; }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn { min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); font-weight: 600; }
.btn.primary { background: var(--flame); border-color: var(--flame); color: #1a0d00; }
.btn.big { width: 100%; min-height: 54px; font-size: 18px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 0; }
input[type=text], input[type=number], input:not([type]) {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; font-size: 16px;
  border: 1px solid var(--line); background: rgba(0,0,0,.25);
}

.gap { height: 10px; }
.msg { min-height: 1.4em; margin: 8px 0 0; color: var(--gold); }
.banner { position: sticky; top: 0; z-index: 5; margin: 0 -14px 8px; padding: 8px 14px; background: #7a1f2b; font-size: 14px; text-align: center; }

/* home */
.game-list { list-style: none; margin: 0; padding: 0; }
.game-list li { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 8px 0; }
.game-list li:first-child { border-top: 0; }
.game-list a { flex: 1; min-width: 0; color: var(--ink); text-decoration: none; padding: 6px 0; }
.game-list a b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* play: pot and turn */
.head { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.turn-name { font-size: 26px; font-weight: 800; line-height: 1.15; }
.turn-next { color: var(--muted); font-size: 14px; margin-top: 2px; }
.warn { color: var(--bad); font-weight: 700; margin-top: 4px; }
.pot { text-align: center; padding: 8px 14px; border-radius: 14px; background: rgba(247,201,72,.12); border: 1px solid rgba(247,201,72,.45); }
.pot b { display: block; font-size: 34px; color: var(--gold); line-height: 1.1; }
.pot span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.last { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.last .heb { font-size: 48px; line-height: 1; width: 56px; text-align: center; }
.heb { font-family: var(--heb); font-weight: 700; }
.c-n { color: var(--n); } .c-g { color: var(--g); } .c-h { color: var(--h); } .c-s { color: var(--s); }

/* letter keys */
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 10px; }
.key { min-height: 104px; border-radius: 16px; border: 2px solid; background: rgba(255,255,255,.06); display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; padding: 8px 14px; text-align: left; }
.key .heb { font-size: 56px; line-height: 1; }
.key b { display: block; font-size: 18px; }
.key small { display: block; color: var(--muted); font-size: 13px; }
.key.n { border-color: var(--n); } .key.g { border-color: var(--g); } .key.h { border-color: var(--h); } .key.s { border-color: var(--s); }
.key:active { transform: scale(.97); }
.key:disabled { opacity: .35; }

/* ticker */
.ticker { border-left: 4px solid var(--flame); }
.ticker .t1 { font-weight: 700; }
.ticker .t2 { color: var(--muted); min-height: 1.4em; margin-top: 2px; }

/* players */
.players { display: grid; gap: 10px; margin-bottom: 12px; }
.player { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.player.up { border-color: var(--flame); box-shadow: 0 0 0 2px rgba(255,122,48,.35); }
.player.out { opacity: .5; }
.player.won { border-color: var(--gold); }
.pname { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.pname span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--card2); white-space: nowrap; }
.tag.up { background: var(--flame); color: #1a0d00; }
.tag.win { background: var(--gold); color: #2a1d00; }
.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.cell { text-align: center; border-radius: 10px; padding: 4px 0; background: rgba(0,0,0,.2); border: 1px solid transparent; }
.cell .heb { display: block; font-size: 22px; line-height: 1.1; }
.cell b { font-size: 18px; }
.cell small { color: var(--muted); }
.cell.near { border-color: var(--bad); }
.money { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* winner */
.winner { text-align: center; border-color: var(--gold); background: rgba(247,201,72,.14); }
.winner .big { font-size: 26px; font-weight: 800; color: var(--gold); }

/* dreidel */
.dreidel-box { text-align: center; }
.dreidel { width: 120px; height: 160px; transform-origin: 50% 90%; }
.dreidel.spinning { animation: wobble .18s linear infinite; }
@keyframes wobble { 0% { transform: rotate(-9deg) scaleX(1); } 50% { transform: rotate(0) scaleX(.82); } 100% { transform: rotate(9deg) scaleX(1); } }

/* folded sections */
details.card summary { cursor: pointer; font-weight: 700; min-height: 28px; list-style-position: inside; }
.bar { display: grid; grid-template-columns: 28px 1fr 84px; gap: 8px; align-items: center; margin: 6px 0; }
.bar i { display: block; height: 12px; border-radius: 6px; }
.log { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; max-height: 320px; overflow: auto; }
.who-spun { margin: 10px 0 0; padding: 0; list-style: none; font-size: 14px; }
.who-spun li { padding: 3px 0; border-top: 1px solid var(--line); }
.log li { padding: 4px 0; border-top: 1px solid var(--line); }

/* setup */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; border-radius: 99px; background: var(--card2); font-weight: 600; }
.chip button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.add { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.rules-list { margin: 0; padding-left: 18px; }
.rules-list li { margin: 2px 0; }

/* settings */
.set { border-top: 1px solid var(--line); padding: 10px 0; }
.set:first-of-type { border-top: 0; }
.set-head { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.set-head b { display: block; }
.set-head small { color: var(--muted); }
.set-body { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; color: var(--muted); }
.set-body input { width: 86px; min-height: 38px; text-align: center; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: rgba(255,255,255,.2); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--flame); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }

/* dialogs and pop-ups */
dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100% - 24px); border: 1px solid var(--line); border-radius: 18px; padding: 16px; background: #12235f; color: var(--ink); }
dialog::backdrop { background: rgba(0,0,10,.6); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
.choices { display: grid; gap: 8px; margin: 10px 0; }
.linkbox { word-break: break-all; font-size: 14px; padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,.3); margin: 6px 0; }
.pop { position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 10px); z-index: 20; width: min(420px, calc(100% - 32px));
  padding: 18px; border-radius: 18px; text-align: center; font-size: 22px; white-space: pre-line; font-weight: 800; background: #1b2f7a;
  border: 2px solid var(--gold); box-shadow: 0 12px 40px rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.pop.show { opacity: 1; transform: translate(-50%, 0); }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 21; width: min(460px, calc(100% - 24px));
  padding: 12px 14px; border-radius: 12px; background: #2b1340; border: 1px solid var(--bad); font-size: 15px; display: none; }
.toast.show { display: block; }

/* bigger screens (a laptop or TV showing the watch link) */
@media (min-width: 900px) {
  .wrap.game { max-width: 1100px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: start; }
  .wrap.game > .top, .wrap.game > .banner { grid-column: 1 / -1; }
  .turn-name { font-size: 34px; }
  .pot b { font-size: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  .dreidel.spinning { animation: none; }
  .pop, .switch span, .switch span::after { transition: none; }
}
.row + .btn.big, .players + .row { margin-top: 10px; }
