/* 3x3 Games portal. Fonts are self-hosted latin subsets (variable weight). */
@font-face { font-family: "Fredoka"; src: url("fonts/fredoka-latin.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url("fonts/dm-sans-latin.woff2") format("woff2"); font-weight: 100 1000; font-display: swap; }

:root {
  --bg: #f3faf8;
  --card: #ffffff;
  --text: #243c4a;
  --muted: #708894;
  --accent: #158eaa;
  --border: #dcebea;
  --panel: #e9f4ef;
  --panel-border: #d5e7dd;
  --logo-blue: #22aadd;
  --logo-pink: #ef79a0;
  --shadow: 0 3px 0 #deebe7;
  --shadow-hover: 0 8px 18px rgba(36, 60, 74, .12), 0 3px 0 #deebe7;
  --fallback: linear-gradient(135deg, #e3f1f6, #f4e8f0);
  --font-head: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --gap: 12px;
  --section: 32px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--font-body);
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 10; background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow-hover); }
.skip-link:focus { top: 12px; }

.wrap { width: 100%; max-width: 1550px; margin: 0 auto; padding-left: 4%; padding-right: 4%; }

/* ------------------------------------------------------------------ header / logo */
.site-header { background: var(--card); border-bottom: 1px solid var(--border); }
.site-header .wrap { min-height: 72px; display: flex; align-items: center; }
.logo {
  font-family: var(--font-head); font-weight: 500; font-size: 34px; line-height: 1;
  letter-spacing: -0.02em; text-decoration: none; white-space: nowrap; display: inline-block;
}
.logo-a { color: var(--logo-blue); }
.logo-b { color: var(--logo-pink); }
.logo-c { color: var(--text); opacity: .55; font-size: .5em; letter-spacing: 0; margin-left: 1px; }
.logo--small { font-size: 20px; }

main.wrap { padding-top: 32px; padding-bottom: 8px; }

/* ------------------------------------------------------------------ sections */
.section-title {
  font-family: var(--font-head); font-weight: 500; font-size: 24px; line-height: 1.2;
  margin: 0 0 14px; color: var(--text);
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head .section-title { margin: 0; }
.section-link { font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.section-link:hover { text-decoration: underline; }
.count { font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 8px; white-space: nowrap; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }

.top-row { display: grid; grid-template-columns: 1.15fr 1fr; gap: 22px; align-items: start; margin-bottom: var(--section); }
.last-played { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px; padding: 20px; min-width: 0; }
/* No panel around New, but the same insets so headings and card rows line up with Last played. */
.new-games { padding: 21px 0; min-width: 0; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.last-played .empty { margin-top: 12px; }
.last-played .empty[hidden] { display: none; }
.card--placeholder { box-shadow: none; background: transparent; border: 2px dashed var(--panel-border); pointer-events: none; }
.card--placeholder .card-media { background: var(--fallback); opacity: .55; }

.top8, .all-games, .related { margin-bottom: var(--section); }
.grid-top { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: var(--gap); }
.grid-all, .grid-related { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 18px 15px; }

.sort select {
  font: 500 13px var(--font-body); color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 30px 7px 12px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ------------------------------------------------------------------ cards */
.card {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--card); border-radius: 13px; overflow: hidden; box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.card:focus-visible { outline-offset: 2px; border-radius: 13px; }
.card-media { position: relative; display: block; aspect-ratio: 1.46 / 1; background: var(--fallback); overflow: hidden; }
.card--top .card-media { aspect-ratio: 1.12 / 1; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-media.is-missing::after {
  content: ""; position: absolute; inset: 28% 36%; border-radius: 10px; background: rgba(255, 255, 255, .55);
}
.card-title {
  display: block; padding: 11px 12px; font-weight: 700; font-size: 12px; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card--compact .card-title, .card--top .card-title { font-size: 11px; padding: 9px 10px; }
.card-badge {
  position: absolute; top: 8px; left: 8px; padding: 3px 6px; border-radius: 5px;
  font-size: 8px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; line-height: 1.2;
}
.card-badge--new { background: #dff4ec; color: #1d6b55; }
.card-badge--updated { background: #ece6fb; color: #5a4598; }
.card-badge--hot { background: #fdf1c4; color: #80600a; }
.card-rank {
  position: absolute; top: 4px; left: 9px;
  font-family: var(--font-head); font-weight: 600; font-size: 31px; line-height: 1; color: #fff;
  -webkit-text-stroke: 1.5px #243c4a; paint-order: stroke fill;
  text-shadow: 0 2px 0 #243c4a, 0 0 6px rgba(36, 60, 74, .55);
}

/* ------------------------------------------------------------------ game page */
.back-link { display: inline-block; font-size: 13px; font-weight: 700; text-decoration: none; margin-bottom: 8px; }
.back-link:hover { text-decoration: underline; }
.game-layout {
  display: grid; grid-template-columns: 155px minmax(0, 1fr) 155px; gap: 20px;
  grid-template-areas: "left main right"; align-items: start; margin-bottom: var(--section);
}
.game-main { grid-area: main; min-width: 0; }
.game-side { display: flex; flex-direction: column; gap: var(--gap); }
.game-side--left { grid-area: left; }
.game-side--right { grid-area: right; }
/* Side columns start level with the game block (below back link + title). */
.game-side { margin-top: 68px; }
.game-title { font-family: var(--font-head); font-weight: 500; font-size: 28px; line-height: 1.15; margin: 0 0 14px; }
.game-block { background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.game-frame { position: relative; aspect-ratio: 16 / 10; max-height: calc(100vh - 150px); width: 100%; background: #10202a; }
.game-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.game-stage:fullscreen { display: flex; flex-direction: column; width: 100%; height: 100%; background: #10202a; }
.game-stage:-webkit-full-screen { display: flex; flex-direction: column; width: 100%; height: 100%; background: #10202a; }
.game-stage.is-fs {
  position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; background: #10202a;
  height: 100vh; height: 100dvh;
}
.game-stage:fullscreen .game-frame { max-height: none; aspect-ratio: auto; flex: 1; min-height: 0; }
.game-stage:-webkit-full-screen .game-frame { max-height: none; aspect-ratio: auto; flex: 1; min-height: 0; }
.game-stage.is-fs .game-frame { max-height: none; aspect-ratio: auto; flex: 1; min-height: 0; }
html.fs-lock, html.fs-lock body { overflow: hidden; }
.fs-bar {
  display: none; align-items: center; justify-content: space-between; gap: 12px; flex: none;
  padding: 6px 12px; padding-bottom: max(6px, env(safe-area-inset-bottom)); background: #10202a; border-top: 1px solid #24404e;
}
.game-stage:fullscreen .fs-bar, .game-stage.is-fs .fs-bar { display: flex; }
.game-stage:-webkit-full-screen .fs-bar { display: flex; }
.fs-back, .fs-exit {
  font: 700 14px var(--font-body); color: #fff; text-decoration: none; background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .22); border-radius: 9px; padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.fs-back:hover, .fs-exit:hover { background: rgba(255, 255, 255, .2); }
.game-play {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; width: 100%; border: 0; padding: 16px; cursor: pointer; background: rgba(16, 32, 42, .55);
  font: 700 17px var(--font-head); color: #fff; text-align: center;
}
.game-play[hidden] { display: none; }
.game-play-icon {
  width: 72px; height: 72px; border-radius: 50%; background: var(--logo-blue); box-shadow: 0 4px 0 #1787b1;
  position: relative;
}
.game-play-icon::after {
  content: ""; position: absolute; left: 29px; top: 22px;
  border-style: solid; border-width: 14px 0 14px 22px; border-color: transparent transparent transparent #fff;
}
.game-error {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: #fff; text-align: center; padding: 16px;
}
.game-error[hidden] { display: none; }
.game-error p { margin: 0; font-weight: 700; }
.game-error a { color: #9fe3f3; }
.game-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 14px; border-top: 1px solid var(--border); }
.toolbar-name { font-family: var(--font-head); font-weight: 500; font-size: 15px; color: var(--muted); }
.btn-fullscreen {
  font: 700 13px var(--font-body); color: var(--accent); background: transparent;
  border: 1px solid var(--border); border-radius: 9px; padding: 6px 12px; cursor: pointer;
}
.btn-fullscreen:hover { background: var(--bg); }
.btn-fullscreen[hidden] { display: none; }
.game-text {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 18px;
  background: var(--card); border-radius: 16px; padding: 18px 22px; box-shadow: var(--shadow); font-size: 14px;
}
.game-text h2 { font-family: var(--font-head); font-weight: 500; font-size: 18px; margin: 0 0 6px; }
.game-text p { margin: 0 0 8px; }
.game-text ul { margin: 0 0 8px; padding-left: 18px; }

/* ------------------------------------------------------------------ information pages */
.info-title { font-size: 28px; }
.info-layout { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 22px; align-items: start; margin-bottom: var(--section); }
.info-nav { display: flex; flex-direction: column; gap: 4px; }
.info-nav a { display: block; padding: 8px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.info-nav a:hover { background: var(--panel); }
.info-nav a[aria-current="page"] { background: var(--card); box-shadow: var(--shadow); font-weight: 700; color: var(--accent); }
.info-panel { background: var(--card); border-radius: 16px; padding: 24px 28px; box-shadow: var(--shadow); max-width: 820px; min-width: 0; }
.info-panel h2 { font-family: var(--font-head); font-weight: 500; font-size: 22px; margin: 0 0 10px; }
.info-panel h3 { font-family: var(--font-head); font-weight: 500; font-size: 17px; margin: 20px 0 4px; }
.info-panel p, .info-panel ul { margin: 0 0 10px; }
.info-panel ul { padding-left: 20px; }
.draft {
  background: #fff8e1; border: 1px dashed #e2c76a; color: #6b5512; border-radius: 10px;
  padding: 8px 12px; font-size: 13px;
}
.page-404 .empty { margin-bottom: 16px; }

/* ------------------------------------------------------------------ footer */
.site-footer { padding: 28px 0 40px; }
.site-footer .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.site-footer nav a { color: var(--muted); font-size: 12px; text-decoration: none; }
.site-footer nav a:hover { color: var(--text); text-decoration: underline; }
.site-footer .copyright { margin: 0; flex-basis: 100%; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .grid-top { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-all, .grid-related { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  /* Game page: game first, related games below it. */
  .game-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "main main" "left right"; }
  .game-side { margin-top: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  :root { --gap: 10px; --section: 26px; }
  .wrap { padding-left: 5%; padding-right: 5%; }
  .site-header .wrap { min-height: 0; padding-top: 16px; padding-bottom: 16px; }
  .logo { font-size: 30px; }
  main.wrap { padding-top: 22px; }
  .section-title { font-size: 20px; }
  .top-row { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .last-played { padding: 16px; }
  .new-games { padding: 0; }
  .grid-all, .grid-related { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; }
  .card-title { font-size: 11px; padding: 9px 9px; }
  .card--compact .card-title, .card--top .card-title { font-size: 10px; padding: 8px 8px; }
  .card-rank { font-size: 24px; left: 6px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "left" "right"; gap: var(--gap); }
  .game-title { font-size: 22px; }
  .game-frame { max-height: 70vh; }
  .game-text { grid-template-columns: 1fr; gap: 6px; padding: 16px; }
  .info-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .info-nav { flex-direction: row; flex-wrap: wrap; }
  .info-panel { padding: 18px; }
}
@media (max-width: 480px) {
  .count { display: none; }
}
@media (max-width: 380px) {
  .grid-top, .grid-all, .grid-related { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-title { font-size: 12px; }
  .card--top .card-title { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
}
