/* GummiRummy. Four looks set by data-theme on <html>: gummy (original), frosted, paper, velvet. Layout is shared. */

/* ---------- Look: Gummy (the original) ---------- */
:root, [data-theme="gummy"] {
  --font-ui: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --font-num: 'Fredoka', ui-rounded, system-ui, sans-serif;
  --num-weight: 700;
  --num-ls: -0.04em;
  --text: #4a2440;
  --text-soft: #8a5a7c;
  --page-bg:
    radial-gradient(40vmax 40vmax at 8% 10%, rgba(255, 190, 120, 0.45), transparent 60%),
    radial-gradient(45vmax 45vmax at 95% 15%, rgba(190, 160, 255, 0.40), transparent 60%),
    radial-gradient(50vmax 50vmax at 70% 100%, rgba(120, 230, 190, 0.35), transparent 60%),
    radial-gradient(40vmax 40vmax at 0% 100%, rgba(255, 120, 170, 0.35), transparent 60%),
    linear-gradient(160deg, #fff3f7, #ffe3ee);
  --page-color: #fff3f7;
  --tray-bg: rgba(255, 255, 255, 0.52);
  --tray-border: 2px solid rgba(255, 255, 255, 0.8);
  --tray-shadow: inset 0 3px 14px rgba(255, 255, 255, 0.9), inset 0 -10px 30px rgba(255, 110, 170, 0.10), 0 12px 34px rgba(200, 80, 130, 0.12);
  --tray-radius: 26px;
  --tray-dot: rgba(170, 90, 140, 0.16);
  --rack-bg: radial-gradient(120% 70% at 30% 0%, rgba(255, 255, 255, 0.55), transparent 45%), linear-gradient(180deg, #ffa4c7, #ff79ab);
  --rack-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), inset 0 -6px 0 rgba(180, 30, 90, 0.18), 0 10px 24px rgba(255, 80, 140, 0.28);
  --rack-border: 0;
  --rack-radius: 24px;
  --rack-dot: rgba(255, 255, 255, 0.45);
  --tile-top: #fffefb;
  --tile-radius: 18% / 14%;
  --tile-border: 0;
  --tile-shadow: inset 0 1.5px 0 #fff, inset 0 -3px 0 rgba(120, 70, 60, 0.07), 0 2px 0 rgba(150, 100, 90, 0.28), 0 4px 10px rgba(120, 50, 80, 0.16);
  --ink0: #e5194f; --ink1: #f26a00; --ink2: #139445; --ink3: #1d5bea;
  --face0: #ffedf2; --face1: #fff0e0; --face2: #e8f8ee; --face3: #eaf0ff;
  --pip: block;
  --card-bg: rgba(255, 255, 255, 0.7);
  --card-border: 1.5px solid rgba(255, 255, 255, 0.95);
  --card-shadow: 0 4px 14px rgba(200, 80, 130, 0.12);
  --card-radius: 18px;
  --chip-bg: rgba(255, 255, 255, 0.7);
  --btn-radius: 20px;
  --btn-gloss: radial-gradient(110% 80% at 28% 12%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 42%);
  --btn-inset: inset 0 -5px 0 rgba(0, 0, 0, 0.12), inset 0 2px 0 rgba(255, 255, 255, 0.5);
  --btn-border: 0;
  --btn-text: #fff;
  --go1: #6ae79b; --go2: #1fb864; --go-shadow: rgba(31, 184, 100, 0.35);
  --sa1: #8db1ff; --sa2: #4b7bff; --sa-shadow: rgba(75, 123, 255, 0.32); --sa-text: #fff;
  --sb1: #ffc46b; --sb2: #ff9418; --sb-shadow: rgba(255, 148, 24, 0.32); --sb-text: #fff;
  --un1: #ff8aa8; --un2: #f2416f; --un-shadow: rgba(242, 65, 111, 0.32);
  --wait1: #e8d6e2; --wait2: #cdb3c4;
  --sheet-bg: rgba(255, 255, 255, 0.94);
  --overlay-bg: rgba(255, 220, 235, 0.55);
  --soft-panel: #fff4f8;
  --fresh: #2ad08a;
  --bad: #e5194f;
  --p0: #22c38c; --p1: #ff6fa8; --p2: #ffa51f; --p3: #8a63ff;
  --show-blob: block; --show-mono: none;
  --jk-fill: url(#jg); --jk-stroke: none; --jk-ink: #3a1830; --jk-shine: 0.55;
}

/* ---------- Look: Frosted (grown-up candy) ---------- */
[data-theme="frosted"] {
  --font-ui: 'Outfit', system-ui, sans-serif;
  --font-num: 'Outfit', system-ui, sans-serif;
  --num-weight: 600;
  --num-ls: -0.03em;
  --text: #2b2838;
  --text-soft: #7a748c;
  --page-bg:
    radial-gradient(50vmax 40vmax at 0% 0%, rgba(255, 196, 214, 0.35), transparent 60%),
    radial-gradient(50vmax 40vmax at 100% 100%, rgba(190, 210, 255, 0.40), transparent 60%),
    linear-gradient(150deg, #f6f3f7, #eceaf2 55%, #e9eef4);
  --page-color: #f2f0f5;
  --tray-bg: rgba(255, 255, 255, 0.5);
  --tray-border: 1px solid rgba(255, 255, 255, 0.95);
  --tray-shadow: inset 0 1px 0 #fff, 0 24px 60px rgba(60, 50, 100, 0.08);
  --tray-radius: 22px;
  --tray-dot: rgba(60, 50, 100, 0.11);
  --rack-bg: linear-gradient(180deg, rgba(110, 90, 170, 0.13), rgba(110, 90, 170, 0.08));
  --rack-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 16px 40px rgba(60, 50, 100, 0.10);
  --rack-border: 1px solid rgba(255, 255, 255, 0.95);
  --rack-radius: 22px;
  --rack-dot: rgba(60, 50, 100, 0.12);
  --tile-top: rgba(255, 255, 255, 0.97);
  --tile-radius: 14% / 11%;
  --tile-border: 1px solid rgba(255, 255, 255, 1);
  --tile-shadow: inset 0 -2px 0 rgba(60, 50, 100, 0.05), 0 1px 2px rgba(50, 40, 80, 0.12), 0 8px 18px rgba(50, 40, 80, 0.10);
  --ink0: #d3245b; --ink1: #e0701b; --ink2: #128f68; --ink3: #3157d4;
  --face0: #fdf1f5; --face1: #fdf4ec; --face2: #eef8f4; --face3: #f0f3fd;
  --pip: none;
  --card-bg: rgba(255, 255, 255, 0.55);
  --card-border: 1px solid rgba(255, 255, 255, 0.95);
  --card-shadow: 0 8px 24px rgba(60, 50, 100, 0.07);
  --card-radius: 16px;
  --chip-bg: rgba(255, 255, 255, 0.6);
  --btn-radius: 16px;
  --btn-gloss: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0));
  --btn-inset: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  --go1: #23b285; --go2: #11906a; --go-shadow: rgba(17, 144, 106, 0.25);
  --sa1: rgba(255, 255, 255, 0.85); --sa2: rgba(255, 255, 255, 0.6); --sa-shadow: rgba(60, 50, 100, 0.10); --sa-text: #2b2838;
  --sb1: rgba(255, 255, 255, 0.85); --sb2: rgba(255, 255, 255, 0.6); --sb-shadow: rgba(60, 50, 100, 0.10); --sb-text: #2b2838;
  --un1: #ef7a9b; --un2: #d3245b; --un-shadow: rgba(211, 36, 91, 0.22);
  --wait1: #e4e1ea; --wait2: #d2cedb;
  --sheet-bg: rgba(255, 255, 255, 0.9);
  --overlay-bg: rgba(236, 234, 242, 0.6);
  --soft-panel: #f4f2f8;
  --fresh: #12a374;
  --p0: #128f68; --p1: #d3245b; --p2: #e0701b; --p3: #6b5bd6;
  --show-blob: none; --show-mono: flex;
  --jk-fill: url(#jg); --jk-ink: #2b2838; --jk-shine: 0.45;
}

/* ---------- Frosted, dark mode ---------- */
[data-theme="frosted"][data-mode="dark"] {
  --text: #f1ecf8;
  --text-soft: #b2a6c8;
  --page-bg:
    radial-gradient(60vmax 45vmax at 0% 0%, rgba(214, 70, 140, 0.22), transparent 60%),
    radial-gradient(60vmax 50vmax at 100% 100%, rgba(98, 84, 230, 0.28), transparent 60%),
    linear-gradient(155deg, #2a1843, #1c1030 55%, #150c25);
  --page-color: #1c1030;
  --tray-bg: rgba(255, 255, 255, 0.055);
  --tray-border: 1px solid rgba(255, 255, 255, 0.12);
  --tray-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 24px 60px rgba(0, 0, 0, 0.35);
  --tray-dot: rgba(255, 255, 255, 0.10);
  --rack-bg: linear-gradient(180deg, rgba(190, 170, 255, 0.17), rgba(190, 170, 255, 0.11));
  --rack-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.10), 0 16px 40px rgba(0, 0, 0, 0.35);
  --rack-border: 1px solid rgba(255, 255, 255, 0.14);
  --rack-dot: rgba(255, 255, 255, 0.12);
  --tile-top: #ffffff;
  --tile-border: 1px solid rgba(255, 255, 255, 0.9);
  --tile-shadow: inset 0 -2px 0 rgba(60, 50, 100, 0.08), 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 18px rgba(0, 0, 0, 0.32);
  --face0: #fbeef3; --face1: #fcf1e7; --face2: #eaf6f1; --face3: #edf0fc;
  --card-bg: rgba(255, 255, 255, 0.07);
  --card-border: 1px solid rgba(255, 255, 255, 0.13);
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  --chip-bg: rgba(255, 255, 255, 0.08);
  --go1: #3ccf9f; --go2: #17a079; --go-shadow: rgba(23, 160, 121, 0.3);
  --sa1: rgba(255, 255, 255, 0.14); --sa2: rgba(255, 255, 255, 0.07); --sa-shadow: rgba(0, 0, 0, 0.25); --sa-text: #f1ecf8;
  --sb1: rgba(255, 255, 255, 0.14); --sb2: rgba(255, 255, 255, 0.07); --sb-shadow: rgba(0, 0, 0, 0.25); --sb-text: #f1ecf8;
  --un1: #f0789b; --un2: #c9285a; --un-shadow: rgba(0, 0, 0, 0.3);
  --wait1: rgba(255, 255, 255, 0.10); --wait2: rgba(255, 255, 255, 0.05);
  --sheet-bg: #251a3b;
  --overlay-bg: rgba(12, 6, 22, 0.6);
  --soft-panel: rgba(255, 255, 255, 0.07);
  --fresh: #3fd6a4;
  --bad: #ff5f86;
  --p0: #3fd6a4; --p1: #ff6f9a; --p2: #ffa24d; --p3: #a08fff;
}
[data-theme="frosted"][data-mode="dark"] .logo { background: linear-gradient(90deg, #ff7fa6, #b4a6ff 60%, #86a2ff); -webkit-background-clip: text; background-clip: text; }
[data-theme="frosted"][data-mode="dark"] .sorts .jelly { border: 1px solid rgba(255, 255, 255, 0.14); }
[data-theme="frosted"][data-mode="dark"] .seg button.on { background: rgba(255, 255, 255, 0.14); }

/* ---------- Look: Paper Goods (stationery) ---------- */
[data-theme="paper"] {
  --font-ui: 'DM Sans', system-ui, sans-serif;
  --font-num: 'Fraunces', Georgia, serif;
  --num-weight: 700;
  --num-ls: -0.02em;
  --text: #2b2622;
  --text-soft: #7a6e62;
  --page-bg:
    radial-gradient(80vmax 60vmax at 50% 40%, rgba(255, 255, 255, 0.35), transparent 70%),
    repeating-linear-gradient(0deg, rgba(120, 90, 50, 0.025) 0 1px, transparent 1px 3px),
    #ece4d6;
  --page-color: #ece4d6;
  --tray-bg: #fbf8f1;
  --tray-border: 1px solid #e0d6c4;
  --tray-shadow: 0 1px 0 #fff inset, 0 2px 0 rgba(80, 60, 30, 0.05), 0 14px 30px rgba(80, 60, 30, 0.10);
  --tray-radius: 6px;
  --tray-dot: rgba(43, 38, 34, 0.20);
  --rack-bg:
    repeating-linear-gradient(105deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, #cfab7c, #bf9a69);
  --rack-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 10px 22px rgba(80, 60, 30, 0.18);
  --rack-border: 0;
  --rack-radius: 6px;
  --rack-dot: rgba(60, 40, 20, 0.22);
  --tile-top: #fffdf7;
  --tile-radius: 7% / 5%;
  --tile-border: 1px solid #d8cdb9;
  --tile-shadow: 1.5px 2px 0 rgba(43, 38, 34, 0.22), 0 3px 8px rgba(80, 60, 30, 0.08);
  --ink0: #cf3f27; --ink1: #c27d06; --ink2: #2b7449; --ink3: #253f8c;
  --face0: #fffdf7; --face1: #fffdf7; --face2: #fffdf7; --face3: #fffdf7;
  --pip: none;
  --card-bg: #fbf8f1;
  --card-border: 1px solid #e0d6c4;
  --card-shadow: 0 6px 14px rgba(80, 60, 30, 0.07);
  --card-radius: 6px;
  --chip-bg: #fbf8f1;
  --btn-radius: 8px;
  --btn-gloss: linear-gradient(transparent, transparent);
  --btn-inset: 3px 3px 0 #2b2622;
  --btn-border: 1.5px solid #2b2622;
  --btn-text: #fffdf7;
  --go1: #2b7449; --go2: #2b7449; --go-shadow: transparent;
  --sa1: #fffdf7; --sa2: #fffdf7; --sa-shadow: transparent; --sa-text: #2b2622;
  --sb1: #fffdf7; --sb2: #fffdf7; --sb-shadow: transparent; --sb-text: #2b2622;
  --un1: #cf3f27; --un2: #cf3f27; --un-shadow: transparent;
  --wait1: #e6dccb; --wait2: #e6dccb;
  --sheet-bg: #fbf8f1;
  --overlay-bg: rgba(236, 228, 214, 0.7);
  --soft-panel: #f3ede1;
  --fresh: #2b7449;
  --bad: #cf3f27;
  --p0: #2b7449; --p1: #cf3f27; --p2: #c27d06; --p3: #253f8c;
  --show-blob: none; --show-mono: flex;
  --jk-fill: #f4d35e; --jk-stroke: #2b2622; --jk-ink: #2b2622; --jk-shine: 0;
}

/* ---------- Look: Velvet Night (dark) ---------- */
[data-theme="velvet"] {
  --font-ui: 'Jost', system-ui, sans-serif;
  --font-num: 'Playfair Display', Georgia, serif;
  --num-weight: 800;
  --num-ls: -0.01em;
  --text: #f3e9dc;
  --text-soft: #b8a3b7;
  --page-bg: radial-gradient(120vmax 80vmax at 50% -10%, #43204f, #1b0f20 65%);
  --page-color: #1b0f20;
  --tray-bg:
    radial-gradient(130% 100% at 50% 0%, rgba(255, 255, 255, 0.06), transparent 60%),
    linear-gradient(180deg, #3d1c49, #2a1233);
  --tray-border: 1px solid rgba(214, 178, 106, 0.35);
  --tray-shadow: inset 0 0 70px rgba(0, 0, 0, 0.45), 0 20px 50px rgba(0, 0, 0, 0.45);
  --tray-radius: 18px;
  --tray-dot: rgba(255, 235, 210, 0.08);
  --rack-bg: linear-gradient(180deg, #2f1538, #22102a);
  --rack-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 14px 34px rgba(0, 0, 0, 0.5);
  --rack-border: 1.5px solid #c9a45c;
  --rack-radius: 18px;
  --rack-dot: rgba(255, 235, 210, 0.10);
  --tile-top: #fcf7ee;
  --tile-radius: 11% / 8%;
  --tile-border: 0;
  --tile-shadow: inset 0 -3px 0 rgba(120, 90, 50, 0.12), 0 2px 0 #c7b28e, 0 8px 16px rgba(0, 0, 0, 0.45);
  --ink0: #b3122f; --ink1: #c27300; --ink2: #0b7a51; --ink3: #1c45a6;
  --face0: #f3e8d6; --face1: #f3e8d6; --face2: #f3e8d6; --face3: #f3e8d6;
  --pip: none;
  --card-bg: rgba(255, 255, 255, 0.05);
  --card-border: 1px solid rgba(214, 178, 106, 0.25);
  --card-shadow: none;
  --card-radius: 14px;
  --chip-bg: rgba(255, 255, 255, 0.06);
  --btn-radius: 14px;
  --btn-gloss: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 50%);
  --btn-inset: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  --btn-border: 0;
  --btn-text: #2a1530;
  --go1: #ecd08e; --go2: #b98a3c; --go-shadow: rgba(201, 164, 92, 0.25);
  --sa1: #3a1d45; --sa2: #2c1435; --sa-shadow: rgba(0, 0, 0, 0.3); --sa-text: #f3e9dc;
  --sb1: #3a1d45; --sb2: #2c1435; --sb-shadow: rgba(0, 0, 0, 0.3); --sb-text: #f3e9dc;
  --un1: #b3263f; --un2: #861426; --un-shadow: rgba(0, 0, 0, 0.3);
  --wait1: #3a2a40; --wait2: #2d2033;
  --sheet-bg: #2a1630;
  --overlay-bg: rgba(20, 10, 25, 0.6);
  --soft-panel: rgba(255, 255, 255, 0.06);
  --fresh: #e3c27a;
  --bad: #ff5a76;
  --p0: #e3c27a; --p1: #ef7b9c; --p2: #f0a64a; --p3: #a493f2;
  --show-blob: none; --show-mono: flex;
  --jk-fill: #c9a45c; --jk-ink: #2a1530; --jk-shine: 0.4;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--page-bg);
  background-color: var(--page-color);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font-family: var(--font-ui); }

/* ---------- Layout: wide screens ---------- */
#game {
  height: 100vh;
  height: 100dvh;
  display: grid;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  grid-template-columns: minmax(0, 1fr) 150px;
  grid-template-rows: auto minmax(0, 1fr) 14px var(--rackH, 260px);
  grid-template-areas: "top top" "board side" "div side" "rack side";
  row-gap: 4px;
}
#top { grid-area: top; display: flex; align-items: center; gap: 14px; min-width: 0; }
#opps { flex: 1; display: flex; justify-content: center; gap: 10px; min-width: 0; }
#boardArea { grid-area: board; position: relative; min-height: 0; }
#side { grid-area: side; min-height: 0; display: flex; flex-direction: column; align-items: stretch; gap: 10px; justify-content: flex-end; }
#rackArea { grid-area: rack; height: auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }
#divider {
  grid-area: div;
  display: flex; align-items: center; justify-content: center;
  cursor: row-resize;
  touch-action: none;
}
#divider i {
  display: block; width: 72px; height: 5px; border-radius: 3px;
  background: var(--text-soft); opacity: 0.45;
  transition: opacity 0.15s, width 0.15s;
}
#divider:hover i, #divider.dragging i { opacity: 0.9; width: 96px; }

/* ---------- Logo ---------- */
.logo { font-weight: 700; font-size: 30px; letter-spacing: -0.5px; line-height: 1; display: flex; white-space: nowrap; }
[data-theme="gummy"] .logo span {
  display: inline-block;
  color: var(--c);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.9), 0 3px 6px rgba(120, 40, 80, 0.18);
}
.logo span:nth-child(4n+1) { --c: #ff4f7e; }
.logo span:nth-child(4n+2) { --c: #ff9f1c; }
.logo span:nth-child(4n+3) { --c: #2cc36b; }
.logo span:nth-child(4n+4) { --c: #4b7bff; }
[data-theme="gummy"] .logo span:nth-child(odd) { transform: translateY(-1px) rotate(-3deg); }
[data-theme="gummy"] .logo span:nth-child(even) { transform: translateY(1px) rotate(3deg); }
[data-theme="frosted"] .logo { font-weight: 600; letter-spacing: -0.03em; background: linear-gradient(90deg, #d3245b, #6b5bd6 60%, #3157d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
[data-theme="paper"] .logo { font-family: 'Fraunces', Georgia, serif; font-style: italic; font-weight: 700; letter-spacing: -0.02em; color: #2b2622; text-decoration: underline; text-decoration-color: #cf3f27; text-decoration-thickness: 3px; text-underline-offset: 6px; }
[data-theme="velvet"] .logo { font-family: 'Playfair Display', Georgia, serif; font-style: italic; font-weight: 700; letter-spacing: 0; background: linear-gradient(180deg, #f3dea6, #c9a45c); -webkit-background-clip: text; background-clip: text; color: transparent; }

.chip {
  background: var(--chip-bg);
  border: var(--card-border);
  border-radius: 99px;
  padding: 5px 12px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-soft);
  white-space: nowrap;
}
.chip b { color: var(--text); }
.iconbtn {
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  flex: none;
  border-radius: 12px;
  border: var(--card-border);
  font-size: 20px;
  color: var(--text);
  background: var(--card-bg);
  box-shadow: var(--card-shadow);
  cursor: pointer;
}

/* ---------- Player cards ---------- */
.pcard {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 11px 10px;
  border-radius: var(--card-radius);
  background: var(--card-bg);
  border: var(--card-border);
  box-shadow: var(--card-shadow);
  min-width: 0;
  transition: box-shadow 0.2s, border-color 0.2s;
}
#opps .pcard { flex: 0 1 230px; }
.pcard.active { border-color: var(--pc); box-shadow: 0 0 0 2px var(--pc), var(--card-shadow); }
.pface { position: relative; width: 30px; height: 30px; flex: none; }
.pface svg { display: var(--show-blob); width: 100%; height: 100%; }
.pface .mono {
  display: var(--show-mono);
  width: 100%; height: 100%;
  align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--pc);
  color: #fff;
  font-weight: 600; font-size: 14px;
}
[data-theme="paper"] .pface .mono { background: transparent; color: var(--pc); border: 1.5px solid var(--pc); font-family: 'Fraunces', serif; font-weight: 700; }
[data-theme="velvet"] .pface .mono { color: #2a1530; }
.pmid { min-width: 0; flex: 1; }
.pname { font-weight: 600; font-size: 15px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pstatus { font-size: 12.5px; color: var(--text-soft); font-weight: 500; min-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcount { display: flex; align-items: baseline; gap: 4px; flex: none; }
.pcount b { font-size: 32px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.pcount small { font-size: 12px; color: var(--text-soft); font-weight: 500; }
.pbar { position: absolute; left: 12px; right: 12px; bottom: 4px; height: 3px; border-radius: 3px; overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: var(--pc); border-radius: 3px; transition: width 0.25s linear; }
.pcard.hurry .pbar i { background: var(--bad); }
.thinking-dots span { display: inline-block; animation: dot 1.2s infinite; }
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-3px); } }

/* Your card sits first in the player strip; its second line is your countdown. */
.pclock {
  font-size: 17px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums;
  color: var(--pc); min-height: 15px;
}
.pcard.me.hurry .pclock { color: var(--bad); }
.pcard.me.active { background: color-mix(in srgb, var(--pc) 14%, var(--card-bg)); }
@keyframes pulse { to { transform: scale(1.12); } }

/* Your turn: the table lights up in your color. */
#boardScroll { transition: box-shadow 0.35s, border-color 0.35s; }
#boardScroll.myturn {
  border-color: var(--p0);
  background: linear-gradient(color-mix(in srgb, var(--p0) 7%, transparent), color-mix(in srgb, var(--p0) 7%, transparent)), var(--tray-bg);
  box-shadow: var(--tray-shadow), 0 0 0 4px var(--p0), 0 0 36px color-mix(in srgb, var(--p0) 60%, transparent);
}
#boardScroll.myturn.hurry {
  border-color: var(--bad);
  background: linear-gradient(color-mix(in srgb, var(--bad) 7%, transparent), color-mix(in srgb, var(--bad) 7%, transparent)), var(--tray-bg);
  box-shadow: var(--tray-shadow), 0 0 0 4px var(--bad), 0 0 36px color-mix(in srgb, var(--bad) 60%, transparent);
}
#boardScroll.myturn.flash { animation: turnflash 1.1s ease-out 1; }
@keyframes turnflash {
  0% { box-shadow: var(--tray-shadow), 0 0 0 12px color-mix(in srgb, var(--p0) 70%, transparent), 0 0 80px var(--p0); }
  100% { box-shadow: var(--tray-shadow), 0 0 0 4px var(--p0), 0 0 36px color-mix(in srgb, var(--p0) 60%, transparent); }
}

/* ---------- Board ---------- */
#boardScroll {
  position: absolute; inset: 0;
  overflow: auto;
  border-radius: var(--tray-radius);
  background: var(--tray-bg);
  border: var(--tray-border);
  box-shadow: var(--tray-shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  touch-action: pan-x pan-y;
}
#boardInner {
  position: relative;
  margin: 8px;
  background-image: radial-gradient(circle at 50% 44%, var(--tray-dot) 1.6px, transparent 2px);
  background-size: var(--bw, 40px) var(--bh, 52px);
}
#toast {
  position: absolute; left: 50%; top: 12px;
  transform: translate(-50%, -8px);
  background: var(--sheet-bg);
  color: var(--text);
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 99px;
  box-shadow: 0 8px 24px rgba(40, 20, 50, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90%;
  text-align: center;
  z-index: 5;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.warn { color: var(--bad); }
#meldMeter {
  position: absolute; left: 14px; bottom: 12px;
  font-weight: 600; font-size: 14px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--sheet-bg);
  color: var(--text-soft);
  pointer-events: none;
  display: none;
}
#meldMeter.on { display: block; }
#meldMeter.ok { color: var(--fresh); }

/* ---------- Tiles ---------- */
.tile {
  position: absolute; left: 0; top: 0;
  border-radius: var(--tile-radius);
  border: var(--tile-border);
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--tile-top) 0%, var(--face, #fff8ef) 100%);
  box-shadow: var(--tile-shadow);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.3s, height 0.3s, font-size 0.3s, box-shadow 0.15s;
  transform-origin: 0 0;
  will-change: transform;
  touch-action: none;
  cursor: grab;
  z-index: 1;
}
.tile .num {
  font-family: var(--font-num);
  font-weight: var(--num-weight);
  line-height: 1;
  color: var(--ink-t);
  margin-top: -10%;
  letter-spacing: var(--num-ls);
  font-variant-numeric: lining-nums;
}
[data-theme="gummy"] .tile .num { margin-top: -12%; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9); }
[data-theme="paper"] .tile .num, [data-theme="velvet"] .tile .num { margin-top: -4%; }
.tile .pip {
  display: var(--pip);
  position: absolute; left: 50%; bottom: 11%;
  width: 40%; height: 9%;
  transform: translateX(-50%);
  border-radius: 99px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--ink-t) 70%, white), var(--ink-t));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  opacity: 0.85;
}
.c0 { --ink-t: var(--ink0); --face: var(--face0); }
.c1 { --ink-t: var(--ink1); --face: var(--face1); }
.c2 { --ink-t: var(--ink2); --face: var(--face2); }
.c3 { --ink-t: var(--ink3); --face: var(--face3); }
.tile.joker { --face: var(--tile-top); }
.tile.joker svg { width: 70%; height: auto; margin-top: -4%; }
.jk-face { fill: var(--jk-fill); stroke: var(--jk-stroke, none); stroke-width: 2.2; }
.jk-shine { fill: #fff; opacity: var(--jk-shine); }
.jk-ink { fill: var(--jk-ink); }
.jk-smile { stroke: var(--jk-ink); stroke-width: 2.8; fill: none; stroke-linecap: round; }

.tile.fresh { box-shadow: 0 0 0 2.5px var(--fresh), 0 4px 12px rgba(0, 0, 0, 0.18); }
.tile.recent { box-shadow: 0 0 0 2.5px var(--pc), 0 4px 12px rgba(0, 0, 0, 0.18); }
.tile.soft-bad { box-shadow: 0 0 0 2px color-mix(in srgb, var(--bad) 55%, transparent), 0 3px 8px rgba(0, 0, 0, 0.14); }
.tile.bad { box-shadow: 0 0 0 3px var(--bad), 0 4px 14px rgba(0, 0, 0, 0.3); animation: shake 0.42s; }
.tile.drawn { box-shadow: 0 0 0 3px #ffd23f, 0 6px 16px rgba(255, 180, 0, 0.35); }
.tile.lift { box-shadow: 0 0 0 3px #ffd23f, 0 10px 22px rgba(0, 0, 0, 0.3); z-index: 3; }
.tile.locked { cursor: default; }
.tile.dragging { transition: none !important; z-index: 50; cursor: grabbing; box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35); }
.tile.slow { transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.3s, height 0.3s, font-size 0.3s, box-shadow 0.15s; }
.tile.back { background: linear-gradient(160deg, var(--p1), var(--p3)); }
@keyframes shake {
  0%, 100% { translate: 0 0; } 20% { translate: -4px 0; } 40% { translate: 4px 0; } 60% { translate: -3px 0; } 80% { translate: 3px 0; }
}
#dragLayer { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
#dragLayer .tile { position: fixed; }

/* ---------- Rack ---------- */
#rackArea {
  position: relative;
  padding: 10px;
  border-radius: var(--rack-radius);
  background: var(--rack-bg);
  border: var(--rack-border);
  box-shadow: var(--rack-shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
[data-theme="paper"] #rackArea::after {
  content: ''; position: absolute; inset: 5px;
  border: 1.5px dashed rgba(255, 250, 240, 0.45);
  border-radius: 4px;
  pointer-events: none;
}
#rackInner {
  position: relative;
  margin: 0 auto;
  background-image: radial-gradient(circle at 50% 46%, var(--rack-dot) 2px, transparent 2.5px);
  background-size: var(--rw, 50px) var(--rh, 66px);
}

/* ---------- Buttons ---------- */
.jelly {
  position: relative;
  border: var(--btn-border);
  border-radius: var(--btn-radius);
  color: var(--btn-text);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  background: var(--btn-gloss), linear-gradient(180deg, var(--j1), var(--j2));
  box-shadow: var(--btn-inset), 0 7px 16px var(--js);
  transition: transform 0.1s, filter 0.15s;
  padding: 10px;
}
[data-theme="gummy"] .jelly { text-shadow: 0 1px 1px rgba(0, 0, 0, 0.18); }
.jelly:active { transform: translateY(2px) scale(0.97); }
[data-theme="paper"] .jelly:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #2b2622; }
.jelly:disabled { filter: grayscale(0.6) opacity(0.6); cursor: default; }
.j-green { --j1: var(--go1); --j2: var(--go2); --js: var(--go-shadow); }
.j-blue { --j1: var(--sa1); --j2: var(--sa2); --js: var(--sa-shadow); color: var(--sa-text); }
.j-orange { --j1: var(--sb1); --j2: var(--sb2); --js: var(--sb-shadow); color: var(--sb-text); }
.j-red { --j1: var(--un1); --j2: var(--un2); --js: var(--un-shadow); color: #fff; }
[data-theme="velvet"] .j-blue, [data-theme="velvet"] .j-orange { border: 1px solid rgba(214, 178, 106, 0.45); }
[data-theme="velvet"] .j-red { color: #f3e9dc; }
[data-theme="paper"] .sheet .j-blue { --j1: #253f8c; --j2: #253f8c; color: #fffdf7; }
[data-theme="velvet"] .sheet .j-blue { --j1: #4a2657; --j2: #3a1d45; color: #f3e9dc; }
[data-theme="frosted"] .sheet .j-blue { --j1: #5a7be0; --j2: #3157d4; color: #fff; }

.sorts { display: flex; flex-direction: column; gap: 10px; }
.sorts .jelly { display: flex; justify-content: center; gap: 4px; padding: 10px 6px; }
.mini {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 31px;
  border-radius: 5px;
  background: linear-gradient(180deg, var(--tile-top), var(--face));
  color: var(--ink-t);
  font-family: var(--font-num);
  font-weight: var(--num-weight); font-size: 17px;
  text-shadow: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}
[data-theme="paper"] .mini { border: 1px solid #d8cdb9; }
#undoBtn { display: flex; align-items: center; justify-content: center; gap: 6px; }
#undoBtn[hidden] { display: none; }
#actBtn { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 104px; }
#actBtn .act-icon { font-size: 38px; line-height: 0.9; }
#actBtn .act-lbl { font-size: 18px; }
#actBtn .act-sub { font-size: 12px; opacity: 0.85; font-weight: 500; }
#actBtn.done .act-icon { font-size: 32px; }
#actBtn.waiting { --j1: var(--wait1); --j2: var(--wait2); --js: transparent; color: var(--text-soft); }

/* ---------- Overlay sheets ---------- */
#overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
#overlay[hidden] { display: none; }
.sheet {
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--sheet-bg);
  border: var(--card-border);
  border-radius: calc(var(--card-radius) + 8px);
  padding: 26px 24px;
  box-shadow: 0 24px 60px rgba(30, 20, 40, 0.25);
  text-align: center;
}
.sheet h1 { margin: 0 0 4px; }
.sheet h1 .logo { font-size: 52px; justify-content: center; }
.sheet h2 { margin: 6px 0 10px; font-size: 26px; }
.sheet p { color: var(--text-soft); margin: 8px 0; line-height: 1.4; }
.sheet .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.sheet .jelly { padding: 14px 26px; font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); max-width: 320px; margin-left: auto !important; margin-right: auto !important; gap: 8px; margin: 16px 0 6px; }
.stat { background: var(--soft-panel); border-radius: var(--card-radius); padding: 10px 4px; }
.stat b { display: block; font-size: 26px; color: var(--text); }
.stat span { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.lineup { display: flex; justify-content: center; gap: 22px; margin: 14px 0 4px; }
.lineup .who { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 600; font-size: 14px; }
.lineup .pface { width: 44px; height: 44px; }
.lineup .pface .mono { font-size: 18px; }
.settings { text-align: left; margin-top: 8px; }
.setting { margin: 14px 0; }
.setting > label { display: block; font-weight: 600; margin-bottom: 6px; }
.seg { display: flex; background: var(--soft-panel); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: 0; background: transparent;
  padding: 9px 4px; border-radius: 9px;
  font-size: 15px; font-weight: 600; color: var(--text-soft);
  cursor: pointer;
}
.seg button.on { background: var(--sheet-bg); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
.linkbtn { background: none; border: 0; color: var(--text-soft); font-weight: 600; font-size: 15px; text-decoration: underline; cursor: pointer; padding: 8px; }
.rules { text-align: left; font-size: 15px; color: var(--text-soft); line-height: 1.45; }
.rules li { margin: 6px 0; }
.final { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.final .fr { display: flex; justify-content: space-between; align-items: center; background: var(--soft-panel); border-radius: var(--card-radius); padding: 8px 14px; font-weight: 600; }
.final .fr.win { box-shadow: inset 0 0 0 2px var(--fresh); }

/* ---------- Narrow / upright screens (phones) ---------- */
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  #game {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) 14px auto var(--rackH, 200px);
    grid-template-areas: "top" "board" "div" "side" "rack";
    row-gap: 6px;
  }
  #top { flex-wrap: wrap; row-gap: 8px; gap: 10px; }
  .logo { font-size: 24px; }
  #modeBtn { margin-left: auto; }
  #opps { order: 10; flex-basis: 100%; gap: 6px; }
  #opps .pcard { flex: 1 1 0; padding: 6px 8px 9px; gap: 4px; }
  #opps .pface { display: none; }
  #opps .pname { font-size: 12.5px; }
  #opps .pclock { font-size: 14px; }
  #opps .pstatus { font-size: 11px; }
  #opps .pcount b { font-size: 23px; }
  #opps .pcount small { display: none; }
  .iconbtn { width: 36px; height: 36px; font-size: 17px; }
  #side { flex-direction: row; align-items: stretch; justify-content: space-between; gap: 8px; }
  #side { gap: 6px; }
  #undoBtn { flex: none; width: 44px; }
  .sorts { flex-direction: row; gap: 6px; }
  .sorts .jelly { padding: 7px 6px; gap: 2px; align-items: center; }
  .mini { width: 15px; height: 22px; font-size: 12px; border-radius: 4px; }
  #undoBtn { width: 50px; padding: 0; }
  #undoBtn .lbl { display: none; }
  #actBtn { min-height: 0; min-width: 0; flex: 1 1 auto; flex-direction: row; gap: 6px; padding: 0 6px; }
  .sorts .jelly { padding: 7px 5px; }
  #actBtn .act-icon { font-size: 22px; }
  #actBtn .act-lbl { font-size: 16px; }
  #actBtn { gap: 4px; }
  #actBtn .act-sub { display: none; }
  #rackArea { padding: 7px; }
  .chip { font-size: 12px; padding: 4px 9px; }
}
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  #game { grid-template-columns: minmax(0, 1fr) 118px; gap: 6px; }
  .logo { display: none; }
  #opps .pcard { padding: 4px 10px 7px; }
  #opps .pface { width: 22px; height: 22px; }
  .pcount b { font-size: 24px; }
  #actBtn { min-height: 64px; }
  .sorts { gap: 6px; }
  .sorts .jelly { padding: 6px 4px; }
  .mini { width: 18px; height: 24px; font-size: 14px; }
  #rackArea { padding: 6px; }
}
[data-theme]:not([data-theme="frosted"]) #modeBtn { display: none; }
/* Mid-width wide screens (an open Fold or a tablet held sideways): give names room in the top strip. */
@media (min-aspect-ratio: 1/1) and (max-width: 1320px) and (min-width: 761px) {
  #top > .logo, #record { display: none; }
  #opps { justify-content: flex-start; gap: 8px; }
  #opps .pcard { flex: 1 1 0; }
  #opps .pface, #opps .pcount small { display: none; }
}
/* Upright tablets (and an open Fold held upright): roomier controls than a phone. */
@media (max-aspect-ratio: 1/1) and (min-width: 600px) {
  .mini { width: 22px; height: 29px; font-size: 16px; }
  .sorts .jelly { padding: 9px 8px; gap: 3px; }
  #actBtn { flex: 0 1 220px; margin-left: auto; height: 56px; }
  #actBtn .act-lbl { font-size: 18px; }
  #opps .pname { font-size: 15px; }
  #opps .pcount b { font-size: 28px; }
  #opps .pclock { font-size: 17px; }
}
/* Your timer only: the bar pulses yellow from 20 seconds and red from 10. */
.pcard.me .pbar { height: 4px; bottom: 3px; }
.pcard.me.warn .pbar i { background: #f2b705; animation: barpulse 0.9s ease-in-out infinite; }
.pcard.me.warn .pclock { color: #f2b705; }
.pcard.me.hurry .pbar i { background: var(--bad); animation: barpulse 0.5s ease-in-out infinite; }
.pcard.me.warn .pbar, .pcard.me.hurry .pbar { height: 6px; bottom: 2px; overflow: visible; }
@keyframes barpulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px currentColor; }
  50% { opacity: 0.35; box-shadow: none; }
}
.pcard.me.warn .pbar i { color: #f2b705; }
.pcard.me.hurry .pbar i { color: var(--bad); }
.pcard.me.active.warn { border-color: #f2b705; box-shadow: 0 0 0 2px #f2b705, var(--card-shadow); }
.pcard.me.active.hurry { border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad), var(--card-shadow); }
/* The table's outline follows your timer: yellow from 20 seconds (red from 10 is above). */
#boardScroll.myturn.warn {
  border-color: #f2b705;
  background: linear-gradient(rgba(242, 183, 5, 0.07), rgba(242, 183, 5, 0.07)), var(--tray-bg);
  box-shadow: var(--tray-shadow), 0 0 0 4px #f2b705, 0 0 36px rgba(242, 183, 5, 0.6);
}
/* Wide screens: the side column has room, so the sort and Draw/Done buttons are about 50% bigger. */
@media (min-aspect-ratio: 1/1) and (min-width: 761px) and (min-height: 521px) {
  #game { grid-template-columns: minmax(0, 1fr) 164px; }
  .sorts { gap: 12px; }
  .sorts .jelly { padding: 16px 8px; gap: 6px; border-radius: calc(var(--btn-radius) + 4px); }
  .mini { width: 34px; height: 45px; font-size: 25px; border-radius: 7px; }
  #actBtn { min-height: 156px; border-radius: calc(var(--btn-radius) + 6px); }
  #actBtn .act-icon { font-size: 54px; }
  #actBtn.done .act-icon { font-size: 46px; }
  #actBtn .act-lbl { font-size: 24px; }
  #actBtn .act-sub { font-size: 15px; }
}
