:root {
  --bg: #0f1117; --panel: #171a24; --cell: #222737; --line: #2c3246;
  --ink: #eef1f8; --dim: #8b93a8;
  --a: #ff9040; --b: #4aa8ff; --hot: #ffd84a; --bad: #ff5468; --ok: #5fe08a;
  --bw: min(100vw - 20px, 100vh - 358px, 460px);
  --bw: min(100vw - 20px, 100dvh - 358px, 460px);
  --cs: calc(var(--bw) / 8);
  /* System fonts only. CJK and Hangul fallbacks are ordered per language so Han characters get the right regional glyphs. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang TC", "Hiragino Sans", "Apple SD Gothic Neo", "Noto Sans TC", "Noto Sans JP", "Noto Sans KR", "Microsoft JhengHei", "Yu Gothic UI", "Malgun Gothic", system-ui, sans-serif;
}
:root:lang(zh-Hant) { --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif; }
:root:lang(ja) { --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif; }
/* Korean breaks lines at spaces, not inside words; CJK taglines break only at their separators. */
:root:lang(ko) body { word-break: keep-all; overflow-wrap: anywhere; }
:root:lang(ja) .tag, :root:lang(zh-Hant) .tag { word-break: keep-all; }
:root:lang(ko) { --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; overscroll-behavior: none; }
body { font: 600 16px/1.35 var(--font); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, input { font-family: inherit; }
[hidden] { display: none !important; }
#app { height: 100vh; height: 100dvh; max-width: 480px; margin: 0 auto; position: relative; padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom)); }
.screen { height: 100%; display: flex; flex-direction: column; align-items: center; }

/* ---------- lobby / waiting ---------- */
#lobby, #wait { justify-content: flex-start; gap: 14px; padding: 0 22px; overflow-y: auto; }
/* Centred while it fits; on a short screen nothing shrinks and it scrolls from the top (the spacers' auto margins centre it). */
#lobby > *, #wait > * { flex-shrink: 0; }
#lobby::before, #lobby::after, #wait::before, #wait::after { content: ""; margin: auto 0; }
#lobby::before { min-height: 26px; } /* keeps the logo clear of the language button when the lobby scrolls */
.logo { font-size: min(68px, calc((min(100vw, 480px) - 64px) * 1.32 / var(--logo-chars, 5))); font-weight: 900; letter-spacing: 1px; margin: 0; line-height: 1; white-space: nowrap; }
.logo i { font-style: normal; color: var(--a); } .logo b { color: var(--b); }
.tag { margin: 0 0 14px; color: var(--dim); letter-spacing: .5px; text-align: center; text-wrap: balance; }
.field { width: 100%; height: 54px; border-radius: 16px; border: 2px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-size: 18px; text-align: center; outline: none; -webkit-user-select: text; user-select: text; }
.field:focus { border-color: var(--b); }
.btn { width: 100%; height: 56px; border: 0; border-radius: 16px; background: var(--line); color: var(--ink); font: inherit; font-size: 19px; font-weight: 800; letter-spacing: 1px; cursor: pointer; transition: transform .08s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(100deg, var(--a), #ffb04a); color: #23130a; }
.join { display: grid; grid-template-columns: 1fr 110px; gap: 10px; width: 100%; }
.msg { margin: 0; min-height: 22px; color: var(--dim); }
.msg.err { color: var(--bad); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
.bigcode { font-size: 84px; font-weight: 900; letter-spacing: 10px; padding-left: 10px; color: var(--hot); line-height: 1.1; font-variant-numeric: tabular-nums; }
.how { margin: 14px 0 0; padding: 14px 16px 14px 36px; background: var(--panel); border-radius: 16px; color: var(--ink); font-weight: 500; width: 100%; }
.how li { margin: 6px 0; } .how small { color: var(--dim); }
.top { width: 100%; font-size: 13px; color: var(--dim); font-weight: 500; }
.top .row { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 5px 2px; border-top: 1px solid var(--line); }
.top .row b { color: var(--ink); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .row.me b { color: var(--hot); }
.top .row.gap { border-top-style: dashed; }
.top .tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 14px; margin: 6px 0 4px; }
.top .tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 2px 4px; color: var(--dim); font: inherit; font-size: 12px; font-weight: 700; letter-spacing: 1px; cursor: pointer; }
.top .tab.on { color: var(--ink); border-bottom-color: var(--hot); }
.top .empty { margin: 6px 0 0; text-align: center; }
#back { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 17px; letter-spacing: .3px; padding: 0 14px; }
#back .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#back .star { flex: none; letter-spacing: 0; }

/* ---------- game ---------- */
#game { gap: 7px; touch-action: none; justify-content: center; }
.hint { margin: 2px 0 0; width: var(--bw); text-align: center; font-size: 12.5px; line-height: 1.6; color: var(--dim); font-weight: 500; }
.hint b { color: var(--hot); font-weight: 700; }
.hud { width: var(--bw); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 34px; }
.hl { display: flex; align-items: center; gap: 8px; }
.help { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid var(--line); background: none; color: var(--dim); font: inherit; font-size: 14px; font-weight: 800; cursor: pointer; }
.card .how { text-align: left; background: var(--bg); margin: 12px 0 16px; font-size: 15px; }
.card .how b { color: var(--hot); }
.hearts { font-size: 22px; letter-spacing: 3px; color: var(--bad); }
.hearts .gone { color: var(--line); }
.stage { font-size: 17px; font-weight: 800; letter-spacing: .5px; white-space: nowrap; }
.stage small { color: var(--dim); font-weight: 600; } .stage .star { color: var(--hot); margin-left: 4px; }
.left { justify-self: end; font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.left small { font-size: 13px; font-weight: 700; color: var(--dim); align-self: flex-end; padding-bottom: 5px; }
.left.low { color: var(--bad); animation: pulse .7s ease-in-out infinite; } .left.low small { color: var(--bad); }
.bar { width: var(--bw); height: 24px; border-radius: 12px; background: var(--panel); position: relative; overflow: hidden; }
#barFill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 12px; background: linear-gradient(90deg, var(--a), var(--hot)); transition: width .35s cubic-bezier(.2, .9, .3, 1); }
/* daily challenge: marks at the bronze and silver thresholds, each with its medal; the bar's end is gold */
.bar.daily::before, .bar.daily::after { content: "\1F949"; position: absolute; top: 4px; bottom: 4px; left: var(--t1); padding-left: 3px; border-left: 2px solid rgba(255, 255, 255, .45); font-size: 11px; line-height: 16px; z-index: 1; }
.bar.daily::after { content: "\1F948"; left: var(--t2); }
#barText { z-index: 2; }
.bar.daily #barText { place-items: center start; padding-left: 12px; } /* keep the score clear of the marks */
.bar.daily #barText::after { content: "\1F947"; position: absolute; right: 8px; top: 0; bottom: 0; display: grid; place-items: center; font-size: 12px; }
#barText { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.peer { width: var(--bw); height: 50px; display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.pname { color: var(--dim); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.pname::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.pname.on::before { background: var(--pc-col); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc-col) 25%, transparent); }
.pname.off { opacity: .5; }
.boardWrap { position: relative; width: var(--bw); height: var(--bw); }
.board { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; padding: 5px; background: var(--panel); border-radius: 14px; }
.cell { border-radius: 22%; background: var(--cell); position: relative; }
.cell.p1, .pc.s0 { background: var(--a); box-shadow: inset 0 -3px rgba(0, 0, 0, .18), inset 0 2px rgba(255, 255, 255, .28); }
.cell.p2, .pc.s1 { background: var(--b); box-shadow: inset 0 -3px rgba(0, 0, 0, .18), inset 0 2px rgba(255, 255, 255, .28); }
.cell.p3 { background: #59606f radial-gradient(circle at 32% 30%, rgba(255, 255, 255, .22) 0 14%, transparent 15%); box-shadow: inset 0 -3px rgba(0, 0, 0, .3), inset 0 2px rgba(255, 255, 255, .14); } /* a stone (endless mode) */
.cell.g0 { background: #9c613c; background: color-mix(in srgb, var(--a) 55%, var(--cell)); }
.cell.g1 { background: #386ea5; background: color-mix(in srgb, var(--b) 55%, var(--cell)); }
.cell.pg0 { outline: 2px dashed var(--a); outline-offset: -3px; }
.cell.pg1 { outline: 2px dashed var(--b); outline-offset: -3px; }
.cell.will { filter: brightness(1.35); box-shadow: 0 0 0 2px var(--hot); z-index: 1; }
.cell.drop { animation: drop .16s ease-out; }
.cell.pop { animation: pop .3s ease-in forwards; z-index: 2; }
.ping { position: absolute; width: var(--cs); height: var(--cs); border-radius: 50%; border: 3px solid var(--hot); pointer-events: none; animation: ping .7s ease-out forwards; }
.pts { position: absolute; transform: translate(-50%, -50%); font-size: 30px; font-weight: 900; color: var(--hot); text-shadow: 0 2px 0 rgba(0, 0, 0, .5); pointer-events: none; animation: rise .9s ease-out forwards; white-space: nowrap; z-index: 5; }
.combo { position: absolute; top: -14px; right: -4px; padding: 4px 12px; border-radius: 999px; background: var(--hot); color: #2a2100; font-weight: 900; font-size: 15px; letter-spacing: .5px; z-index: 4; box-shadow: 0 4px 12px rgba(0, 0, 0, .4); }
.combo.bump { animation: bump .3s ease-out; }
.combo.max { background: linear-gradient(100deg, #ff5d8f, var(--hot)); }
.combo.risk { background: var(--bad); color: #fff; animation: shake .35s linear infinite; }
.toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px 22px; border-radius: 18px; background: rgba(15, 17, 23, .92); border: 2px solid var(--line); text-align: center; font-size: 22px; font-weight: 900; z-index: 6; width: max-content; max-width: calc(var(--bw) - 20px); line-height: 1.2; text-wrap: balance; pointer-events: none; animation: toast 1.9s ease forwards; }
.toast small { display: block; font-size: 14px; color: var(--dim); font-weight: 600; margin-top: 2px; }
.toast.good { border-color: var(--ok); color: var(--ok); } .toast.bad { border-color: var(--bad); color: var(--bad); }
.status { height: 24px; max-width: var(--bw); font-size: 15px; color: var(--dim); letter-spacing: .5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.mine { color: var(--hot); font-weight: 800; }

/* ---------- trays & pieces ---------- */
.tray { width: var(--bw); display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; --ps: min(21px, calc((var(--bw) - 46px) / 15)); }
.tray .slot { height: calc(var(--ps) * 5 + 12px); border-radius: 14px; background: var(--panel); display: grid; place-items: center; touch-action: none; border: 2px solid transparent; transition: border-color .2s, opacity .2s; }
.myturn #myTray .slot { border-color: var(--me); border-color: color-mix(in srgb, var(--me) 55%, transparent); }
.tray.small { width: auto; --ps: 8px; gap: 6px; }
.tray.small .slot { width: 50px; height: 46px; border-radius: 10px; }
.piece { display: grid; gap: 2px; grid-template-columns: repeat(var(--w), var(--ps)); grid-auto-rows: var(--ps); pointer-events: none; }
.pc { border-radius: 22%; } .pc.x { visibility: hidden; }
.slot.dead .piece { opacity: .3; filter: grayscale(.8); }
.slot.lifted .piece { opacity: .2; }
#dragLayer { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#dragLayer .piece { position: absolute; left: 0; top: 0; --ps: calc(var(--cs) - 4px); gap: 3px; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .5)); will-change: transform; }

/* ---------- end overlay ---------- */
.overlay { position: absolute; inset: 0; background: rgba(8, 9, 13, .86); display: grid; place-items: center; padding: 18px; z-index: 30; animation: fade .35s ease; overflow-y: auto; }
.card { width: 100%; background: var(--panel); border-radius: 22px; padding: 22px 18px 16px; text-align: center; border: 2px solid var(--line); }
.kicker { margin: 0; color: var(--dim); letter-spacing: 3px; font-size: 13px; }
.card h2 { margin: 6px 0 4px; font-size: 34px; font-weight: 900; line-height: 1.15; text-wrap: balance; }
#payTitle { font-size: 28px; margin-bottom: 8px; }
.card h2.near { color: var(--hot); } .card h2.win { color: var(--ok); }
.sub { margin: 0 0 14px; color: var(--dim); }
.best { margin: -6px 0 14px; font-size: 13px; color: var(--dim); } .best b { color: var(--hot); }
.endlink { display: block; margin: 6px auto 0; }
.goal { margin: -10px 0 14px; font-size: 13px; color: var(--hot); font-weight: 700; text-wrap: balance; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
.stats div { background: var(--bg); border-radius: 12px; padding: 8px 2px; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stats small { display: block; font-size: 11px; color: var(--dim); font-weight: 600; letter-spacing: .5px; line-height: 1.25; }

/* ---------- language, account, trial ---------- */
#lobby { position: relative; }
.langbtn { position: absolute; top: 4px; right: 0; display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel); color: var(--dim); font-size: 14px; font-weight: 700; cursor: pointer; }
.langbtn.inline { position: static; height: 30px; font-size: 13px; }
.globe { width: 15px; height: 15px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='M2.5 12h19M12 2.5c3.4 3.4 3.4 15.6 0 19M12 2.5c-3.4 3.4-3.4 15.6 0 19'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='M2.5 12h19M12 2.5c3.4 3.4 3.4 15.6 0 19M12 2.5c-3.4 3.4-3.4 15.6 0 19'/%3E%3C/svg%3E") center / contain no-repeat; }
.langmenu { position: fixed; z-index: 60; background: #fff; border-radius: 18px; padding: 8px 0; box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 12px 40px rgba(0, 0, 0, .45); border: 1px solid #e3e3ea; animation: fade .15s ease; }
.langmenu button { display: flex; width: 100%; align-items: center; justify-content: space-between; padding: 13px 22px; border: 0; background: none; color: #1c1c22; font-size: 18px; font-weight: 500; text-align: left; cursor: pointer; -webkit-user-select: none; }
.langmenu button:active { background: #f1f0f7; }
.langmenu button.on { color: #2b1b8f; font-weight: 800; }
.langmenu button.on::after { content: ""; width: 18px; height: 14px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 14' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.8 7.4l4.6 4.6L16.2 1.8'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 14' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.8 7.4l4.6 4.6L16.2 1.8'/%3E%3C/svg%3E") center / contain no-repeat; }
.account { width: 100%; background: var(--panel); border-radius: 16px; padding: 12px 14px 8px; text-align: center; }
.accline { margin: 0; color: var(--ink); font-size: 15px; }
.accline.member { color: var(--ok); } .accline.out { color: var(--hot); }
.accline small { display: block; margin-top: 2px; font-size: 12px; color: var(--dim); font-weight: 500; overflow-wrap: anywhere; }
.btn.small { height: 46px; margin-top: 10px; font-size: 16px; letter-spacing: .3px; }
.acclinks { display: flex; flex-wrap: wrap; gap: 4px 18px; justify-content: center; margin-top: 4px; }
.acclinks.col { flex-direction: column; align-items: center; gap: 0; margin-top: 8px; }
.link { background: none; border: 0; padding: 7px 2px; color: var(--b); font-size: 14px; font-weight: 700; cursor: pointer; }
.fine { margin: 8px 0 0; font-size: 12px; color: var(--dim); font-weight: 500; }
.card .msg:empty { display: none; }
.card .field { margin: 4px 0 10px; }
.cardtop { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.trial { position: absolute; top: -12px; left: -4px; padding: 3px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--dim); font-size: 12px; font-weight: 800; z-index: 4; font-variant-numeric: tabular-nums; white-space: nowrap; box-shadow: 0 3px 10px rgba(0, 0, 0, .35); }
.trial.low { color: var(--hot); border-color: color-mix(in srgb, var(--hot) 55%, transparent); }
.trial.out { color: #fff; background: var(--bad); border-color: var(--bad); }
.trial.paused { opacity: .55; }
.banner { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 70; width: max-content; max-width: min(92vw, 440px); padding: 10px 16px; border-radius: 14px; background: rgba(15, 17, 23, .96); border: 2px solid var(--line); text-align: center; font-size: 15px; font-weight: 800; animation: fade .3s ease; }
.banner.good { border-color: var(--ok); color: var(--ok); } .banner.bad { border-color: var(--bad); color: var(--bad); }
#pay, #signin { z-index: 40; } #signin { z-index: 45; }

@keyframes pulse { 50% { opacity: .45; } }
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { transform: scale(.55); } }
@keyframes pop { 30% { transform: scale(1.18); filter: brightness(2.2); } 100% { transform: scale(0); opacity: 0; } }
@keyframes ping { from { transform: scale(.4); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@keyframes rise { from { opacity: 0; margin-top: 10px; } 20% { opacity: 1; } to { opacity: 0; margin-top: -60px; } }
@keyframes bump { 40% { transform: scale(1.35) rotate(-4deg); } }
@keyframes shake { 25% { transform: translateX(-2px) rotate(-2deg); } 75% { transform: translateX(2px) rotate(2deg); } }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 20% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- shorter screens: drop the hint, then tighten everything ---------- */
@media (max-height: 720px) {
  :root { --bw: min(100vw - 20px, 100vh - 314px, 460px); --bw: min(100vw - 20px, 100dvh - 314px, 460px); }
  .hint { display: none; }
}
@media (max-height: 620px) {
  :root { --bw: min(100vw - 20px, 100vh - 262px, 460px); --bw: min(100vw - 20px, 100dvh - 262px, 460px); }
  #game { gap: 4px; }
  .peer { height: 40px; }
  .tray { --ps: min(15px, calc((var(--bw) - 46px) / 15)); }
  .tray.small { --ps: 7px; } .tray.small .slot { height: 40px; }
  .logo { font-size: min(54px, calc((min(100vw, 480px) - 64px) * 1.32 / var(--logo-chars, 5))); } .bigcode { font-size: 64px; }
  .card .how { margin: 8px 0 12px; font-size: 14px; } .card .how li { margin: 4px 0; }
}
