/* WHOT | MyGameHub */
:root {
  --page: #071531;
  --panel: #0e2149;
  --panel-2: #132a59;
  --line: rgba(255, 255, 255, 0.13);
  --text: #eef3ff;
  --muted: #9fb2d9;
  --board: #0d2b5e;
  --board-deep: #081d44;
  --on-board: #eef3ff;
  --accent: #f5c518;
  --accent-ink: #1d1600;
  --accent-text: #f5c518;
  --card: #fffaf0;
  --card-edge: #e6dcc6;
  --ink: #8b1a2b;
  --back: #6e1322;
  --danger: #ff6b6b;
  --ok: #35d0a5;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --card-w: 74px;
  --head: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --page: #e4ebf7;
  --panel: #ffffff;
  --panel-2: #eef2fa;
  --line: rgba(11, 29, 63, 0.14);
  --text: #0b1d3f;
  --muted: #4f6283;
  --board: #13407f;
  --board-deep: #0d3066;
  --accent-text: #8a6500;
  --shadow: 0 10px 26px rgba(11, 29, 63, 0.18);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --page: #e4ebf7; --panel: #ffffff; --panel-2: #eef2fa; --line: rgba(11, 29, 63, 0.14);
    --text: #0b1d3f; --muted: #4f6283; --board: #13407f; --board-deep: #0d3066; --accent-text: #8a6500;
    --shadow: 0 10px 26px rgba(11, 29, 63, 0.18); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  background: var(--page);
  color: var(--text);
  font: 400 16px/1.5 var(--body);
  min-height: 100vh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--head); font-weight: 700; letter-spacing: 0.01em; line-height: 1.05; margin: 0 0 0.6rem; }
h2 { font-size: 1.5rem; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.mt { margin-top: 1.4rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 0.5rem 1rem; z-index: 99; }
.skip:focus { left: 0.5rem; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.7rem clamp(0.8rem, 3vw, 1.6rem); max-width: 1200px; margin: 0 auto;
}
.brand { font-family: var(--head); font-weight: 800; font-size: 1.7rem; color: var(--accent-text); text-decoration: none; letter-spacing: 0.02em; }
.brand small { font-family: var(--body); font-weight: 600; font-size: 0.8rem; color: var(--muted); letter-spacing: 0; margin-left: 0.35rem; }
.top-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.room-tag { font-family: var(--head); font-weight: 700; font-size: 1.1rem; letter-spacing: 0.12em; padding: 0.2rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 0.35rem 0.8rem; font-size: 0.88rem; font-weight: 600; cursor: pointer; position: relative;
}
.icon-btn:hover { border-color: var(--accent); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 0.72rem; padding: 0 0.4rem; margin-left: 0.2rem; }

main { max-width: 1200px; margin: 0 auto; padding: 0 clamp(0.8rem, 3vw, 1.6rem) 2rem; }

/* buttons and fields */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 0.7rem 1.1rem; font-weight: 600; cursor: pointer; min-height: 44px;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.warn { background: transparent; border: 2px solid var(--accent); color: var(--text); }
.btn.big { font-size: 1.1rem; padding: 0.9rem 1.6rem; width: 100%; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field > span { font-weight: 600; font-size: 0.92rem; color: var(--muted); }
.field.grow { flex: 1; margin-bottom: 0; }
input[type="text"], select {
  background: var(--page); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.65rem 0.8rem; min-height: 44px; width: 100%;
}
input[type="text"]:focus { border-color: var(--accent); outline: none; }
#inCode { font-family: var(--head); font-weight: 700; font-size: 1.3rem; letter-spacing: 0.25em; text-transform: uppercase; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.5rem); }
.msg { min-height: 1.4em; margin: 0.8rem 0 0; color: var(--accent); font-weight: 600; }

/* swatches and segmented controls */
.swatches { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; background: var(--c); }
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--page) inset; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; background: transparent; border: 0; padding: 0.6rem 0.4rem; cursor: pointer; font-weight: 600; min-height: 44px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

/* home */
.home-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: clamp(1rem, 4vw, 3rem); align-items: center; padding: 1rem 0 1.5rem; }
.hero { text-align: left; }
.hero-title {
  font-family: var(--head); font-weight: 800; font-size: clamp(5rem, 16vw, 11rem);
  line-height: 0.82; margin: 0.5rem 0 0.8rem; color: var(--accent-text); letter-spacing: 0.01em;
}
.hero-sub { font-size: 1.15rem; max-width: 30ch; color: var(--muted); margin: 0; }
.hero-fan { position: relative; height: 170px; width: 280px; }
.hero-fan .card { position: absolute; bottom: 0; left: 60px; --card-w: 104px; transform-origin: 50% 120%; box-shadow: var(--shadow); }
.hero-fan .card:nth-child(1) { transform: rotate(-16deg) translateX(-40px); }
.hero-fan .card:nth-child(2) { transform: rotate(-2deg); }
.hero-fan .card:nth-child(3) { transform: rotate(13deg) translateX(44px); }
@media (prefers-reduced-motion: no-preference) {
  .hero-fan .card { animation: deal 0.6s cubic-bezier(.2,.8,.2,1) both; }
  .hero-fan .card:nth-child(2) { animation-delay: 0.08s; }
  .hero-fan .card:nth-child(3) { animation-delay: 0.16s; }
}
@keyframes deal { from { opacity: 0; translate: 0 40px; } to { opacity: 1; translate: 0 0; } }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0.4rem 0 1.2rem; }
.join-row { display: flex; gap: 0.6rem; align-items: flex-end; }
.solo-setup { border-top: 1px solid var(--line); margin-top: 1.2rem; padding-top: 1.2rem; }
.rules { margin-top: 0.5rem; }
.rules summary { cursor: pointer; font-family: var(--head); font-weight: 700; font-size: 1.35rem; }
.rules-body { max-width: 70ch; }
.specials { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.6rem 1.2rem; margin: 1rem 0; }
.specials div { border-left: 3px solid var(--accent); padding-left: 0.7rem; }
.specials dt { font-family: var(--head); font-weight: 700; font-size: 1.15rem; }
.specials dd { margin: 0; color: var(--muted); }

/* lobby */
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding-top: 0.5rem; }
.code-big { font-family: var(--head); font-weight: 800; font-size: clamp(3rem, 12vw, 5rem); letter-spacing: 0.18em; line-height: 1; margin: 0 0 1rem; color: var(--accent-text); }
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.plist li { display: flex; align-items: center; gap: 0.7rem; background: var(--panel-2); border-radius: 12px; padding: 0.55rem 0.7rem; }
.dot { width: 30px; height: 30px; border-radius: 50%; background: var(--pc); display: grid; place-items: center; color: #10131a; font-weight: 700; font-size: 0.9rem; flex: none; }
.pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.75rem; font-weight: 700; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.host { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tag.off { color: var(--danger); border-color: var(--danger); }
.settings .srow { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.settings .srow:last-child { border-bottom: 0; }
.settings .srow > span { font-weight: 600; }
.settings select { width: auto; min-width: 10rem; }
.settings .sval { color: var(--muted); font-weight: 600; }
.toggle { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.bot-add { display: flex; gap: 0.5rem; }
.start-box { margin-top: 1.2rem; }
.start-box p { margin: 0.5rem 0 0; text-align: center; }

/* cards */
.card { width: var(--card-w); aspect-ratio: 100 / 140; display: block; border-radius: calc(var(--card-w) * 0.1); flex: none; }
.card svg { width: 100%; height: 100%; display: block; }
.cf { fill: var(--card); stroke: var(--card-edge); stroke-width: 2; }
.cs { fill: var(--ink); }
.cn { fill: var(--ink); font-family: var(--head); font-weight: 800; font-size: 24px; }
.cw { fill: var(--ink); font-family: var(--head); font-weight: 800; font-size: 34px; letter-spacing: 1px; }
.cb { fill: var(--back); stroke: #4a0c17; stroke-width: 2; }
.cb-frame { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.cb-word { fill: var(--accent); font-family: var(--head); font-weight: 800; font-size: 30px; letter-spacing: 1px; }

/* game */
.opponents { display: flex; gap: 0.6rem; overflow-x: auto; padding: 0.3rem 0.1rem 0.7rem; scrollbar-width: thin; }
.opp {
  position: relative; flex: 0 0 auto; min-width: 128px; background: var(--panel); border: 2px solid var(--line);
  border-radius: 14px; padding: 0.55rem 0.7rem; display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.55rem; align-items: center;
}
.opp.turn { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245, 197, 24, 0.25); }
.opp .dot { grid-row: span 2; }
.opp .oname { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9rem; }
.opp .ometa { font-size: 0.8rem; color: var(--muted); display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.minibacks { display: flex; grid-column: 1 / -1; margin-top: 0.35rem; min-height: 22px; }
.miniback { width: 15px; height: 21px; border-radius: 3px; background: var(--back); border: 1.5px solid var(--accent); margin-right: -7px; }
.opp .count { font-family: var(--head); font-weight: 800; font-size: 1.15rem; color: var(--text); }
.flag { font-size: 0.72rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.flag.off { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.catch-btn { grid-column: 1 / -1; margin-top: 0.4rem; background: var(--danger); color: #1b0000; border: 0; border-radius: 10px; font-weight: 800; padding: 0.4rem; cursor: pointer; font-family: var(--head); font-size: 1.1rem; }
@media (prefers-reduced-motion: no-preference) { .catch-btn { animation: pulse 0.9s ease-in-out infinite; } }

.board {
  background: radial-gradient(ellipse at 50% 35%, var(--board) 0%, var(--board-deep) 100%);
  color: var(--on-board); border-radius: 22px; padding: clamp(1rem, 4vw, 2rem);
  box-shadow: inset 0 2px 30px rgba(0, 0, 0, 0.45); position: relative;
}
.table { display: flex; justify-content: center; align-items: center; gap: clamp(1.5rem, 8vw, 5rem); --card-w: clamp(92px, 20vw, 128px); }
.pile { position: relative; display: grid; place-items: center; background: none; border: 0; padding: 0; }
.market { cursor: pointer; }
.market:disabled { cursor: default; }
.market .pile-cards { position: relative; }
.market .pile-cards::before, .market .pile-cards::after {
  content: ""; position: absolute; inset: 0; border-radius: calc(var(--card-w) * 0.1); background: var(--back); border: 2px solid #4a0c17; z-index: -1;
}
.market .pile-cards::before { transform: translate(4px, 4px); }
.market .pile-cards::after { transform: translate(8px, 8px); }
.market.can .card { box-shadow: 0 0 0 3px var(--accent); }
.pile-count { position: absolute; bottom: -1.9rem; font-weight: 700; font-size: 0.9rem; color: var(--on-board); opacity: 0.85; white-space: nowrap; }
.discard .card { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4); }
.ask-chip {
  position: absolute; bottom: -2.2rem; white-space: nowrap; background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; padding: 0.2rem 0.75rem; font-weight: 700; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 0.35rem;
}
.ask-chip svg { width: 16px; height: 16px; }
.ask-chip path { fill: var(--accent-ink); }
.feed { text-align: center; margin: 2.8rem 0 0; min-height: 1.5em; font-weight: 600; color: var(--on-board); }
@media (prefers-reduced-motion: no-preference) { .discard .card.fresh { animation: land 0.28s ease-out; } }
@keyframes land { from { transform: translateY(-26px) scale(1.06) rotate(-4deg); opacity: 0.4; } to { transform: none; opacity: 1; } }

.me-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: 1rem 0 0.2rem; flex-wrap: wrap; }
.status-wrap { flex: 1; min-width: 200px; }
.status { font-family: var(--head); font-weight: 700; font-size: 1.6rem; margin: 0; line-height: 1.1; }
.status.mine { color: var(--accent-text); }
.timer { position: relative; height: 8px; margin-right: 3rem; background: var(--panel-2); border-radius: 999px; margin-top: 0.5rem; max-width: 360px; }
.timer-fill { position: absolute; inset: 0 auto 0 0; width: 100%; background: var(--accent); border-radius: 999px; }
.timer.low .timer-fill { background: var(--danger); }
.timer span { position: absolute; left: calc(100% + 0.5rem); top: -0.55rem; font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.me-actions { display: flex; gap: 0.5rem; }
#btnLast.hot { background: var(--accent); color: var(--accent-ink); }
@media (prefers-reduced-motion: no-preference) { #btnLast.hot { animation: pulse 0.9s ease-in-out infinite; } }
@keyframes pulse { 50% { transform: scale(1.05); } }

.hand {
  display: flex; justify-content: flex-start; padding: 1.6rem 0.5rem 1rem; overflow-x: auto; overflow-y: visible;
  --card-w: clamp(70px, 17vw, 100px); min-height: calc(var(--card-w) * 1.4 + 2.6rem);
}
.hand .hcard {
  background: none; border: 0; padding: 0; cursor: pointer; margin-left: calc(var(--card-w) * var(--overlap, -0.3));
  transition: transform 0.14s ease, filter 0.14s ease; border-radius: calc(var(--card-w) * 0.1);
}
.hand .hcard:first-child { margin-left: 0; }
/* spacers centre a short hand but collapse when it overflows, so the first cards stay reachable */
.hand::before, .hand::after { content: ""; flex: 1 0 0.5rem; }
.hand .hcard .card { box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3); }
.hand.myturn .hcard.legal { transform: translateY(-14px); }
.hand.myturn .hcard.legal .card { box-shadow: 0 0 0 3px var(--accent), 0 10px 18px rgba(0, 0, 0, 0.35); }
.hand.myturn .hcard:not(.legal) { filter: brightness(0.72) saturate(0.7); cursor: not-allowed; }
@media (hover: hover) and (pointer: fine) {
  .hand.myturn .hcard.legal:hover { transform: translateY(-22px); }
}
.hand .hcard.shake { animation: shake 0.3s; }
@keyframes shake { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
.hand-empty { color: var(--muted); align-self: center; }
.quick-react { display: flex; justify-content: center; gap: 0.3rem; flex-wrap: wrap; }
.quick-react button, .chat-react button { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: 1.3rem; width: 44px; height: 44px; cursor: pointer; }
.quick-react button:hover, .chat-react button:hover { border-color: var(--accent); }

/* chat */
.chat-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100vw); background: var(--panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 30; box-shadow: var(--shadow);
  padding: calc(0.8rem + env(safe-area-inset-top, 0px)) 0.9rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
}
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-log { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-log li { line-height: 1.35; overflow-wrap: anywhere; }
.chat-log b { color: var(--pc); }
.chat-log .sys { color: var(--muted); font-size: 0.88rem; }
.chat-react { display: flex; gap: 0.3rem; flex-wrap: wrap; margin: 0.6rem 0; }
.chat-input { display: flex; gap: 0.5rem; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(3, 10, 26, 0.72); display: grid; place-items: center; z-index: 40; padding: 1rem; }
.overlay-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: clamp(1.1rem, 4vw, 1.8rem); width: min(640px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.overlay-card.small { width: min(420px, 100%); }
.overlay-card h2 { font-size: clamp(1.9rem, 6vw, 2.6rem); color: var(--accent-text); }
.res-table { display: grid; gap: 0.5rem; margin: 1rem 0; }
.res-row { display: grid; grid-template-columns: auto 1fr auto; gap: 0.3rem 0.7rem; align-items: center; background: var(--panel-2); border-radius: 12px; padding: 0.6rem 0.75rem; }
.res-row.win { outline: 2px solid var(--accent); }
.res-row .rtotal { font-family: var(--head); font-weight: 800; font-size: 1.35rem; text-align: right; }
.res-row .rsub { grid-column: 2 / -1; font-size: 0.85rem; color: var(--muted); }
.res-cards { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; --card-w: 34px; }
.verify { font-size: 0.92rem; padding: 0.6rem 0.8rem; border-radius: 10px; background: var(--panel-2); }
.verify.good { border-left: 4px solid var(--ok); }
.verify.bad { border-left: 4px solid var(--danger); }
.shape-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 0.6rem; margin: 1rem 0; }
.shape-buttons button { background: var(--card); color: var(--ink); border: 2px solid var(--card-edge); border-radius: 12px; padding: 0.7rem 0.4rem; cursor: pointer; display: grid; justify-items: center; gap: 0.3rem; font-weight: 700; min-height: 44px; }
.shape-buttons button:hover { border-color: var(--accent); }
.shape-buttons svg { width: 40px; height: 40px; }
.shape-buttons path { fill: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 0.7rem 1.2rem; border-radius: 12px;
  z-index: 50; max-width: min(92vw, 520px); text-align: center; box-shadow: var(--shadow);
}
.react-layer { position: fixed; inset: 0; pointer-events: none; z-index: 45; }
.floater { position: absolute; font-size: 2.2rem; }
@media (prefers-reduced-motion: no-preference) { .floater { animation: floatup 1.8s ease-out forwards; } }
@keyframes floatup { from { opacity: 1; transform: translateY(0) scale(0.8); } 20% { transform: translateY(-10px) scale(1.25); } to { opacity: 0; transform: translateY(-110px) scale(1); } }

@media (max-width: 820px) {
  .home-grid, .lobby-grid { grid-template-columns: 1fr; }
  .hero { text-align: center; }
  .hero-fan { margin: 0 auto; }
  .hero-sub { margin: 0 auto; }
  .status { font-size: 1.3rem; }
  .brand small { display: none; }
}
@media (max-width: 420px) {
  .icon-btn { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
  .home-actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
