/* shinwar.se — the shell.
   Shared by the index and by every experiment page.
   Experiments are free to be loud; this file stays calm. */

/* ---------- tokens ---------- */

:root {
  --bg:      #fcfcfa;
  --surface: #ffffff;
  --ink:     #1c1b17;
  --muted:   #6e6d64;
  --line:    #e5e3dc;
  --accent:  #9c4221;

  --cat-arcade:  #c2410c;
  --cat-quiz:    #6d28d9;
  --cat-trainer: #0f766e;
  --cat-toy:     #a16207;

  --bar-h: 3rem;
  --wrap:  62rem;

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #131311;
    --surface: #1c1c19;
    --ink:     #eceae4;
    --muted:   #9a978d;
    --line:    #2f2f2a;
    --accent:  #e8a87c;

    --cat-arcade:  #fb923c;
    --cat-quiz:    #a78bfa;
    --cat-trainer: #5eead4;
    --cat-toy:     #fcd34d;
  }
}

/* ---------- reset-ish ---------- */

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

html {
  /* stops pull-to-refresh from nuking an experiment mid-play */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  overscroll-behavior: none;
  /* kills the 300ms tap delay and double-tap-to-zoom */
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a { color: inherit; }

button {
  font: inherit;
  color: inherit;
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- layout ---------- */

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding-inline: max(1.25rem, env(safe-area-inset-left), env(safe-area-inset-right));
}

/* Present to screen readers, invisible on screen. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- index: masthead ---------- */

.masthead {
  padding-block: clamp(3rem, 12vw, 5.5rem) clamp(2rem, 7vw, 3rem);
}

.masthead h1 {
  font-size: clamp(1.5rem, 5vw, 1.9rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.masthead p {
  margin-top: 0.4rem;
  color: var(--muted);
  max-width: 34rem;
  text-wrap: pretty;
}

/* ---------- index: filter chips ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 1.75rem;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.chip:hover { border-color: var(--muted); color: var(--ink); }

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.chip-count {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}

/* ---------- index: card grid ---------- */

.grid {
  display: grid;
  /* min() so a very narrow viewport shrinks the track instead of overflowing it */
  grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr));
  gap: 0.875rem;
  padding-bottom: 4rem;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 8.5rem;
  padding: 1.1rem 1.15rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}

.card:hover {
  border-color: color-mix(in srgb, var(--ink) 35%, var(--line));
  transform: translateY(-2px);
}

.card-title {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-blurb {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  text-wrap: pretty;
}

/* ---------- category tag ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tag-color, var(--muted));
  white-space: nowrap;
}

.tag::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: currentColor;
}

.tag-arcade  { --tag-color: var(--cat-arcade); }
.tag-quiz    { --tag-color: var(--cat-quiz); }
.tag-trainer { --tag-color: var(--cat-trainer); }
.tag-toy     { --tag-color: var(--cat-toy); }

/* ---------- index: empty states ---------- */

.empty {
  grid-column: 1 / -1;
  padding: clamp(2.5rem, 9vw, 4.5rem) 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  max-width: 32rem;
  text-wrap: pretty;
}

.empty strong {
  display: block;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.empty a { color: var(--accent); }

/* ---------- index: footer ---------- */

.footer {
  padding-block: 1.5rem 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------- experiment frame ---------- */

.xbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  height: var(--bar-h);
  padding-inline: max(1rem, env(safe-area-inset-left), env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.xbar-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex: none;
  padding: 0.5rem 0.1rem;
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: none;
}

.xbar-back:hover { color: var(--ink); }

.xbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xbar .tag { flex: none; }

/* Hide the wordmark on narrow phones — the arrow is enough, and games need the room. */
@media (max-width: 26rem) {
  .xbar-back span { display: none; }
  .xbar { gap: 0.7rem; }
}

/* The play area for an experiment. Fills whatever the bar left behind.
   Uses dvh so mobile browser chrome appearing/disappearing doesn't break it. */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  min-height: calc(100dvh - var(--bar-h));
  padding: 1.5rem max(1.25rem, env(safe-area-inset-left)) max(1.5rem, env(safe-area-inset-bottom));
  text-align: center;
}

/* Put this on anything tappable-repeatedly so long-press doesn't select text. */
.no-select {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- generic experiment button ---------- */

.btn {
  min-height: 2.75rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(0.98); }

/* ---------- motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
}
