:root {
  color-scheme: light;
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #efedf8;
  --text: #1b1a24;
  --muted: #5f5d70;
  --border: #dedbea;
  --accent: #5b4bdb;
  --accent-text: #ffffff;
  --accent-soft: #e9e6fb;
  --danger: #c0392b;
  --good: #1e8e5a;
  --shadow: 0 1px 2px rgb(20 16 60 / 6%), 0 4px 16px rgb(20 16 60 / 6%);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Noto Sans JP",
    "Noto Sans SC", "Noto Sans Thai", "Noto Sans Devanagari", "Noto Sans Arabic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121119;
    --surface: #1c1b26;
    --surface-2: #262433;
    --text: #f1f0f7;
    --muted: #a9a6bb;
    --border: #34313f;
    --accent: #8b7ff0;
    --accent-text: #120f2a;
    --accent-soft: #2c2850;
    --danger: #ff7a6b;
    --good: #5fd39a;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html.in-room #view-home,
html.in-room #about,
html.in-room .foot {
  display: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- header / footer ---- */

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px;
}

.brand {
  font-weight: 800;
  font-size: 19px;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.lang {
  margin-inline-start: auto;
  flex-shrink: 0;
}

.lang select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  max-width: 132px;
}

.foot {
  max-width: 560px;
  margin: 8px auto 0;
  padding: 24px 16px 48px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}

.foot > a {
  color: var(--accent);
  font-weight: 600;
}

.lang-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 14px;
  font-size: 13px;
}

.lang-links a {
  color: var(--muted);
}

.lang-links [aria-current] {
  color: var(--text);
  font-weight: 600;
}

/* ---- layout ---- */

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 16px 32px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1,
.title {
  font-size: clamp(26px, 7vw, 34px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 12px 0 0;
  text-wrap: balance;
}

h2 {
  font-size: 17px;
  margin: 0;
}

.lead {
  color: var(--muted);
  margin: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  gap: 8px;
}

.row input {
  flex: 1;
  min-width: 0;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---- form controls ---- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}

.field.inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 48px;
}

select {
  min-height: 40px;
  padding: 8px 12px;
}

input:focus-visible,
select:focus-visible,
.btn:focus-visible,
.emote:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
}

#code-input::placeholder {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-weight: 600;
}

.btn.big {
  min-height: 56px;
  font-size: 18px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.center {
  text-align: center;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

/* ---- lobby ---- */

.code-title {
  margin: 2px 0 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.14em;
  font-variant-numeric: tabular-nums;
}

.lobby-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.count {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.player {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-top: 1px solid var(--border);
}

.player:first-child {
  border-top: 0;
}

.player.offline .avatar,
.player.offline .name {
  opacity: 0.45;
}

.avatar {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.host {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.me {
  background: transparent;
  border: 1px solid var(--border);
}

.icon-btn {
  margin-inline-start: auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.bubble {
  position: absolute;
  inset-inline-end: 48px;
  top: 4px;
  font-size: 26px;
  animation: pop 1.8s ease-out forwards;
  pointer-events: none;
}

@keyframes pop {
  0% {
    transform: translateY(6px) scale(0.6);
    opacity: 0;
  }
  15% {
    transform: translateY(0) scale(1.1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translateY(-14px) scale(1);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bubble {
    animation: none;
  }
}

.emotes {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.emote {
  flex: 1;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 22px;
  cursor: pointer;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- about (crawlable copy) ---- */

.about {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 40px;
}

.about section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.steps,
.features {
  margin: 0;
  padding-inline-start: 22px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.faq details {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.faq details:last-child {
  border-bottom: 1px solid var(--border);
}

.faq summary {
  font-weight: 600;
  cursor: pointer;
}

.faq p {
  margin: 8px 0 0;
  color: var(--muted);
}

/* ---- ads, banner, toast ---- */

.ad-slot:empty {
  display: none;
}

.ad-slot {
  min-height: 100px;
  margin-top: 8px;
}

.banner {
  position: fixed;
  inset-inline: 0;
  top: 0;
  padding: 10px 16px;
  background: var(--danger);
  color: #fff;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  z-index: 10;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 11;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===================== match ===================== */

.match {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mhead {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mhead-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.mhead-text strong {
  font-size: 20px;
  line-height: 1.2;
}

.mtimer {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
}

.mtimer-bar {
  position: absolute;
  inset: 0;
  background: var(--accent-soft);
  transform-origin: left center;
  transition: transform 0.2s linear;
}

[dir="rtl"] .mtimer-bar {
  transform-origin: right center;
}

.mtimer-num {
  position: relative;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.mtimer.urgent .mtimer-bar {
  background: color-mix(in srgb, var(--danger) 30%, transparent);
}

.mtimer.urgent .mtimer-num {
  color: var(--danger);
}

.pstrip {
  list-style: none;
  margin: 0;
  padding: 0 0 4px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.pchip {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
  max-width: 96px;
  padding: 6px 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
}

.pchip .pname {
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pchip .pcount {
  font-size: 11px;
  letter-spacing: -1px;
}

.pchip.me {
  border-color: var(--accent);
}

.pchip.finalist {
  background: var(--accent-soft);
}

.pchip.out {
  opacity: 0.45;
}

.pchip .bubble {
  inset-inline-end: -4px;
  top: -14px;
}

.mbody {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mbody h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.rules {
  text-align: center;
}

.rules p {
  margin: 0 0 8px;
}

.rules-icon {
  font-size: 44px;
  line-height: 1;
}

.spectating,
.note {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
}

.big-note {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.good {
  color: var(--good);
}

/* cards in hand */
.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.pcard {
  width: 56px;
  height: 76px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 26px;
  font-weight: 800;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 4px 0 var(--accent-soft);
  transition: transform 0.12s;
}

.pcard:active {
  transform: translateY(3px);
  box-shadow: none;
}

.pcard.mini {
  width: 34px;
  height: 44px;
  font-size: 18px;
  border-width: 1.5px;
  box-shadow: none;
  cursor: default;
}

.pcard.mini.win {
  background: var(--accent);
  color: var(--accent-text);
}

.pcard.mini.back {
  background: var(--surface-2);
  border-style: dashed;
  color: var(--muted);
}

.bids,
.scores,
.results,
.standings,
.others,
.give-list,
.guesses {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.bids li,
.scores li,
.results li,
.standings li,
.others li,
.give-list li,
.guesses li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-top: 1px solid var(--border);
}

.bids li:first-child,
.scores li:first-child,
.results li:first-child,
.standings li:first-child,
.others li:first-child,
.give-list li:first-child,
.guesses li:first-child {
  border-top: 0;
}

.bids li > span:first-child,
.scores li > span,
.results .nm,
.give-list li > span:first-child,
.others li > span:first-child {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bids .won .pts {
  color: var(--good);
  font-weight: 800;
}

.bids .dup .pcard {
  text-decoration: line-through;
  opacity: 0.6;
}

.bids .pts {
  min-width: 44px;
  text-align: end;
  font-size: 13px;
  color: var(--muted);
}

.me {
  font-weight: 800;
}

.results .rk,
.standings .rk {
  width: 32px;
  font-weight: 800;
  color: var(--muted);
}

.results .dl {
  min-width: 36px;
  text-align: end;
  font-weight: 800;
}

.results .dl.up {
  color: var(--good);
}

.results .dl.down {
  color: var(--danger);
}

.results .pc {
  min-width: 48px;
  text-align: end;
  font-size: 13px;
}

.results li.out {
  opacity: 0.6;
}

.elim {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  font-weight: 800;
  animation: elim 0.5s ease;
}

@keyframes elim {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}

/* code trade */
.sym {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: var(--c);
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
}

.clues {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clue {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--surface-2);
}

.clue > span:nth-child(2) {
  flex: 1;
  font-size: 14px;
}

.clue.in > span:nth-child(2) {
  color: var(--good);
  font-weight: 700;
}

.clue.notin > span:nth-child(2) {
  color: var(--muted);
}

.clue.sel {
  outline: 2px solid var(--accent);
}

.mini-btn {
  flex-shrink: 0;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.mini-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.mini-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.offer-to {
  margin-top: 10px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.offer-in {
  border-color: var(--accent);
  animation: elim 0.4s ease;
}

.offer-in p {
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.row-btns {
  display: flex;
  gap: 8px;
}

.row-btns .btn {
  flex: 1;
}

.sym-pick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.sym-btn {
  min-height: 52px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.sym-btn .sym {
  width: 36px;
  height: 36px;
  font-size: 22px;
}

.sym-btn.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.guesses {
  margin-top: 10px;
}

.gsyms {
  display: flex;
  gap: 4px;
  flex: 1;
}

.gsyms .sym {
  width: 24px;
  height: 24px;
  font-size: 14px;
}

.others {
  font-size: 13px;
  color: var(--muted);
}

/* block battle */
.bscore {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.bscore b {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.bboard {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 3px;
  padding: 6px;
  border-radius: 14px;
  background: #1d1b2c;
  width: min(100%, 420px);
  margin: 0 auto;
  touch-action: manipulation;
}

.bboard.over {
  opacity: 0.55;
}

.bcell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: #2c2945;
  cursor: pointer;
}

.bcell[data-full] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 60%, white), var(--c));
}

.bcell.ghost {
  background: color-mix(in srgb, #ffffff 35%, #2c2945);
}

.bcell.ghost-bad {
  background: color-mix(in srgb, var(--danger) 45%, #2c2945);
}

.btray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.bpiece {
  min-height: 84px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.bpiece.sel {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-3px);
}

.bpiece:disabled {
  opacity: 0.35;
}

.mshape {
  display: grid;
  grid-template-columns: repeat(var(--w), 16px);
  grid-template-rows: repeat(var(--h), 16px);
  gap: 2px;
}

.mshape i {
  border-radius: 4px;
  background: var(--accent);
}

/* negotiation */
.give-list .pcount {
  font-size: 13px;
}

/* final duel */
.duel-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}

.duelist {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.duelist.me {
  border-color: var(--accent);
}

.duelist.gone {
  opacity: 0.45;
}

.duelist .dn {
  font-weight: 800;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.duelist .dw {
  font-size: 13px;
  min-height: 18px;
}

/* end */
.winner-box {
  text-align: center;
  padding: 12px 0 0;
}

.winner-box h2 {
  margin: 0;
  font-size: clamp(24px, 7vw, 32px);
}

.trophy {
  font-size: 72px;
  margin: 0;
  line-height: 1;
  animation: trophy 1.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes trophy {
  from {
    transform: scale(0.2) rotate(-20deg);
    opacity: 0;
  }
}

.burst {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.burst i {
  position: absolute;
  top: -12px;
  left: var(--x);
  width: 8px;
  height: 14px;
  border-radius: 2px;
  background: var(--c);
  animation: fall 2.2s ease-in var(--d) forwards;
}

@keyframes fall {
  to {
    transform: translateY(105vh) rotate(540deg);
  }
}

.match-emotes {
  margin-top: 8px;
}

.emote.small {
  min-height: 40px;
  font-size: 19px;
}

@media (prefers-reduced-motion: reduce) {
  .trophy,
  .elim,
  .offer-in,
  .burst {
    animation: none;
  }
  .burst {
    display: none;
  }
}
