:root {
  --navy-950: #08112a;
  --navy-900: #0b1633;
  --navy-800: #12224a;
  --navy-700: #1b2f63;
  --navy-600: #284081;
  --yellow: #ffcc00;
  --yellow-ink: #3a2c00;
  --red: #ee2b2b;
  --blue: #1e6fe0;
  --green: #22b14c;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 12px;
  --card-w: 76px;
}

[data-theme='dark'] {
  --bg: var(--navy-900);
  --surface: var(--navy-800);
  --surface-2: var(--navy-700);
  --text: #eef2ff;
  --muted: #9fb0d8;
  --border: #2a3d74;
  --felt: var(--navy-800);
  --felt-line: #22376e;
}

[data-theme='light'] {
  --bg: #eef2fb;
  --surface: #ffffff;
  --surface-2: #e4eaf7;
  --text: #0f1b3d;
  --muted: #4b5b85;
  --border: #d0d9ee;
  --felt: var(--navy-800);
  --felt-line: #22376e;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: 0.01em; margin: 0 0 8px; line-height: 1.1; }
h2 { font-size: 22px; }

button, select, input { font: inherit; color: inherit; }
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
}
button:hover:not(:disabled) { border-color: var(--yellow); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, select:focus-visible, input:focus-visible, .card:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
button.primary { background: var(--yellow); color: var(--yellow-ink); border-color: var(--yellow); }
button.ghost { background: transparent; }
button.icon { min-width: 40px; min-height: 40px; padding: 6px; border-radius: 50%; background: transparent; }
button.icon[aria-pressed='true'] { background: var(--yellow); color: var(--yellow-ink); }
input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}

.topbar {
  position: relative; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  max-width: 1180px; margin: 0 auto;
}
.brandwrap { display: flex; align-items: baseline; gap: 10px; }
.brand { font-family: var(--display); font-size: 30px; font-weight: 700; color: var(--yellow); text-transform: uppercase; letter-spacing: 0.02em; line-height: 1; }
[data-theme='light'] .brand { color: var(--navy-800); }
.hublink { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; }
.hublink:hover { color: var(--text); text-decoration: underline; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
button.pill { min-height: 36px; padding: 6px 14px; border-radius: 999px; background: transparent; font-size: 14px; }
button.pill[aria-pressed='true'] { border-color: var(--yellow); }
.pill .sm { display: none; }

main { max-width: 1180px; margin: 0 auto; padding: 16px 14px 24px; }
.screen { display: flex; flex-direction: column; gap: 16px; }

.homegrid { display: grid; gap: 16px; }
.homeside { display: flex; flex-direction: column; gap: 16px; }
.hero { text-align: center; padding: 8px 0 4px; }
.hero h1 { font-size: 72px; color: var(--yellow); margin: 4px 0 0; text-transform: uppercase; line-height: 0.95; }
[data-theme='light'] .hero h1 { color: var(--navy-800); }
.hero .lede { color: var(--muted); max-width: 36ch; margin: 8px auto 0; font-size: 17px; }
.hero-cards { display: flex; justify-content: center; height: 128px; margin-top: 8px; }
.hero-cards .cardsvg { width: 76px; height: auto; margin: 0 -14px; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35)); }
.hero-cards .cardsvg:nth-child(1) { transform: rotate(-14deg) translateY(10px); }
.hero-cards .cardsvg:nth-child(2) { transform: rotate(-4deg); z-index: 1; }
.hero-cards .cardsvg:nth-child(3) { transform: rotate(8deg) translateY(4px); z-index: 2; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.swatch { width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15); }
.swatch[aria-checked='true'] { border-color: var(--text); outline: 2px solid var(--bg); outline-offset: -5px; }
.pdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; flex: 0 0 auto; }

.howto summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::before { content: '\25B8'; color: var(--yellow); font-size: 20px; transition: transform 0.15s; }
.howto[open] summary::before { transform: rotate(90deg); }
.howto summary h2 { margin: 0; }
.helpgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin: 6px 0 14px; }
.helpitem { display: flex; gap: 12px; align-items: flex-start; border-left: 3px solid var(--yellow); padding-left: 12px; }
.helpitem h3 { font-size: 20px; margin: 0 0 2px; }
.helpitem p { margin: 0; color: var(--muted); font-size: 15px; }
.helpcard { flex: 0 0 54px; }
.helpcard .cardsvg { width: 54px; height: auto; display: block; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.3)); }

@media (min-width: 900px) {
  .homegrid { grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: start; }
  .hero { text-align: left; padding-top: 24px; }
  .hero h1 { font-size: 150px; }
  .hero .lede { margin-left: 0; }
  .hero-cards { justify-content: flex-start; height: 190px; padding-left: 20px; }
  .hero-cards .cardsvg { width: 118px; margin: 0 -22px; }
}

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.field input, .field select { color: var(--text); font-size: 16px; }
.field.compact { flex: 1 1 120px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; flex: 1 1 200px; min-height: 44px; }
.check input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--yellow); }
.joinrow { display: flex; gap: 8px; }
.joinrow input { text-transform: uppercase; letter-spacing: 0.2em; font-family: var(--display); font-size: 20px; }
.msg { min-height: 1.5em; color: var(--yellow); margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.codebox { text-align: center; background: var(--felt); color: #eef2ff; border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.codebox .label { font-size: 13px; color: #9fb0d8; }
.codebox .code { font-family: var(--display); font-size: 56px; letter-spacing: 0.18em; color: var(--yellow); line-height: 1; }
.codebox button { background: var(--navy-700); color: #eef2ff; border-color: var(--navy-600); }

.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plist li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.plist .pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--navy-600); color: #eef2ff; font-weight: 600; }
.tag.host { background: var(--yellow); color: var(--yellow-ink); }
.tag.off { background: #7a2b2b; }
.tag.away { background: #6b5a14; }
.plist button { min-height: 32px; padding: 4px 10px; font-size: 13px; }

/* Game */
.opponents { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.opp {
  flex: 0 0 auto; min-width: 104px; max-width: 150px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 12px;
  padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; position: relative;
}
.opp.turn { border-color: var(--yellow); box-shadow: 0 0 0 2px rgba(255, 204, 0, 0.25); }
.opp.me { background: var(--surface-2); }
.opp .oname { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp .ometa { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.opp .ocount { font-family: var(--display); font-size: 22px; color: var(--text); line-height: 1; }
.opp .ozap { position: absolute; top: -8px; right: -6px; background: var(--yellow); color: var(--yellow-ink); font-family: var(--display); font-weight: 700; font-size: 14px; border-radius: 999px; padding: 0 8px; }
.opp .obubble { position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); font-size: 26px; animation: pop 1.6s ease forwards; pointer-events: none; }

.table {
  position: relative; background: var(--felt); color: #eef2ff;
  border-radius: 18px; padding: 18px 14px 12px; overflow: hidden;
  background-image: repeating-linear-gradient(115deg, transparent 0 22px, var(--felt-line) 22px 23px);
}
.piles { display: flex; align-items: center; justify-content: center; gap: 22px; }
.pile { width: 92px; aspect-ratio: 110 / 165; padding: 0; border: none; background: none; position: relative; min-height: 0; border-radius: 10px; }
.pile .cardsvg { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.4)); }
button.pile:disabled { opacity: 1; cursor: default; }
#drawPile.ready { animation: nudge 1.4s ease-in-out infinite; }
.pile .count { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); background: var(--navy-950); color: #9fb0d8; font-size: 12px; padding: 1px 8px; border-radius: 999px; z-index: 1; }
.discard .cardsvg { animation: land 0.25s ease-out; }
.state { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.colorpill { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; font-size: 18px; color: #fff; }
.dirpill { font-size: 22px; color: var(--yellow); width: 44px; text-align: center; }
.status { text-align: center; margin: 14px 0 8px; font-weight: 600; min-height: 1.5em; }
.status.mine { color: var(--yellow); }
.timer { height: 6px; background: var(--navy-950); border-radius: 999px; overflow: hidden; }
.timerbar { height: 100%; width: 0; background: var(--yellow); transition: width 0.25s linear; }
.timerbar.low { background: var(--red); }
.flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle at 50% 40%, rgba(255,204,0,0.55), transparent 60%); }
.flash.on { animation: flash 0.9s ease-out; }
.reactions-layer { position: absolute; inset: 0; pointer-events: none; }
.reactions-layer span { position: absolute; bottom: 10px; font-size: 32px; animation: float 2s ease-out forwards; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.actions .zap { font-family: var(--display); font-size: 22px; background: var(--yellow); color: var(--yellow-ink); border-color: var(--yellow); padding: 6px 22px; }
.actions .zap:disabled { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.actions .zap.urge { animation: pulse 0.8s ease-in-out infinite; }
.catches { display: contents; }
.catches button { background: var(--red); color: #fff; border-color: var(--red); }

.hand {
  display: flex; gap: 0; overflow-x: auto; overflow-y: visible;
  padding: 18px 12px 10px; min-height: 150px; scroll-snap-type: x proximity;
  justify-content: safe center;
}
.card {
  flex: 0 0 auto; width: var(--card-w); padding: 0; border: none; background: none; min-height: 0;
  margin-left: var(--overlap, -18px); border-radius: 10px; transition: transform 0.12s ease; scroll-snap-align: center;
}
.card:first-child { margin-left: 0; }
.card { position: relative; }
.card:focus-visible { z-index: 5; }
.card .cardsvg { width: 100%; height: auto; display: block; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.35)); }
.card.playable { transform: translateY(-12px); }
.card.playable:hover { transform: translateY(-18px); }
.card.dim { filter: saturate(0.55) brightness(0.8); }
.card.drawn { transform: translateY(-16px); outline: 3px solid var(--yellow); outline-offset: 1px; }
.card:disabled { opacity: 1; cursor: default; }

.bottombar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.emojis { display: flex; gap: 4px; flex: 1 1 auto; }
.emojis button { min-width: 40px; min-height: 40px; padding: 4px; font-size: 20px; background: transparent; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 6px; margin-left: 4px; }
.log { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; max-height: 84px; overflow: hidden; }

.chat {
  position: fixed; right: 0; bottom: 0; top: 0; width: min(360px, 100%); z-index: 30;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
}
.chathead { display: flex; align-items: center; justify-content: space-between; }
.chatlist { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.chatlist li { font-size: 14px; }
.chatlist li b { color: var(--yellow); }
[data-theme='light'] .chatlist li b { color: #8a6a00; }
.chatlist li.sys { color: var(--muted); font-style: italic; }
.chatform { display: flex; gap: 8px; margin-top: 8px; }

.dlg {
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(420px, calc(100% - 24px));
}
.dlg.wide { width: min(560px, calc(100% - 24px)); }
.dlg::backdrop { background: rgba(4, 9, 24, 0.65); }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.colors button { min-height: 72px; color: #fff; font-family: var(--display); font-size: 22px; border: 3px solid transparent; }
.colors button:hover { border-color: #fff; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.minihand { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.minihand .cardsvg { width: 48px; height: auto; }
.scores { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
.scores th, .scores td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); font-size: 15px; }
.scores td:last-child, .scores th:last-child { text-align: right; font-family: var(--display); font-size: 18px; }
.rules p { margin: 0 0 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); transform: translateX(-50%);
  background: var(--navy-950); color: #eef2ff; border: 1px solid var(--yellow);
  padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: calc(100% - 24px); text-align: center;
}
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px 0 18px; }

@keyframes land { from { transform: translateY(-24px) rotate(-8deg); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes nudge { 50% { transform: translateY(-4px); } }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
@keyframes float { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-140px); opacity: 0; } }
@keyframes pop { 0% { transform: translate(-50%, 0) scale(0.4); opacity: 0; } 20% { transform: translate(-50%, -10px) scale(1.1); opacity: 1; } 100% { transform: translate(-50%, -26px) scale(1); opacity: 0; } }

@media (max-width: 480px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .tools { gap: 4px; }
  button.pill { min-height: 32px; padding: 4px 10px; font-size: 13px; }
  .brand { font-size: 26px; }
  .pill .lg { display: none; }
  .pill .sm { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 640px) {
  :root { --card-w: 92px; }
  .pile { width: 110px; }
}
@media (min-width: 1100px) {
  body.chat-open main { margin-right: 360px; }
}
