/* Madishan Games — public site styles v3 (locked bright design, brief v2 §4).
   Mobile-first: base rules are the 320–639 px single-column contract (§4.5), then 640 px (two-column
   catalogue, 24 px gutters) and 1024 px (desktop contract §4.3). Plain CSS only — no nesting, no @scope,
   no container queries — so it runs the same in Safari. Light only: no prefers-color-scheme rules. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Short pages (404) keep the footer at the bottom of the small viewport; no forced 100vh frames. */
@supports (min-height: 100svh) {
  body {
    display: flex;
    flex-direction: column;
    min-height: 100svh;
  }

  body > main {
    flex: 1 0 auto;
  }
}

[hidden] {
  display: none !important;
}

img {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--primary);
}

button {
  font: inherit;
}

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* Safari before 15.4 has no :focus-visible: keep a visible keyboard ring there, hide it for pointer focus elsewhere. */
a:focus,
button:focus,
input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
  outline: none;
}

.skip {
  position: absolute;
  top: -100px;
  left: var(--gutter);
  z-index: 20;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  font-weight: 700;
  text-decoration: none;
}

.skip:focus {
  top: var(--sp-4);
}

.wrap {
  width: 100%;
  max-width: calc(var(--wrap) + 2 * var(--gutter));
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* ---------- buttons and pills ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 10px 20px;
  background: var(--primary);
  color: var(--on-primary);
  border: 0;
  border-radius: var(--radius-control);
  font-family: inherit;
  font-size: 14px;
  line-height: 20px;
  font-weight: 800;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 160ms ease-out;
}

.btn:hover {
  background: var(--primary-hover);
  color: var(--on-primary);
}

.btn--lg {
  min-height: 48px;
  font-size: 16px;
  line-height: 24px;
}

.btn--block {
  width: 100%;
}

.pill {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out;
}

.pill:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.pill[aria-pressed="true"] {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

@media (prefers-reduced-motion: no-preference) {
  .btn:active,
  .pill:active {
    transform: scale(0.99);
  }
}

/* ---------- header ---------- */
.hdr {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.hdr__in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: 64px;
}

.mark {
  color: var(--text);
  font-size: 21px;
  line-height: 28px;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.mark:hover {
  color: var(--primary);
}

.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
}

.nav a {
  color: var(--text);
  font-size: 15px;
  line-height: 22px;
  font-weight: 700;
  text-decoration: none;
  padding: var(--sp-2) 0;
}

.nav a:hover {
  color: var(--primary);
}

/* Mobile: only the small "Games" anchor pill; About and Contact live in the page and footer. */
.nav__more {
  display: none;
}

.nav a.nav__games {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 9px 16px;
}

.nav a.nav__games:hover {
  color: var(--primary-hover);
}

/* ---------- hero ---------- */
.hero {
  padding-top: var(--sp-5);
}

.hero__copy {
  position: relative;
}

.hero__label {
  display: none;
}

.hero__title {
  font-size: 30px;
  line-height: 36px;
  font-weight: 800;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
  overflow-wrap: anywhere;
}

.hero__title br {
  display: none;
}

.hero__intro {
  margin-top: var(--sp-2);
  color: var(--muted);
  font-size: 15px;
  line-height: 23px;
}

.hero__tile {
  display: none;
}

/* Featured panel ("In the spotlight") */
.spot {
  position: relative;
  margin-top: var(--sp-5);
  padding: var(--sp-5);
  background: var(--primary-soft);
  border: 1px solid var(--primary-line);
  border-radius: var(--radius-card);
  scroll-margin-top: var(--sp-4);
}

.spot__row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.spot__body {
  min-width: 0;
}

.spot__labels {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.spot__title {
  margin-top: var(--sp-2);
  font-size: 20px;
  line-height: 27px;
  font-weight: 800;
  overflow-wrap: break-word;
  overflow-wrap: anywhere;
}

.spot__desc {
  margin-top: var(--sp-1);
  color: var(--muted);
  font-size: 15px;
  line-height: 22px;
}

.spot__btn {
  margin-top: 14px;
}

/* ---------- trays (pastel icon tiles) ---------- */
.tray {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  background: var(--sky);
  border-radius: 16px;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
}

.tray--sky {
  background: var(--sky);
}

.tray--mint {
  background: var(--mint);
}

.tray--peach {
  background: var(--peach);
}

.tray--lemon {
  background: var(--lemon);
}

.tray--lilac {
  background: var(--lilac);
}

.tray img {
  width: 64px;
  height: 64px;
  border-radius: 20%;
}

/* Missing or broken icon: readable initials on the same tray; title and store link still work. */
.tray--fallback::before {
  content: attr(data-initials);
  font-size: 24px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.spot .tray {
  width: 88px;
  height: 88px;
  border-radius: 18px;
}

.spot .tray img {
  width: 72px;
  height: 72px;
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.badge--spot {
  background: var(--surface);
  color: var(--primary);
}

.badge--selected {
  background: var(--primary);
  color: var(--on-primary);
}

.badge--new {
  background: var(--mint);
  color: var(--success);
}

.card .badge {
  min-height: 20px;
  padding: 1px 8px;
}

/* On a white card the pill needs the lilac tint to read as a pill (indigo on lilac: 5.5:1). */
.card .badge--spot {
  background: var(--primary-soft);
}

.card__labels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

/* ---------- catalogue section ---------- */
.games {
  padding-top: 28px;
  scroll-margin-top: var(--sp-4);
}

.sec__title {
  font-weight: 800;
}

.sec__eyebrow {
  display: block;
  font-size: 24px;
  line-height: 32px;
}

.sec__lead {
  display: none;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.search {
  width: 100%;
  max-width: 360px;
  margin-top: var(--sp-2);
}

.search__field {
  position: relative;
}

.search__input {
  width: 100%;
  min-height: 44px;
  padding: 10px 48px 10px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  font: inherit;
  font-size: 16px;
  line-height: 24px;
  -webkit-appearance: none;
  appearance: none;
}

.search__input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search__input:focus {
  border-color: var(--primary);
}

.search__clear {
  position: absolute;
  top: 50%;
  right: 4px;
  width: 36px;
  height: 36px;
  transform: translateY(-50%);
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.search__clear:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Category pills: one scrollable row on phones (edge fade, page never overflows), wrapping row from 640 px. */
.filter-wrap {
  position: relative;
  margin: 0 calc(-1 * var(--gutter));
}

.filter {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) calc(var(--gutter) + 40px) var(--sp-2) var(--gutter);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter::-webkit-scrollbar {
  display: none;
}

.filter-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  pointer-events: none;
  background: linear-gradient(90deg, rgb(244 250 255 / 0) 0%, var(--page) 100%);
}

.status {
  margin-top: var(--sp-2);
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

.status:empty {
  display: none;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

/* ---------- game card: compact horizontal row (mobile and /links) ---------- */
.card {
  position: relative;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: start;
  min-width: 0;
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  scroll-margin-top: var(--sp-6);
}

.card__body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.card__title {
  font-size: 16px;
  line-height: 22px;
  font-weight: 800;
  overflow-wrap: break-word;
  overflow-wrap: anywhere;
}

.card__meta {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}

.card__meta svg {
  flex: 0 0 auto;
}

.card__btn {
  margin-top: var(--sp-2);
  min-width: 132px;
  max-width: 100%;
}

.card--pinned {
  border-color: var(--primary-line);
}

/* ?game=<slug>: the selected card (or spotlight) gets a visible label plus a 3 px indigo outline. */
.is-selected,
.is-selected:focus,
.is-selected:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (hover: hover) {
  .card {
    transition: transform 160ms ease-out, box-shadow 160ms ease-out;
  }

  .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-card-hover);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .card,
  .btn,
  .pill {
    transition: none;
  }

  .card:hover {
    transform: none;
  }
}

/* ---------- states ---------- */
.state {
  margin-top: var(--sp-4);
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-align: center;
}

.state p {
  color: var(--muted);
}

.state .btn {
  margin-top: var(--sp-3);
}

/* ---------- studio section ---------- */
.about {
  margin-top: var(--sp-10);
  scroll-margin-top: var(--sp-4);
}

.about__panel {
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.about__title {
  font-size: 22px;
  line-height: 28px;
  font-weight: 800;
}

.about__text {
  margin-top: var(--sp-2);
  max-width: 720px;
  color: var(--muted);
  font-size: 16px;
  line-height: 26px;
}

.about__contact {
  margin-top: var(--sp-3);
  font-size: 16px;
  line-height: 26px;
}

.about__contact a,
.prose a:not(.btn),
.state a:not(.btn) {
  color: var(--primary);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.about__contact a:hover,
.prose a:not(.btn):hover {
  color: var(--primary-hover);
}

/* ---------- footer ---------- */
.ftr {
  margin-top: var(--sp-10);
  padding-top: var(--sp-6);
  padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
  background: var(--sky);
  border-top: 1px solid var(--border);
}

.ftr__in {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.ftr__nav {
  display: flex;
  flex-direction: column;
}

.ftr__nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
  text-decoration: none;
}

.ftr__nav a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.ftr__copy {
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

/* ---------- privacy (reading page) and 404 ---------- */
.prose {
  padding-top: var(--sp-5);
}

.prose__panel {
  max-width: 720px;
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.prose h1 {
  font-size: 30px;
  line-height: 36px;
  font-weight: 800;
}

.prose h2 {
  margin-top: var(--sp-6);
  font-size: 20px;
  line-height: 28px;
  font-weight: 800;
}

.prose p {
  margin-top: var(--sp-2);
  font-size: 16px;
  line-height: 27px;
}

.prose .meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
}

.nf {
  padding-top: var(--sp-10);
}

.nf__in {
  max-width: 560px;
}

.nf h1 {
  font-size: 30px;
  line-height: 36px;
  font-weight: 800;
}

.nf p {
  margin-top: var(--sp-2);
  color: var(--muted);
  font-size: 18px;
  line-height: 28px;
}

/* ---------- /links: compact bio view (max 480 px column at every width) ---------- */
.links {
  width: 100%;
  max-width: calc(480px + 2 * var(--gutter));
  margin: 0 auto;
  padding: var(--sp-6) var(--gutter) calc(var(--sp-8) + env(safe-area-inset-bottom));
}

.links__head {
  margin-bottom: var(--sp-4);
}

.links__mark {
  font-size: 21px;
  line-height: 28px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.links__mark a {
  color: var(--text);
  text-decoration: none;
}

.links__mark a:hover {
  color: var(--primary);
}

.links__lead {
  margin-top: var(--sp-1);
  color: var(--muted);
  font-size: 15px;
  line-height: 23px;
}

.links__list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.links__foot {
  display: flex;
  justify-content: center;
  gap: var(--sp-6);
  margin-top: var(--sp-6);
}

.links__foot a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
  text-decoration: none;
}

.links__foot a:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ====================================================================================
   640 px and up: 24 px gutters, two-column catalogue, desktop-style cards, full header nav
   ==================================================================================== */
@media (min-width: 640px) {
  :root {
    --gutter: 24px;
  }

  .nav__more {
    display: inline;
  }

  .nav a.nav__games {
    background: transparent;
    color: var(--text);
    border-radius: 0;
    padding: var(--sp-2) 0;
  }

  .nav a.nav__games:hover {
    color: var(--primary);
  }

  .tools {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-top: var(--sp-4);
  }

  .search {
    margin-top: 0;
  }

  .filter-wrap {
    margin: 0;
  }

  .filter-wrap::after {
    display: none;
  }

  .filter {
    flex-wrap: wrap;
    padding: 0;
    overflow: visible;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-5);
    margin-top: var(--sp-6);
  }

  /* Regular desktop card (§4.4): 104 px tray column + content, actions aligned along the row. */
  .card:not(.card--row) {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: var(--sp-4);
    align-items: stretch;
    min-height: 152px;
    border-radius: 20px;
  }

  .card:not(.card--row) .tray {
    width: 104px;
    height: 104px;
    border-radius: 18px;
  }

  .card:not(.card--row) .tray img {
    width: 88px;
    height: 88px;
  }

  .card:not(.card--row) .tray--fallback::before {
    font-size: 30px;
  }

  .card:not(.card--row) .card__title {
    font-size: 17px;
    line-height: 24px;
  }

  .card:not(.card--row) .card__meta {
    margin-bottom: var(--sp-2);
  }

  .card:not(.card--row) .card__btn {
    margin-top: auto;
  }

  .about__panel {
    padding: var(--sp-8);
  }

  .ftr__in {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
  }

  .ftr__nav {
    flex-direction: row;
    gap: var(--sp-6);
  }

  .prose {
    padding-top: var(--sp-8);
  }

  .prose__panel {
    padding: var(--sp-8);
  }

  .prose h1,
  .nf h1 {
    font-size: 36px;
    line-height: 44px;
  }
}

/* ====================================================================================
   1024 px and up: desktop contract (§4.3) — 80 px header, two-column hero, three-column catalogue
   ==================================================================================== */
@media (min-width: 1024px) {
  :root {
    --gutter: 32px;
  }

  .hdr__in {
    min-height: 80px;
  }

  .mark {
    font-size: 26px;
    line-height: 32px;
  }

  .hero {
    padding-top: var(--sp-8);
  }

  .hero__grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--sp-8);
    align-items: center;
  }

  .hero__label {
    display: block;
    margin-bottom: var(--sp-3);
    color: var(--muted);
    font-size: 12px;
    line-height: 18px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .hero__title {
    font-size: 52px;
    line-height: 56px;
    letter-spacing: -0.02em;
  }

  .hero__title br {
    display: inline;
  }

  .hero__intro {
    margin-top: var(--sp-3);
    font-size: 18px;
    line-height: 28px;
  }

  /* Three small abstract pastel tiles in the empty right side of the text column; never behind text. */
  .hero__tile {
    display: block;
    position: absolute;
    right: 0;
    pointer-events: none;
    border-radius: 14px;
  }

  .hero__tile--1 {
    top: 0;
    right: 16px;
    width: 56px;
    height: 56px;
    background: var(--lemon);
    transform: rotate(14deg);
  }

  .hero__tile--2 {
    top: 112px;
    right: 72px;
    width: 36px;
    height: 36px;
    background: var(--mint);
    border-radius: 50%;
  }

  .hero__tile--3 {
    bottom: 0;
    right: 8px;
    width: 32px;
    height: 32px;
    background: var(--peach);
    transform: rotate(-10deg);
  }

  .spot {
    margin-top: 0;
    padding: var(--sp-6);
  }

  .spot__row {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: var(--sp-4);
  }

  .spot .tray {
    width: 104px;
    height: 104px;
  }

  .spot .tray img {
    width: 88px;
    height: 88px;
  }

  .spot__title {
    font-size: 28px;
    line-height: 36px;
  }

  .spot__desc {
    font-size: 16px;
    line-height: 24px;
  }

  .spot__btn {
    margin-top: var(--sp-4);
  }

  .games {
    padding-top: var(--sp-8);
  }

  .sec__eyebrow {
    margin-bottom: var(--sp-1);
    color: var(--muted);
    font-size: 12px;
    line-height: 18px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .sec__lead {
    display: block;
    font-size: 28px;
    line-height: 36px;
  }

  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .about {
    margin-top: var(--sp-12);
  }

  .about__title {
    font-size: 24px;
    line-height: 32px;
  }

  .ftr {
    margin-top: var(--sp-12);
  }

  .nf {
    padding-top: var(--sp-16);
  }
}
