:root {
  --bg: #eef4fb;
  --panel: #ffffff;
  --ink: #1f2a37;
  --ink-2: #5b6776;
  --line: #d6dfea;
  --accent: #2f6fd6;
  --accent-ink: #ffffff;
  --red: #e0473b;
  --gold: #f2b134;
  --win: #1f9d6a;
  --table: #2c5aa0;
  --table-2: #234a85;
  --shadow: 0 2px 0 rgb(31 42 55 / 0.12), 0 6px 18px -10px rgb(31 42 55 / 0.35);
  --font: 'M PLUS Rounded 1c', 'Hiragino Sans', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #151b24;
    --panel: #1f2733;
    --ink: #e8edf3;
    --ink-2: #a6b1bf;
    --line: #34404f;
    --accent: #6aa0ff;
    --accent-ink: #0d1522;
    --table: #1d3a66;
    --table-2: #172f53;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 16px 24px;
}

[hidden] {
  display: none !important;
}

h1,
h2 {
  font-weight: 800;
  line-height: 1.3;
}

/* ---------- ヘッダー ---------- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 920px;
  margin: 0 auto;
  padding: 10px 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
}

.logo-mark {
  width: 28px;
  height: 28px;
  background: url('/img/icon.svg') center / contain no-repeat;
}

/* ---------- 共通 ---------- */
.panel {
  margin: 16px 0;
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.center {
  text-align: center;
}

.btn {
  padding: 10px 20px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: 800 1rem var(--font);
  cursor: pointer;
}

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

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0 0 10px;
  padding: 0;
  border: 0;
}

legend {
  width: 100%;
  margin-bottom: 2px;
  color: var(--ink-2);
  font-size: 0.85rem;
}

input[type='text'] {
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font: 500 1rem var(--font);
}

.field {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
  color: var(--ink-2);
  font-size: 0.85rem;
}

.note {
  color: var(--ink-2);
  font-size: 0.85rem;
}

/* ---------- トップ ---------- */
.hero {
  padding: 12px 0 0;
  text-align: center;
}

.hero h1 {
  margin: 8px 0 4px;
  font-size: clamp(2rem, 9vw, 3rem);
  color: var(--accent);
  letter-spacing: 0.05em;
}

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0 16px;
}

.join {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.join input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.rules ol {
  margin: 0;
  padding-left: 1.4em;
}

/* ---------- 待ち合わせ ---------- */
.code {
  margin: 0;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--accent);
}

.share {
  display: flex;
  gap: 8px;
  margin: 10px 0 16px;
}

.share input {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
}

/* ---------- ゲーム ---------- */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.who b {
  min-width: 2em;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--gold);
  color: #3a2a00;
  text-align: center;
}

.who.me {
  justify-content: flex-end;
}

.who.offline span::after {
  content: '（切断中）';
  color: var(--red);
  font-size: 0.8em;
}

.round {
  color: var(--ink-2);
  font-size: 0.85rem;
}

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

@media (min-width: 640px) {
  .hand {
    grid-template-columns: repeat(8, 1fr);
  }
}

.flag-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: 3px solid transparent;
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  font: 500 0.75rem var(--font);
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}

.flag-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
  outline: 1px solid rgb(0 0 0 / 0.12);
}

.flag-card .cname {
  min-height: 1.3em;
  line-height: 1.3;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

button.flag-card {
  cursor: pointer;
}

button.flag-card:hover:not(:disabled) {
  transform: translateY(-3px);
}

.flag-card.selected {
  border-color: var(--accent);
  transform: translateY(-6px);
}

.flag-card.used {
  opacity: 0.25;
  box-shadow: none;
}

.opp-hand .flag-card {
  box-shadow: none;
  border-color: var(--line);
}

.table {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  margin: 14px 0 6px;
  padding: 18px 12px;
  border-radius: 20px;
  background: radial-gradient(ellipse at 50% 40%, var(--table), var(--table-2));
}

.deck {
  position: relative;
  width: 58px;
  height: 80px;
}

.deck span {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  border: 2px solid #fff;
  background: repeating-linear-gradient(45deg, #e0473b 0 6px, #c93a2f 6px 12px);
}

.deck b {
  position: absolute;
  inset: auto 0 -22px;
  color: #fff;
  font-size: 0.75rem;
  text-align: center;
}

.topic-card {
  display: grid;
  place-items: center;
  width: min(220px, 55vw);
  min-height: 120px;
  padding: 12px;
  border-radius: 14px;
  background: #fffdf5;
  color: #1f2a37;
  box-shadow: 0 6px 0 rgb(0 0 0 / 0.2);
  text-align: center;
}

.topic-card .label {
  color: #8a6d1f;
  font-size: 0.75rem;
}

.topic-card .title {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.35;
}

.topic-card.flip {
  animation: flip 0.45s ease-out;
}

@keyframes flip {
  from {
    transform: rotateY(90deg);
  }
  to {
    transform: rotateY(0);
  }
}

.carry {
  position: absolute;
  right: 10px;
  top: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: #3a2a00;
  font-size: 0.75rem;
  font-weight: 800;
}

.status {
  min-height: 1.7em;
  margin: 18px 0 8px;
  text-align: center;
  font-weight: 800;
}

.actions {
  position: sticky;
  bottom: 0;
  padding: 12px 0;
  text-align: center;
  background: linear-gradient(transparent, var(--bg) 30%);
}

.actions .btn {
  min-width: 220px;
}

/* ---------- 出し合った結果 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start center;
  padding: 16px;
  overflow-y: auto;
  background: rgb(10 20 35 / 0.6);
}

.reveal-box {
  width: min(520px, 100%);
  margin: auto 0;
  padding: 18px;
  border-radius: 18px;
  background: var(--panel);
  text-align: center;
  animation: pop 0.25s ease-out;
}

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

.reveal-topic {
  margin: 0 0 10px;
  font-size: 1.15rem;
  font-weight: 800;
}

.reveal-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.reveal-side {
  padding: 8px;
  border: 3px solid var(--line);
  border-radius: 14px;
}

.reveal-side.win {
  border-color: var(--win);
  background: color-mix(in srgb, var(--win) 10%, transparent);
}

.reveal-side img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
  outline: 1px solid rgb(0 0 0 / 0.12);
}

.reveal-side .who-label {
  color: var(--ink-2);
  font-size: 0.75rem;
}

.reveal-side .cname {
  font-weight: 800;
}

.reveal-side .val {
  font-size: 1.05rem;
  font-weight: 800;
}

.reveal-side .mark {
  color: var(--win);
  font-weight: 800;
}

.reveal-result {
  margin: 12px 0 4px;
  font-size: 1.2rem;
  font-weight: 800;
}

.reveal-src {
  margin: 0 0 12px;
  color: var(--ink-2);
  font-size: 0.72rem;
}

.reveal-src a {
  color: var(--ink-2);
}

/* ---------- 結果 ---------- */
.end-score {
  font-size: 1.4rem;
  font-weight: 800;
}

.end-btns {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.review-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.review-row:last-child {
  border-bottom: 0;
}

.review-topic {
  font-weight: 800;
}

.review-topic small {
  margin-left: 6px;
  color: var(--ink-2);
  font-weight: 500;
}

.review-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.85rem;
}

.review-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.review-cell:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.review-pair img {
  width: 36px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 2px;
  outline: 1px solid rgb(0 0 0 / 0.12);
}

.review-pair .win {
  color: var(--win);
  font-weight: 800;
}

.foot {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
  color: var(--ink-2);
  font-size: 0.75rem;
}

/* ---------- 地図 ---------- */
.map {
  margin: 4px 0 8px;
}

.map svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.map .sea {
  fill: #cfe3f7;
}

.map .land {
  fill: #f4f1e8;
  stroke: #a9b4c0;
  stroke-width: 0.08;
}

.map .land.me,
.map .land.one {
  fill: #7fa9ef;
}

.map .land.opp {
  fill: #f19a92;
}

.map .pin {
  stroke: #fff;
}

.map .pin.me,
.map .pin.one {
  fill: #1d4fa8;
}

.map .pin.opp {
  fill: #b8261b;
}

.map .pin-label {
  fill: #1f2a37;
  stroke: #fff;
  paint-order: stroke;
  text-anchor: middle;
  font-weight: 800;
}

.map-note,
.map-loading {
  margin: 2px 0 0;
  color: var(--ink-2);
  font-size: 0.7rem;
  text-align: right;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .map .sea {
    fill: #233a57;
  }

  :root:not([data-theme='light']) .map .land {
    fill: #3a4656;
    stroke: #5b6776;
  }
}

/* ---------- くわしい情報 ---------- */
.detail-title {
  margin: 12px 0 6px;
  font-size: 1rem;
  text-align: left;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.tabs button {
  flex: 1;
  padding: 6px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: 800 0.85rem var(--font);
  cursor: pointer;
}

.tabs button[aria-selected='true'] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.profile {
  text-align: left;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.profile-head img {
  width: 64px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
  outline: 1px solid rgb(0 0 0 / 0.12);
}

.profile-head b {
  display: block;
  font-size: 1.15rem;
}

.profile-head span {
  color: var(--ink-2);
  font-size: 0.85rem;
}

.facts {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.facts th,
.facts td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

.facts th {
  width: 8.5em;
  color: var(--ink-2);
  font-weight: 500;
}

.facts tr.hl th,
.facts tr.hl td {
  background: color-mix(in srgb, var(--gold) 22%, transparent);
}

.facts .rank {
  margin-left: 8px;
  color: var(--accent);
  font-weight: 800;
}

.facts .rank small {
  color: var(--ink-2);
  font-weight: 500;
}

.facts .src {
  display: block;
  color: var(--ink-2);
  font-size: 0.7rem;
}

.facts .src a {
  color: var(--ink-2);
}

.reveal-foot {
  position: sticky;
  bottom: -18px;
  margin: 12px -18px -18px;
  padding: 12px;
  border-radius: 0 0 18px 18px;
  background: var(--panel);
  box-shadow: 0 -6px 12px -10px rgb(0 0 0 / 0.4);
}

.reveal-foot .btn {
  min-width: 200px;
}

.all-cards .flag-card {
  cursor: pointer;
}

/* ---------- 制限時間 ---------- */
.timer {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 360px;
  margin: -4px auto 10px;
}

.timer-bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.timer-bar i {
  display: block;
  height: 100%;
  background: var(--win);
  transition: width 0.2s linear;
}

.timer.hurry .timer-bar i {
  background: var(--red);
}

.timer b {
  min-width: 3.2em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.timer.hurry b {
  color: var(--red);
}

.reveal-side .auto {
  color: var(--red);
  font-size: 0.75rem;
}

/* ---------- 配る演出 ---------- */
.flag-card.deal {
  animation: deal 0.45s cubic-bezier(0.2, 0.8, 0.3, 1.2) both;
}

.flag-card.deal.from-top {
  --deal-from: translate(0, 140px) rotate(-8deg) scale(0.6);
}

.flag-card.deal.from-bottom {
  --deal-from: translate(0, -160px) rotate(8deg) scale(0.6);
}

@keyframes deal {
  from {
    opacity: 0;
    transform: var(--deal-from);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.topic-card .title.small {
  font-size: 1rem;
}

@media (prefers-reduced-motion: reduce) {
  .flag-card.deal,
  .topic-card.flip {
    animation: none;
  }
}

/* ---------- カード図鑑 ---------- */
.top-link {
  color: var(--accent);
  font-weight: 800;
  font-size: 0.9rem;
}

.page-title {
  margin: 8px 0 0;
  color: var(--accent);
}

.book-tabs {
  max-width: 420px;
  margin: 12px 0;
}

.book-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 6px;
}

.book-tools fieldset {
  margin: 0;
}

input[type='search'] {
  padding: 6px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: 500 0.95rem var(--font);
}

.book-btns {
  display: flex;
  gap: 6px;
}

.btn.small {
  padding: 4px 12px;
  font-size: 0.85rem;
}

.book {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.fcard {
  height: 210px;
  perspective: 900px;
  cursor: pointer;
  outline: none;
}

.fcard:focus-visible .fcard-inner {
  outline: 3px solid var(--accent);
  border-radius: 14px;
}

.fcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s;
  transform-style: preserve-3d;
}

.fcard.flipped .fcard-inner {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  overflow: hidden;
}

.fcard .front {
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.fcard .front img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  outline: 1px solid rgb(0 0 0 / 0.12);
}

.fcard .back {
  transform: rotateY(180deg);
  gap: 2px;
  padding: 10px 12px;
  font-size: 0.78rem;
}

.back-name {
  font-size: 1rem;
  line-height: 1.3;
}

.back-cap {
  color: var(--ink-2);
}

.fcard dl {
  margin: 4px 0 0;
}

.fcard dl div {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  border-bottom: 1px dashed var(--line);
}

.fcard dt {
  color: var(--ink-2);
}

.fcard dd {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

.fcard .more {
  margin-top: auto;
  padding: 4px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: 800 0.8rem var(--font);
  cursor: pointer;
}

.topic-book {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.tcard {
  height: 290px;
}

.tcard .front {
  background: #fffdf5;
  color: #1f2a37;
  text-align: center;
}

.tcard .front .label {
  color: #8a6d1f;
  font-size: 0.8rem;
}

.tcard .front .title {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.4;
}

.back-note {
  display: -webkit-box;
  color: var(--ink-2);
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.top3 {
  margin: 6px 0;
  padding-left: 1.6em;
}

.top3 li {
  margin: 4px 0;
}

.top3 img {
  width: 26px;
  margin-right: 6px;
  vertical-align: -3px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 2px;
  outline: 1px solid rgb(0 0 0 / 0.12);
}

.top3 small {
  display: block;
  color: var(--ink-2);
}

.back-src {
  margin-top: auto;
  color: var(--ink-2);
  font-size: 0.7rem;
}

.home-links {
  text-align: center;
}

a.btn {
  display: inline-block;
  text-decoration: none;
}

.end-btns {
  flex-wrap: wrap;
}
