:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --ink: #1d2430;
  --muted: #687080;
  --line: #d9d4c8;
  --table: #167a63;
  --table-dark: #0f574a;
  --gold: #d49b35;
  --red: #bf2f39;
  --blue: #1d5c9c;
  --white: #fffdf8;
  --shadow: 0 16px 40px rgba(24, 32, 41, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    system-ui,
    sans-serif;
  background: linear-gradient(135deg, #f7f5ef 0%, #e8f1ed 48%, #f3ece1 100%);
}

button,
select {
  font: inherit;
}

.game-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.top-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 460px);
  gap: 18px;
  align-items: end;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.84);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--table-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.1rem;
}

.summary {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.setup-panel {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

select,
.primary-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

select {
  width: 100%;
  padding: 0 12px;
  color: var(--ink);
  background: var(--white);
}

.primary-button {
  padding: 0 18px;
  border-color: var(--table-dark);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  background: var(--table-dark);
}

.primary-button:hover {
  background: var(--table);
}

.ad-slot {
  display: grid;
  place-items: center;
  min-height: 88px;
  border: 1px dashed #b9afa0;
  border-radius: 8px;
  color: #756c61;
  text-align: center;
  background: rgba(255, 253, 248, 0.68);
}

.ad-slot span {
  display: block;
  font-size: 0.8rem;
}

.ad-slot strong {
  font-size: 0.95rem;
}

.ad-slot-top {
  margin: 16px 0;
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.status-bar > div,
.score-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

.status-bar > div {
  padding: 12px 14px;
}

.status-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-bar strong {
  font-size: 1.2rem;
}

.play-area {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 180px;
  gap: 16px;
  align-items: start;
}

.score-panel {
  padding: 16px;
}

.scoreboard {
  display: grid;
  gap: 10px;
}

.player-score {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.player-score.is-active {
  border-color: var(--gold);
  box-shadow: inset 4px 0 0 var(--gold);
}

.board-wrap {
  min-width: 0;
}

.message {
  min-height: 42px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
  background: var(--table-dark);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(46px, 1fr));
  gap: 8px;
  padding: 14px;
  border: 10px solid #7c5130;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    var(--table);
  background-size: 24px 24px;
  box-shadow: var(--shadow);
}

.card {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 2.5 / 3.5;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  perspective: 900px;
  background: transparent;
}

.card:disabled {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow: 0 4px 12px rgba(10, 18, 24, 0.16);
}

.card-back {
  border: 2px solid #f7f0df;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.34), transparent 22%),
    repeating-linear-gradient(45deg, #214c86 0 8px, #173966 8px 16px);
}

.card-front {
  overflow: hidden;
  padding: 5px;
  border: 1px solid #d9d4c8;
  transform: rotateY(180deg);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(248, 244, 236, 0.92)),
    var(--white);
}

.corner {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 16px;
  line-height: 0.9;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 900;
  pointer-events: none;
}

.corner b {
  font-size: clamp(0.5rem, 0.78vw, 0.68rem);
}

.corner span {
  font-size: clamp(0.48rem, 0.72vw, 0.64rem);
}

.corner-top {
  top: 3px;
  left: 3px;
}

.corner-bottom {
  right: 3px;
  bottom: 3px;
  transform: rotate(180deg);
}

.pip-layout {
  position: absolute;
  inset: 24px 13px 23px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(5, 1fr);
  place-items: center;
  width: calc(100% - 26px);
  height: calc(100% - 47px);
  pointer-events: none;
}

.pip {
  display: grid;
  place-items: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.62rem, 1.08vw, 0.82rem);
  font-weight: 900;
  line-height: 1;
}

.top-left {
  grid-area: 1 / 1;
}

.top-center {
  grid-area: 1 / 2;
}

.top-right {
  grid-area: 1 / 3;
}

.upper-left {
  grid-area: 2 / 1;
}

.upper-center {
  grid-area: 2 / 2;
}

.upper-right {
  grid-area: 2 / 3;
}

.middle-left {
  grid-area: 3 / 1;
}

.center {
  grid-area: 3 / 2;
}

.middle-right {
  grid-area: 3 / 3;
}

.lower-left {
  grid-area: 4 / 1;
  transform: rotate(180deg);
}

.lower-center {
  grid-area: 4 / 2;
  transform: rotate(180deg);
}

.lower-right {
  grid-area: 4 / 3;
  transform: rotate(180deg);
}

.bottom-left {
  grid-area: 5 / 1;
  transform: rotate(180deg);
}

.bottom-center {
  grid-area: 5 / 2;
  transform: rotate(180deg);
}

.bottom-right {
  grid-area: 5 / 3;
  transform: rotate(180deg);
}

.court-card {
  position: absolute;
  inset: 14px 6px;
  display: block;
  overflow: hidden;
  border-radius: 3px;
  pointer-events: none;
}

.court-portrait {
  display: block;
  width: 100%;
  height: 100%;
}

.red-card {
  color: #c1121f;
}

.black-card {
  color: #11151c;
}

.card.is-matched {
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease 180ms;
}

.game-over {
  background: #2d5b8a;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: 18px;
  padding: 18px 4px 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer nav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.site-footer a,
.back-link {
  color: var(--table-dark);
  font-weight: 800;
  text-decoration: none;
}

.site-footer a:hover,
.back-link:hover {
  text-decoration: underline;
}

.content-page {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.content-page h1 {
  margin: 18px 0 20px;
  font-size: clamp(2rem, 4vw, 3rem);
}

.content-page h2 {
  margin: 28px 0 8px;
  color: var(--table-dark);
}

.content-page p {
  color: #344052;
  font-size: 1rem;
  line-height: 1.9;
}

@media (max-width: 1100px) {
  .top-panel,
  .play-area {
    grid-template-columns: 1fr;
  }

  .setup-panel {
    grid-template-columns: 1fr 1fr;
  }

  .primary-button {
    grid-column: 1 / -1;
  }

  .ad-slot-side {
    min-height: 76px;
  }
}

@media (max-width: 760px) {
  .game-shell {
    padding: 12px;
  }

  .top-panel {
    padding: 16px;
  }

  .setup-panel,
  .status-bar {
    grid-template-columns: 1fr;
  }

  .card-grid {
    grid-template-columns: repeat(4, minmax(54px, 1fr));
    gap: 7px;
    padding: 10px;
    border-width: 6px;
  }

  .pip-layout {
    inset: 26px 17px 25px;
    width: calc(100% - 34px);
    height: calc(100% - 51px);
  }

  .pip {
    font-size: clamp(0.6rem, 3.2vw, 0.86rem);
  }

  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}
