/* ---------- Tokens ---------- */
:root {
  --bg: #100e14;
  --surface: #19161f;
  --surface-2: #231f2b;
  --line: #2f2938;
  --text: #ece6da;
  --muted: #a39cab;
  --accent: #d6a84e;
  --accent-ink: #1a1408;
  --blood: #b8404f;
  --good: #6fb37a;
  --radius: 18px;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f1e7; --surface: #fffaf2; --surface-2: #eee6d6; --line: #ddd1bd;
    --text: #221d27; --muted: #6b6371; --accent: #8c5b10; --accent-ink: #fffaf2;
    --blood: #9c2f3d; --good: #2f7a3c; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f6f1e7; --surface: #fffaf2; --surface-2: #eee6d6; --line: #ddd1bd;
  --text: #221d27; --muted: #6b6371; --accent: #8c5b10; --accent-ink: #fffaf2;
  --blood: #9c2f3d; --good: #2f7a3c; color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.6 var(--sans); -webkit-text-size-adjust: 100%;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); }
h2 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h3 { font-size: 1.4rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
section { padding: 56px 0; }
.kicker { font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: .8em; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-in { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; color: var(--text); text-decoration: none; }
.menu { display: flex; gap: 4px 18px; flex-wrap: wrap; margin-left: auto; }
.menu a { color: var(--muted); text-decoration: none; font-size: .95rem; padding: 6px 0; }
.menu a:hover, .menu a.on { color: var(--text); }
.theme-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 1.1rem; cursor: pointer;
}
@media (max-width: 640px) {
  .top-in { padding-top: 8px; padding-bottom: 8px; gap: 6px 12px; }
  .menu { order: 3; width: 100%; margin-left: 0; gap: 4px 16px; }
  .theme-btn { margin-left: auto; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 600 1rem var(--sans);
  text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ---------- Hero ---------- */
.hero { padding: 64px 0 40px; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 40em; }
.hero .row { margin-top: 28px; }
.icons-strip { display: flex; gap: 12px; margin-top: 36px; }
.icons-strip img { width: 56px; height: 56px; border-radius: 14px; }

/* ---------- Bento ---------- */
.bento { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  padding: 22px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
a.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile.wide { grid-column: span 2; }
.tile .ic { width: 64px; height: 64px; border-radius: 16px; }
.tile h3 { margin: 4px 0 0; }
.tile p { margin: 0; color: var(--muted); font-size: .95rem; }
.tile .more { margin-top: auto; color: var(--accent); font-size: .9rem; font-weight: 600; }
.tile.accent { background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--surface)); }
@media (max-width: 900px) { .bento { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .bento { grid-template-columns: 1fr; } .tile.wide { grid-column: auto; } }

/* ---------- Game cards ---------- */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.game-card { padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px; color: var(--text); text-decoration: none; }
.game-card:hover { border-color: var(--accent); }
.game-card .from { font-size: .82rem; color: var(--muted); }
.game-card .more { margin-top: auto; color: var(--accent); font-weight: 600; font-size: .9rem; }

/* ---------- Lists ---------- */
.posts { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.posts a.post { display: block; padding: 18px 22px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.posts a.post:hover { border-color: var(--accent); }
.posts .date { font-size: .82rem; color: var(--muted); }
.posts .t { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; line-height: 1.25; margin: 2px 0 4px; }
.posts .s { color: var(--muted); font-size: .95rem; }

.where { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.where a { display: flex; flex-direction: column; padding: 16px 18px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.where a:hover { border-color: var(--accent); }
.where small { color: var(--muted); }

/* ---------- App page ---------- */
.app-head { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; padding: 48px 0 8px; }
.app-head img { width: 112px; height: 112px; border-radius: 26px; }
.app-head h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 .2em; }
.app-head p { margin: 0; color: var(--muted); font-size: 1.1rem; }
.stores { margin: 24px 0 8px; }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 28px 0; }
.shots img { border-radius: 14px; border: 1px solid var(--line); width: 100%; }
.prose { max-width: 44em; }
.prose ul { padding-left: 1.2em; }
.prose li { margin-bottom: .45em; }
.prose figure { margin: 1.6em 0; }
.prose figcaption { color: var(--muted); font-size: .9rem; margin-top: .5em; }
.prose blockquote { margin: 1.2em 0; padding: 4px 0 4px 18px; border-left: 3px solid var(--accent); color: var(--muted); font-style: italic; }
.also { padding: 16px 20px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin: 28px 0; }
.also p { margin: 0 0 .4em; }
.crumbs { padding-top: 28px; font-size: .9rem; }
.crumbs a { color: var(--muted); }
article.prose { padding: 8px 0 40px; }
article .date { color: var(--muted); font-size: .9rem; }

/* ---------- Game pages ---------- */
.game { padding-top: 28px; padding-bottom: 56px; }
.game-bar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin: 14px 0 18px; }
.stat { color: var(--muted); font-size: .95rem; }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  min-height: 40px; min-width: 64px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 600 .9rem var(--sans);
}
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.msg { min-height: 1.6em; font-weight: 600; margin: 6px 0 12px; }
.msg.good { color: var(--good); }
.msg.bad { color: var(--blood); }

/* Pairs */
.board { display: grid; gap: 8px; margin: 0 auto; touch-action: manipulation; }
.card {
  position: relative; aspect-ratio: 9 / 14; border: 0; padding: 0; cursor: pointer;
  border-radius: 10px; background: transparent; perspective: 800px;
}
.card .in { position: absolute; inset: 0; transition: transform .35s; transform-style: preserve-3d; }
.card.open .in, .card.done .in { transform: rotateY(180deg); }
.card .f, .card .b {
  position: absolute; inset: 0; border-radius: 10px; backface-visibility: hidden;
  background-size: cover; background-position: center; border: 1px solid var(--line);
}
.card .f { transform: rotateY(180deg); }
.card.done { cursor: default; }
.card.done .f { box-shadow: 0 0 0 2px var(--accent); opacity: .55; }
@media (prefers-reduced-motion: reduce) { .card .in { transition: none; } }

/* Code */
.code-show {
  font: 600 clamp(2rem, 9vw, 3.6rem)/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .25em; min-height: 1.6em; text-align: center; padding: 18px 8px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); word-break: break-all;
}
.code-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.code-form input {
  flex: 1 1 200px; min-height: 52px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 600 1.4rem ui-monospace, Consolas, monospace; letter-spacing: .2em;
}
.code-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Chain */
.chain { display: grid; gap: 10px; margin: 0 auto; touch-action: manipulation; }
.ctile {
  aspect-ratio: 1; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); font: 700 clamp(1.3rem, 6vw, 2rem) var(--sans); cursor: pointer;
}
.ctile.hidden { color: transparent; }
.ctile.ok { background: color-mix(in srgb, var(--good) 30%, var(--surface)); color: var(--text); }
.ctile.miss { background: color-mix(in srgb, var(--blood) 40%, var(--surface)); color: var(--text); }
.ctile:disabled { cursor: default; }

/* Echo */
.eho-canvas {
  display: block; width: 100%; margin: 0 auto; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.eho-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Crypt */
/* Sklep (crypt packing) */
.sk-stage { position: relative; margin: 0 auto; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.sk-cell {
  position: absolute; box-sizing: border-box; z-index: 0;
  background: color-mix(in srgb, var(--bg) 75%, var(--line));
  box-shadow: inset 0 0 0 1px var(--line);
}
.sk-ghost { position: absolute; display: none; box-sizing: border-box; z-index: 3; pointer-events: none; border-radius: 3px; }
.sk-ghost.good { background: color-mix(in srgb, var(--good) 55%, transparent); box-shadow: inset 0 0 0 2px var(--good); }
.sk-ghost.bad { background: color-mix(in srgb, var(--blood) 55%, transparent); box-shadow: inset 0 0 0 2px var(--blood); }

.sk-piece {
  position: absolute; z-index: 2; cursor: grab; touch-action: none;
  transition: left .14s ease, top .14s ease;
  --tone: color-mix(in srgb, var(--accent) 55%, var(--surface-2));
  --edge: color-mix(in srgb, var(--text) 60%, var(--tone));
}
.sk-piece.sk-drag { z-index: 6; cursor: grabbing; transition: none; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .45)); }
.sk-won .sk-piece { cursor: default; }
.sk-t0 { --tone: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.sk-t1 { --tone: color-mix(in srgb, var(--blood) 50%, var(--surface-2)); }
.sk-t2 { --tone: color-mix(in srgb, var(--good) 40%, var(--surface-2)); }
.sk-t3 { --tone: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.sk-t4 { --tone: color-mix(in srgb, var(--accent) 50%, color-mix(in srgb, var(--blood) 50%, var(--surface-2))); }
.sk-t5 { --tone: color-mix(in srgb, var(--text) 28%, var(--surface-2)); }
.sk-t6 { --tone: color-mix(in srgb, var(--blood) 28%, var(--surface-2)); }
.sk-t7 { --tone: color-mix(in srgb, var(--good) 28%, color-mix(in srgb, var(--accent) 40%, var(--surface-2))); }

.sk-c {
  position: absolute; box-sizing: border-box; background: var(--tone);
  border: 0 solid var(--edge);
}
.sk-c.t { border-top-width: 2px; }
.sk-c.r { border-right-width: 2px; }
.sk-c.b { border-bottom-width: 2px; }
.sk-c.l { border-left-width: 2px; }
/* inner lid outline, like a coffin lid */
.sk-c::after {
  content: ""; position: absolute; inset: 0; box-sizing: border-box; pointer-events: none;
  border: 0 solid color-mix(in srgb, var(--edge) 70%, transparent);
}
.sk-c.t::after { top: 4px; border-top-width: 1px; }
.sk-c.r::after { right: 4px; border-right-width: 1px; }
.sk-c.b::after { bottom: 4px; border-bottom-width: 1px; }
.sk-c.l::after { left: 4px; border-left-width: 1px; }

.sk-shake { animation: sk-shake .3s; }
@keyframes sk-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.btn[aria-pressed="true"]#sk-daily { border-color: var(--accent); color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  .sk-piece { transition: none; }
  .sk-shake { animation: none; outline: 2px solid var(--blood); }
}

/* ---------- Footer ---------- */
.foot { border-top: 1px solid var(--line); padding: 32px 0 40px; margin-top: 24px; }
.foot-in { display: flex; flex-wrap: wrap; gap: 16px 48px; justify-content: space-between; }
.foot p { margin: .3em 0; font-size: .95rem; }
