:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #ebe6db;
  --text: #1f1d1a;
  --muted: #6b655c;
  --line: #d8d1c3;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --gold: #c98f1c;
  --win: #2e8b57;
  --lose: #b5473a;
  --shadow: 0 2px 10px rgb(0 0 0 / 0.08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1f2226;
    --surface-2: #2a2e33;
    --text: #ece8e1;
    --muted: #a19b91;
    --line: #3a3f45;
    --accent: #5fb59b;
    --accent-text: #0e1513;
    --gold: #e5b04a;
    --win: #5cc08a;
    --lose: #e07b6d;
    --shadow: 0 2px 12px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1f2226;
  --surface-2: #2a2e33;
  --text: #ece8e1;
  --muted: #a19b91;
  --line: #3a3f45;
  --accent: #5fb59b;
  --accent-text: #0e1513;
  --gold: #e5b04a;
  --win: #5cc08a;
  --lose: #e07b6d;
  --shadow: 0 2px 12px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; letter-spacing: .02em; }
.top nav { display: flex; align-items: center; gap: .75rem; }
.who { color: var(--muted); font-size: .9rem; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 64rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); padding: .6rem 1rem; min-height: 2.75rem;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: .25rem; min-height: 0; }
button.icon { padding: .25rem .6rem; min-height: 2.25rem; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input, select {
  font: inherit; padding: .55rem .7rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); min-height: 2.75rem;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 1rem; }
.narrow { max-width: 32rem; margin: 0 auto; }
.medium { max-width: 40rem; margin: 0 auto; }
.wide { max-width: 44rem; margin: 0 auto; }
.full { width: 100%; }
.num { width: 6rem; }
.flush { margin: 0; }
.row.spread { justify-content: space-between; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); }

/* deck chooser */
.decks { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.deck-opt { display: flex; gap: .75rem; align-items: center; text-align: left; padding: .6rem; }
.deck-opt img { width: 4.5rem; height: 3.2rem; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.deck-opt[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--surface-2); }
.deck-opt strong { display: block; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

.tag { display: inline-block; margin-left: .3rem; font-size: .75rem; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); margin-right: .35rem; vertical-align: middle; }
.dot.on { background: var(--win); }

.invite { display: flex; gap: .5rem; }
.invite input { flex: 1; min-width: 0; font-size: .85rem; }

/* game table */
.table { display: grid; gap: 1rem; grid-template-columns: minmax(0, 22rem) 1fr; align-items: start; }
@media (max-width: 720px) { .table { grid-template-columns: 1fr; } }
.status { font-weight: 600; padding: .6rem .9rem; border-radius: 10px; background: var(--surface-2); }
.status.turn { background: var(--accent); color: var(--accent-text); }
.players { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }
.pl { padding: .6rem .75rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.pl.active { border: 2px solid var(--gold); }
.pl.out { opacity: .5; }
.pl .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .c { font-size: 1.4rem; font-weight: 800; }
.meta { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; color: var(--muted); font-size: .9rem; }

/* card */
.card {
  --g: #2f6f5e;
  background: var(--surface); border-radius: 16px; overflow: hidden; border: 1px solid var(--line);
  box-shadow: var(--shadow); width: 100%; max-width: 22rem;
}
.card .head { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; background: var(--g); color: #fff; }
.card .code { font-weight: 800; font-size: 1.1rem; background: rgb(255 255 255 / .2); border-radius: 8px; padding: .05rem .45rem; }
.card .name { font-weight: 700; line-height: 1.15; }
.card .sub { font-size: .8rem; opacity: .9; }
.card .pic { aspect-ratio: 4 / 3; background: var(--surface-2); position: relative; }
.card .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .credit { font-size: .66rem; color: var(--muted); padding: .2rem .75rem; border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .credit a { color: inherit; }
.card .attrs { list-style: none; margin: 0; padding: .25rem; }
.card .attrs li { margin: 0; }
.attr {
  display: flex; justify-content: space-between; gap: .5rem; width: 100%;
  border: 0; border-radius: 8px; background: none; padding: .5rem .6rem; min-height: 2.6rem; text-align: left;
}
.attr .v { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.attr .hint { font-size: .7rem; color: var(--muted); margin-left: .3rem; }
.card.pick .attr { background: var(--surface-2); margin: .2rem 0; }
.card.pick .attr:hover { background: var(--accent); color: var(--accent-text); }
.card.pick .attr:hover .hint { color: inherit; }
.attr.chosen { background: var(--gold); color: #1d1d1d; }
.attr.chosen .hint { color: inherit; }
.card .attrs button.attr:disabled { opacity: 1; cursor: default; }

.card.small { max-width: 15rem; font-size: .88rem; }
.card.small .attr { min-height: 0; padding: .3rem .5rem; }
.card.small .pic { aspect-ratio: 16 / 9; }
.card.won { outline: 3px solid var(--win); }

/* group colors A-H */
.g-A { --g: #b5473a; } .g-B { --g: #c27a1c; } .g-C { --g: #8a7a12; } .g-D { --g: #2e8b57; }
.g-E { --g: #23798e; } .g-F { --g: #3c5fa8; } .g-G { --g: #6a4ca3; } .g-H { --g: #a34879; }

/* round result */
.reveal { border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); padding: 1rem; }
.reveal .cards { display: flex; gap: .75rem; margin-top: .75rem; overflow-x: auto; padding-bottom: .25rem; scroll-snap-type: x proximity; }
.reveal .cards > div { flex: 0 0 13.5rem; scroll-snap-align: start; }
.reveal .who { display: block; color: var(--text); font-weight: 600; margin-bottom: .3rem; max-width: none; }

.ranking { counter-reset: r; }
.ranking li::before { counter-increment: r; content: counter(r) "."; font-weight: 700; margin-right: .5rem; color: var(--muted); }
.ranking li { justify-content: flex-start; }
.ranking li .grow { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom, 0)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 10; max-width: calc(100% - 2rem);
}

/* minimal motion */
@keyframes flip-in { from { transform: perspective(800px) rotateY(80deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { 0% { transform: scale(.96); } 60% { transform: scale(1.02); } 100% { transform: none; } }
.anim-flip { animation: flip-in .35s ease-out both; }
.reveal .cards > * { animation: flip-in .35s ease-out both; }
.reveal .cards > *:nth-child(2) { animation-delay: .1s; }
.reveal .cards > *:nth-child(3) { animation-delay: .2s; }
.reveal .cards > *:nth-child(4) { animation-delay: .3s; }
.card.won { animation: pop .4s .4s ease-out both; }
.reveal.no-anim .cards > *, .reveal.no-anim .card.won { animation: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
