:root {
  --ground: #f7f3ea;
  --ground-deep: #ebe4d6;
  --jade: #1b5e4a;
  --jade-light: #2a7a62;
  --mahogany: #5c3a29;
  --brass: #b8860b;
  --brass-light: #d4a843;
  --ink: #2c2419;
  --muted: #5a5248;
  --card-bg: #fffdf8;
  --border: #d4cbb8;
  --shadow: rgba(44, 36, 25, 0.12);
  --header-h: 3.75rem;
  --radius: 0.5rem;
  --font-serif: Georgia, "Times New Roman", Times, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --max-w: 72rem;
  --prose-w: 42rem;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  position: relative;
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--ground);
  background-image: radial-gradient(ellipse at 50% 0%, #fffef9 0%, var(--ground) 55%);
  min-height: 100vh;
}

img,
svg {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--jade);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--jade-light);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: 0.65rem 1rem;
  background: var(--jade);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.skip-link:focus {
  left: 0.75rem;
  top: 0.35rem;
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.site-footer {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 2rem 1.25rem 2.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0 0 0.65rem;
}

.site-footer a {
  text-decoration: none;
}

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

.crumbs {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.crumbs a {
  text-decoration: none;
}

.content.wide {
  max-width: var(--max-w);
}

.meta {
  margin-top: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.lede {
  font-size: 1.12rem;
  color: var(--muted);
  max-width: 40rem;
}

.hero-brand {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 0.35rem;
}

.hero-tiles {
  margin: 0 0 1.25rem;
}

.hero-tiles figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.page-img.diagram {
  max-width: min(100%, 22rem);
  height: auto;
}

.affiliate-note {
  font-size: 0.88rem;
  color: var(--muted);
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-serif);
  color: var(--mahogany);
  line-height: 1.25;
  font-weight: 700;
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
}

h2 {
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  margin-top: 2rem;
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

h3 {
  font-size: 1.2rem;
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

[id] {
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

.top {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  background: rgba(247, 243, 234, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--shadow);
}

.top-inner {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--mahogany);
  text-decoration: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand:hover {
  color: var(--jade);
}

.brand-amp {
  color: var(--jade);
}

.brand .brand-mark {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

nav.top-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem 0.15rem;
  font-size: 0.9rem;
}

nav.top-nav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}

nav.top-nav a:hover {
  color: var(--jade);
  background: rgba(27, 94, 74, 0.08);
}

nav.top-nav a[aria-current="page"] {
  color: var(--jade);
  background: rgba(27, 94, 74, 0.12);
  font-weight: 600;
}

main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.prose {
  max-width: var(--prose-w);
}

.prose p {
  margin: 0 0 1rem;
}

.prose ul,
.prose ol {
  margin: 0 0 1rem;
  padding-left: 1.35rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.hero {
  padding: 2rem 0 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.hero h1 {
  margin: 0 0 0.75rem;
}

.hero .lede {
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 36rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-primary {
  background: var(--jade);
  color: #fff;
  border-color: var(--jade);
}

.btn-primary:hover {
  background: var(--jade-light);
  border-color: var(--jade-light);
  color: #fff;
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--mahogany);
  border-color: var(--brass);
}

.btn-secondary:hover {
  background: var(--ground-deep);
  color: var(--jade);
}

.btn-ghost {
  background: transparent;
  color: var(--jade);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--jade);
}

.callout {
  margin: 1.5rem 0;
  padding: 1rem 1.15rem;
  background: var(--card-bg);
  border-left: 4px solid var(--brass);
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: 0 1px 3px var(--shadow);
}

.callout strong {
  color: var(--mahogany);
}

.variant-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.variant-cards article {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 2px 6px var(--shadow);
}

.variant-cards h3 {
  margin: 0 0 0.5rem;
  color: var(--jade);
}

.calc,
.chooser,
.tool-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 2px 8px var(--shadow);
}

.calc fieldset,
.chooser fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1rem;
}

.calc legend,
.chooser legend {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--mahogany);
  padding: 0 0.35rem;
}

.calc label,
.chooser label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
  cursor: pointer;
}

.calc input[type="number"],
.calc select,
.chooser select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  background: #fff;
}

.calc-output {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--jade);
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--ground);
  border-radius: var(--radius);
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 4px var(--shadow);
}

.comparison-table th,
.comparison-table td {
  border: 1px solid var(--border);
  padding: 0.65rem 0.85rem;
  text-align: left;
  vertical-align: top;
}

.comparison-table th {
  background: var(--jade);
  color: #fff;
  font-family: var(--font-serif);
}

.comparison-table tr:nth-child(even) td {
  background: var(--ground);
}


.charleston-step {
  padding: 0.75rem;
  margin: 0.5rem 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.charleston-step.is-active {
  border-color: var(--jade);
  background: var(--ground);
}

.charleston-step.is-done {
  border-style: solid;
  opacity: 0.85;
}

.notation-input {
  width: 100%;
  min-height: 4rem;
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}

.notation-result {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--ground);
  border-radius: var(--radius);
}

.notation-result ul {
  margin: 0;
  padding-left: 1.1rem;
}

.notation-result li {
  margin: 0.3rem 0;
}

.notation-result code {
  font-weight: 700;
  color: var(--jade);
}

.notation-result .notation-unknown code {
  color: #a33;
}

.calc-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin: 0 0 1rem;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 0 1rem;
}

.calc .check-grid label {
  align-items: flex-start;
}

.calc .check-grid input {
  margin-top: 0.3rem;
}

.calc input:disabled + *,
.calc label:has(input:disabled) {
  color: var(--muted);
  cursor: not-allowed;
}

.charleston-status {
  font-weight: 600;
  color: var(--mahogany);
  margin: 0 0 0.75rem;
}

.charleston-layout {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.charleston-diagram {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
}

.charleston-svg {
  display: block;
  width: 100%;
  height: auto;
}

.charleston-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.charleston-step strong {
  display: block;
}

.charleston-step p {
  margin: 0.25rem 0 0;
}

.charleston-stage {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.charleston-rules {
  margin: 0.25rem 0 0;
}

.quiz-question {
  margin-bottom: 0.75rem;
}

.quiz-result {
  font-weight: 700;
  color: var(--jade);
  min-height: 1.5em;
}

button.variant-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  cursor: pointer;
}

button.variant-card strong {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--jade);
}

button.variant-card:hover,
button.variant-card.is-selected {
  border-color: var(--jade);
  background: var(--ground);
}

.variant-detail h3 {
  margin-bottom: 0.25rem;
}

.table-wrap {
  overflow-x: auto;
}

.comparison-table th.is-selected {
  background: var(--brass);
}

.comparison-table tr td.is-selected {
  background: #fbf3dc;
  font-weight: 600;
}

.chip-label {
  font-weight: 600;
}

@media (max-width: 640px) {
  .charleston-layout {
    grid-template-columns: 1fr;
  }

  .charleston-diagram {
    position: static;
    max-width: 16rem;
    margin: 0 auto;
  }
}

.atlas-controls,
.wall-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.75rem;
}

.atlas-controls label,
.wall-controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--mahogany);
}

.atlas-controls select,
.wall-controls select,
.chooser select,
.notation-example-select {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.atlas-count,
.atlas-totals {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0.25rem 0 1rem;
}

.atlas-group {
  margin: 1.5rem 0 0;
}

.atlas-group h3 {
  margin: 0 0 0.2rem;
}

.atlas-blurb {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.atlas-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.25rem, 1fr));
  gap: 0.75rem;
}

.atlas-item[hidden],
.atlas-group[hidden] {
  display: none;
}

.tile-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: 100%;
  height: 100%;
  padding: 0.85rem 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}

.tile-card:hover,
.tile-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--jade);
  box-shadow: 0 4px 12px var(--shadow);
  outline: none;
}

.tile-card .tile-face {
  display: block;
  width: clamp(56px, 7vw, 76px);
  max-width: none;
  height: auto;
  aspect-ratio: 3 / 4;
  margin: 0 0 0.35rem;
  filter: drop-shadow(0 2px 3px var(--shadow));
}

.tile-name {
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.25;
  color: var(--ink);
}

.tile-hanzi {
  font-size: 1rem;
  color: var(--mahogany);
}

.tile-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem;
  margin-top: 0.25rem;
}

.tile-count-chip {
  font-size: 0.7rem;
  line-height: 1.2;
  padding: 0.12rem 0.35rem;
  border-radius: 999px;
  background: rgba(27, 94, 74, 0.1);
  color: var(--jade);
  white-space: nowrap;
}

.tile-count-chip.is-zero {
  background: transparent;
  color: var(--muted);
  opacity: 0.7;
}

.atlas[data-active-ruleset="american"] .tile-count-chip[data-ruleset="american"],
.atlas[data-active-ruleset="chinese"] .tile-count-chip[data-ruleset="chinese"],
.atlas[data-active-ruleset="riichi"] .tile-count-chip[data-ruleset="riichi"] {
  background: var(--jade);
  color: #fff;
  opacity: 1;
}

.tile-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: min(36rem, 92vw);
  background: var(--card-bg);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.tile-dialog::backdrop {
  background: rgba(44, 36, 25, 0.55);
}

.tile-dialog-body {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;
}

.tile-dialog-art img {
  width: 180px;
  max-width: 45vw;
  height: auto;
  aspect-ratio: 3 / 4;
  filter: drop-shadow(0 4px 8px var(--shadow));
}

.tile-dialog-text {
  flex: 1 1 14rem;
}

.tile-dialog-text h2 {
  margin: 0 0 0.35rem;
}

.tile-dialog-hanzi {
  font-size: 1.6rem;
  margin: 0 0 0.5rem;
  color: var(--mahogany);
}

.tile-dialog-counts {
  margin: 0.75rem 0 0;
}

.tile-dialog-actions {
  margin-top: 1rem;
  text-align: right;
}

.phase-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.phase-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--mahogany);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
}

.phase-btn:hover {
  border-color: var(--jade);
  color: var(--jade);
}

.phase-btn[aria-pressed="true"] {
  background: var(--jade);
  border-color: var(--jade);
  color: #fff;
}

.wall-stats {
  font-weight: 600;
  color: var(--mahogany);
  margin: 0.5rem 0 0.25rem;
}

.wall-phase-copy {
  margin: 0 0 0.75rem;
  color: var(--ink);
  max-width: 46rem;
}

.wall-table-wrap {
  max-width: 40rem;
  margin: 0 auto;
}

.wall-table-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

.wall-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  padding: 0;
  margin: 0.85rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.wall-legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  display: inline-block;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 3px;
  border: 1px solid var(--mahogany);
}

.footer-note {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  :root {
    --header-h: auto;
  }

  .top {
    height: auto;
    padding: 0.5rem 0;
  }

  .top-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
  }

  nav.top-nav {
    font-size: 0.85rem;
    justify-content: flex-start;
    width: 100%;
  }

  .brand {
    font-size: 1.2rem;
  }

  .brand .brand-mark {
    width: 32px;
    height: 32px;
  }

  .comparison-table {
    display: block;
    overflow-x: auto;
  }
}
.sample-game {
  outline: none;
}

.sample-status {
  font-weight: 600;
  color: var(--mahogany);
  margin: 0 0 0.75rem;
}

.sample-table-wrap {
  max-width: 44rem;
  margin: 0 auto 1rem;
}

.sample-table-wrap svg,
.sample-table-svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: #1b5e4a;
}

/* Sizes below are SVG user units: the 800 unit table renders near 700px on desktop. */
.table-center-stack {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.table-label {
  box-sizing: border-box;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.97);
  border: 1px solid #d4cbb8;
  text-align: center;
  font-family: var(--font-sans);
  color: var(--mahogany);
  overflow-wrap: anywhere;
}

.table-label .label-title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 17px;
  line-height: 1.2;
}

.table-label .label-body {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
}

/* Phone: cancel main horizontal padding so the table uses the full content width. */
@media (max-width: 640px) {
  .sample-table-wrap {
    width: calc(100% + 2.5rem);
    max-width: none;
    margin-left: -1.25rem;
    margin-right: -1.25rem;
  }

  .sample-table-wrap svg,
  .sample-table-svg {
    border-radius: 0;
  }

  /* At phone width the table renders near half size, so labels scale up and the score
     detail, which the step note repeats, is dropped. */
  .table-label .label-title {
    font-size: 26px;
  }

  .table-label .label-body {
    font-size: 21px;
  }

  .table-label[data-label-kind="score"] .label-body {
    display: none;
  }

  .sample-table-svg .seat-label {
    font-size: 20px;
  }
}

.sample-note {
  margin: 0 0 1rem;
  max-width: 46rem;
  color: var(--ink);
  line-height: 1.5;
}

.sample-fallback {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.sample-fallback li {
  margin: 0.55rem 0;
}

.sample-fallback li.is-active,
.sample-fallback li[aria-current="step"] {
  background: var(--ground);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
  margin-left: -0.5rem;
}

.sample-fallback strong {
  display: block;
  color: var(--mahogany);
}
