:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #64716c;
  --forest: #123d32;
  --forest-2: #1c5949;
  --mint: #dfece6;
  --cream: #f6f1e7;
  --paper: #fffdf8;
  --line: #d9ded9;
  --red: #c43f43;
  --gold: #d69c36;
  --danger: #b72e35;
  --shadow: 0 16px 40px rgba(18, 61, 50, 0.12);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--cream);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 5%, rgba(214, 156, 54, 0.16), transparent 28rem),
    linear-gradient(180deg, #edf4ef 0, var(--cream) 34rem);
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px max(30px, env(safe-area-inset-bottom));
}

.hero,
.section-heading,
.progress-card > div:first-child,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hero {
  margin-bottom: 18px;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-link {
  padding: 9px 11px;
  border: 1px solid rgba(18, 61, 50, 0.14);
  border-radius: 12px;
  color: var(--forest);
  background: rgba(255, 253, 248, 0.72);
  font-size: 0.76rem;
  font-weight: 800;
  text-decoration: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--forest-2);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(2rem, 9vw, 2.8rem);
  letter-spacing: 0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.icon-button,
.close-button {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  color: #fff;
  background: var(--forest);
  font-size: 1.2rem;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(18, 61, 50, 0.2);
}

.progress-card,
.palette-card {
  border: 1px solid rgba(18, 61, 50, 0.08);
  border-radius: 20px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.progress-card {
  padding: 16px 18px 13px;
}

.progress-label,
.section-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

.progress-track {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e8e4;
}

.progress-bar {
  width: 20%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--forest-2), #56a783);
  transition: width 220ms ease;
}

.board-wrap {
  position: relative;
  display: grid;
  grid-template-columns: 28px 1fr;
  grid-template-rows: 28px 1fr;
  margin: 20px 0;
}

.corner-label {
  display: grid;
  grid-column: 1;
  grid-row: 1;
  place-items: center;
  color: var(--muted);
  font-size: 0.54rem;
}

.column-label {
  display: grid;
  grid-row: 1;
  place-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.column-label:nth-of-type(2) { grid-column: 2; transform: translateX(-40%); }
.column-label:nth-of-type(3) { grid-column: 2; transform: translateX(-20%); }
.column-label:nth-of-type(4) { grid-column: 2; }
.column-label:nth-of-type(5) { grid-column: 2; transform: translateX(20%); }
.column-label:nth-of-type(6) { grid-column: 2; transform: translateX(40%); }

.board {
  display: grid;
  grid-column: 2;
  grid-row: 2;
  grid-template-columns: repeat(5, 1fr);
  overflow: hidden;
  border: 3px solid var(--forest);
  border-radius: 18px;
  background: var(--forest);
  box-shadow: 0 18px 36px rgba(18, 61, 50, 0.2);
}

.row-labels {
  display: grid;
  grid-column: 1;
  grid-row: 2;
  grid-template-rows: repeat(5, 1fr);
}

.row-labels span {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.cell {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid rgba(18, 61, 50, 0.18);
  border-bottom: 1px solid rgba(18, 61, 50, 0.18);
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  transition: transform 120ms ease, background 150ms ease, box-shadow 150ms ease;
}

.cell:nth-child(5n) { border-right: 0; }
.cell:nth-last-child(-n + 5) { border-bottom: 0; }

.cell:active:not(.is-fixed) {
  transform: scale(0.92);
}

.cell.is-fixed {
  background:
    repeating-linear-gradient(135deg, rgba(18, 61, 50, 0.035) 0 5px, transparent 5px 10px),
    #edf0ec;
  cursor: default;
}

.suit {
  line-height: 1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 10.8vw, 3.2rem);
  font-weight: 700;
}

.cell[data-piece="H"] .suit,
.cell[data-piece="D"] .suit,
.palette-button[data-piece="H"] .palette-symbol,
.palette-button[data-piece="D"] .palette-symbol {
  color: var(--red);
}

.cell[data-piece="J"] .suit {
  font-family: inherit;
  font-size: clamp(1.25rem, 6vw, 2rem);
  color: var(--forest-2);
}

.coordinate {
  position: absolute;
  right: 5px;
  bottom: 4px;
  color: #8b948f;
  font-size: clamp(0.48rem, 2vw, 0.65rem);
  font-weight: 700;
}

.lock {
  position: absolute;
  top: 4px;
  left: 5px;
  color: #89918d;
  font-size: 0.62rem;
}

.palette-card {
  margin-bottom: 16px;
  padding: 16px;
}

.section-heading {
  gap: 12px;
  margin-bottom: 13px;
}

.palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.palette-button {
  display: grid;
  min-width: 0;
  min-height: 76px;
  padding: 7px 2px;
  place-items: center;
  border: 2px solid transparent;
  border-radius: 14px;
  color: var(--ink);
  background: #f0f2ef;
  cursor: pointer;
}

.palette-button.is-selected {
  border-color: var(--forest-2);
  background: var(--mint);
  box-shadow: 0 5px 15px rgba(18, 61, 50, 0.14);
}

.palette-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.palette-symbol {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}

.palette-button[data-piece="J"] .palette-symbol {
  font-family: inherit;
  color: var(--forest-2);
  font-size: 1rem;
}

.palette-name,
.palette-count {
  font-size: 0.68rem;
}

.palette-count {
  color: var(--muted);
  font-weight: 800;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.button {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
}

.button-primary {
  color: #fff;
  background: var(--forest);
  box-shadow: 0 8px 18px rgba(18, 61, 50, 0.2);
}

.button-ghost {
  color: var(--muted);
  background: #e8ece9;
}

.dialog {
  width: min(calc(100% - 32px), 480px);
  padding: 22px;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(10, 31, 25, 0.32);
}

.dialog::backdrop {
  background: rgba(10, 28, 23, 0.62);
  backdrop-filter: blur(3px);
}

.dialog h2 {
  font-size: 1.35rem;
}

.dialog ol {
  padding-left: 1.3rem;
  color: #3e4c47;
  font-size: 0.9rem;
  line-height: 1.7;
}

.close-button {
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: #ecefeb;
  font-size: 1.4rem;
}

.dialog-confirm {
  width: 100%;
}

.win-dialog {
  text-align: center;
}

.win-mark {
  display: grid;
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--forest-2);
  font-size: 2.5rem;
  box-shadow: 0 10px 28px rgba(18, 61, 50, 0.25);
}

.win-stats {
  margin: 12px 0 22px;
  color: var(--muted);
}

.win-dialog .button {
  width: 100%;
  margin-top: 8px;
}

@media (min-width: 520px) {
  .app-shell { padding-inline: 26px; }
  .cell .coordinate { right: 7px; bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
