/* Clip Cricket: flat and calm. Colours come from the table colour and the time of day (set by the game on :root);
   the values here are the daytime sage table, used until the script has run. */
:root {
  --bg: #EEF2EF; --card: #FBFCFB; --ink: #24302A; --soft: #5F6E66; --accent: #3B7A5D; --on-accent: #FFFFFF;
  --danger: #B8473C; --gold: #E9D48A; --gold-ink: #4A3B08; --table: #A3C0AE;
  --line: rgba(30, 40, 35, 0.10); --tint: rgba(30, 40, 35, 0.05); --dim: rgba(20, 28, 24, 0.28);
  --shadow: 0 12px 36px rgba(20, 30, 25, .14);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Sinhala", "Iskoola Pota", "Nirmala UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; overflow: hidden; transition: background-color .5s ease, color .5s ease; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.btn:focus-visible { outline-offset: 3px; }

#app {
  position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- top bar: the score, and one menu button ---- */
#hud { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 18px 0; }
#score { min-width: 0; flex: 1 1 auto; }
#score .label { font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--soft); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#runs { font-size: clamp(44px, 12vw, 60px); line-height: 1.02; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
#runs.bump { animation: bump .45s cubic-bezier(.2, 1.5, .4, 1); }
#score .best { margin-top: 3px; font-size: 14px; color: var(--soft); white-space: nowrap; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#score .best b { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.chase { font-size: 12.5px; font-weight: 800; color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); border-radius: 999px; padding: 2px 9px; font-variant-numeric: tabular-nums; }
.chase.hot { background: var(--gold); color: var(--gold-ink); }
.chase.pulse { animation: chase .9s cubic-bezier(.2, 1.4, .4, 1); }
#wordmark { align-self: center; font-weight: 800; font-size: 15px; letter-spacing: .02em; color: var(--soft); display: none; }
#wordmark span { color: var(--accent); }
@media (min-width: 560px) { #wordmark { display: block; } }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--tint); border: 0; transition: transform .12s ease, background-color .2s ease; padding: 0; flex: none; }
.icon:active { transform: scale(.92); }
.icon svg { width: 22px; height: 22px; stroke: var(--ink); fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---- stage ---- */
#stage { position: relative; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#pop { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; opacity: 0; width: max-content; max-width: 92%; }
#pop .pill { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 28px 13px; border-radius: 26px; background: color-mix(in srgb, var(--card) 94%, transparent); box-shadow: var(--shadow); }
#pop-main { font-size: clamp(34px, 10vw, 56px); font-weight: 900; letter-spacing: -.02em; line-height: 1.05; color: var(--ink); }
#pop-sub { font-size: clamp(14px, 4vw, 18px); font-weight: 800; color: var(--soft); }
#pop.show { animation: pop 1.45s ease both; }
#pop.show.big { animation-duration: 1.8s; }
#pop.show.out #pop-main { color: var(--danger); }
#pop.show.six #pop-main, #pop.show.big #pop-sub { color: var(--accent); }
#pop.show.big .pill { background: var(--gold); }
#pop.show.big #pop-main, #pop.show.big #pop-sub { color: var(--gold-ink); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -40%) scale(.7); } 14% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 26% { transform: translate(-50%, -50%) scale(1); } 78% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -58%) scale(1); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.16); } 100% { transform: scale(1); } }
@keyframes chase { 0% { transform: scale(1); } 35% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---- hint ---- */
/* a fixed height: a hint of one line, two lines or none must never resize the table (that looked like a refresh) */
#hint { padding: 4px 22px 14px; text-align: center; height: 72px; display: grid; place-items: center; overflow: hidden; }
#hint-text { margin: 0; font-size: 15.5px; font-weight: 600; color: var(--soft); line-height: 1.4; max-width: 34em; text-wrap: balance; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
#hint-text.flash { color: var(--ink); }

/* ---- layers: sheets and cards ---- */
.layer { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; background: var(--dim); animation: fade .2s ease; }
.layer[hidden] { display: none; }
.layer.center { align-items: center; padding: 16px; }
@media (min-width: 640px) { .layer { align-items: center; padding: 20px; } }
.panel { width: min(100%, 440px); max-height: min(92dvh, 760px); overflow: auto; background: var(--card); color: var(--ink); border-radius: 26px 26px 0 0; padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); animation: rise .26s cubic-bezier(.2, .9, .3, 1); overscroll-behavior: contain; }
.layer.center .panel, .panel.card { border-radius: 26px; padding-bottom: 22px; }
@media (min-width: 640px) { .panel { border-radius: 26px; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel h2 { margin: 0 0 12px; font-size: 20px; font-weight: 800; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel .close { width: 40px; height: 40px; border-radius: 12px; }

.row { display: grid; gap: 7px; margin: 14px 0; }
.row > .lbl { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--soft); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--tint); }
.seg button { border: 0; background: transparent; padding: 8px 6px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--soft); display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; }
.seg button[aria-checked="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.seg svg { width: 20px; height: 20px; flex: none; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch { height: 58px; border-radius: 14px; border: 2px solid transparent; padding: 0 10px 8px; display: flex; align-items: flex-end; font-weight: 700; font-size: 13px; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.swatch span { background: color-mix(in srgb, var(--card) 80%, transparent); border-radius: 8px; padding: 2px 7px; }
.swatch[aria-checked="true"] { border-color: var(--accent); }
.note { font-size: 13px; color: var(--soft); margin: 4px 0 0; line-height: 1.45; }
.linkbtn { background: none; border: 0; padding: 10px 4px; color: var(--accent); font-weight: 700; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.links { display: flex; justify-content: center; gap: 22px; margin-top: 6px; }

.btn { border: 0; border-radius: 16px; padding: 14px 20px; font-weight: 800; font-size: 17px; background: var(--accent); color: var(--on-accent); min-height: 54px; width: 100%; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--tint); color: var(--ink); }
.btns { display: grid; gap: 10px; margin-top: 18px; }

/* ---- the menu ---- */
.menu { display: grid; gap: 8px; }
.menu button { display: grid; grid-template-columns: 40px minmax(0, 1fr) 20px; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 16px; border: 0; background: var(--tint); text-align: left; min-height: 60px; }
.menu .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--card); }
.menu .ic svg, .menu .chev svg { width: 21px; height: 21px; stroke: var(--ink); fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.menu .chev svg { width: 18px; height: 18px; stroke: var(--soft); }
.menu .tt { display: block; font-weight: 800; font-size: 16px; }
.menu small { display: block; font-weight: 600; font-size: 13px; color: var(--soft); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toggles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 14px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 10px 14px; border-radius: 16px; border: 0; background: var(--tint); font-weight: 700; font-size: 15px; min-height: 54px; }
.switch .knob { width: 44px; height: 26px; border-radius: 13px; background: color-mix(in srgb, var(--ink) 20%, transparent); position: relative; transition: background-color .2s ease; flex: none; }
.switch .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s ease; }
.switch[aria-checked="true"] .knob { background: var(--accent); }
.switch[aria-checked="true"] .knob::after { transform: translateX(18px); }

/* ---- game over ---- */
.over { text-align: center; }
.over .t { font-size: 14px; letter-spacing: .16em; text-transform: uppercase; font-weight: 800; color: var(--danger); }
.over .big { font-size: clamp(64px, 20vw, 88px); font-weight: 900; line-height: 1.02; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.over .unit { font-size: 16px; font-weight: 700; color: var(--soft); margin-top: -2px; }
.over .why { margin: 10px 0 0; font-size: 15px; color: var(--soft); line-height: 1.4; }
.over .facts { margin: 8px 0 0; font-size: 14px; font-weight: 700; color: var(--soft); }
.over .badge { display: inline-block; margin-top: 12px; padding: 5px 14px; border-radius: 999px; background: var(--gold); color: var(--gold-ink); font-weight: 800; font-size: 14px; }
.over input { width: 100%; margin-top: 16px; padding: 13px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--tint); color: var(--ink); font: inherit; font-size: 17px; font-weight: 700; text-align: center; user-select: text; -webkit-user-select: text; }
.over input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
/* OUT: one tap anywhere starts the next innings */
#over { cursor: pointer; }
#over .links, #over input { cursor: auto; }
.over.tapagain .btn { animation: breathe 2.2s ease-in-out .8s infinite; }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .78; } }
.rank-name { width: 100%; margin: 0 0 10px; padding: 11px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--tint); color: var(--ink); font: inherit; font-size: 16px; font-weight: 700; user-select: text; -webkit-user-select: text; }
.rank-name:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---- ranking ---- */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto 26px; align-items: center; gap: 8px; padding: 11px 6px; border-bottom: 1px solid var(--line); font-weight: 700; }
.rank li:last-child { border-bottom: 0; }
.rank li.me { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 12px; border-bottom-color: transparent; }
.rank .n { color: var(--soft); font-variant-numeric: tabular-nums; text-align: center; }
.rank .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .rn { font-variant-numeric: tabular-nums; font-weight: 800; }
.rank .rn small { font-weight: 600; color: var(--soft); font-size: 12px; margin-left: 3px; }
.rank .shp { display: grid; place-items: center; }
.rank svg { width: 20px; height: 20px; fill: var(--soft); opacity: .8; }
.empty { text-align: center; color: var(--soft); padding: 26px 8px; }

/* ---- rules ---- */
.rules ol { margin: 0 0 6px; padding: 0; list-style: none; display: grid; gap: 14px; }
.rules li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; font-size: 15.5px; line-height: 1.45; }
.rules li i { font-style: normal; width: 34px; height: 34px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); display: grid; place-items: center; font-weight: 800; }
.rules .tag { text-align: center; margin: 0 0 16px; color: var(--soft); font-weight: 700; }

/* ---- multiplayer ---- */
.names { display: grid; gap: 8px; }
.names input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--tint); color: var(--ink); font: inherit; font-size: 16px; font-weight: 700; user-select: text; -webkit-user-select: text; }
.names input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.seg.locked { opacity: .5; }
.seg.locked button { cursor: not-allowed; }
.note.live { font-size: 15px; font-weight: 700; color: var(--ink); margin: 6px 0 2px; }
.over .who { font-size: clamp(34px, 10vw, 46px); font-weight: 900; line-height: 1.1; letter-spacing: -.02em; margin: 8px 0 2px; overflow-wrap: anywhere; }
.turn .t, .results .t { color: var(--accent); }
.stand { list-style: none; margin: 16px 0 0; padding: 0; text-align: left; }
.stand li { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 10px 6px; border-bottom: 1px solid var(--line); font-weight: 700; }
.stand li:last-child { border-bottom: 0; }
.stand li.first { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 12px; border-bottom-color: transparent; }
.stand .n { color: var(--soft); text-align: center; font-variant-numeric: tabular-nums; }
.stand .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stand .rn { font-variant-numeric: tabular-nums; font-weight: 800; }
.stand .rn small { font-weight: 600; color: var(--soft); font-size: 12px; margin-left: 3px; }

html[lang="si"] #hint-text, html[lang="si"] .panel { line-height: 1.55; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
