:root {
  --bg: #0c0c0e;
  --bg-alt: #131316;
  --text: #f2f0ea;
  --text-dim: #9a978f;
  --accent: #ffcc33;
  --ua-blue: #0057b7;
  --ua-yellow: #ffd700;
  --tile-border: #232226;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', 'Helvetica Neue', Arial, sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(20px, 5vw, 56px);
}

.logo {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.logo-link {
  color: inherit;
  text-decoration: none;
}

.lang-toggle {
  position: relative;
  display: flex;
  align-items: center;
  width: 92px;
  height: 36px;
  padding: 3px;
  background: linear-gradient(90deg, var(--ua-blue) 50%, var(--ua-yellow) 50%);
  border: 1px solid var(--tile-border);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}

.lang-option {
  flex: 1;
  z-index: 1;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  transition: color 0.25s ease;
  pointer-events: none;
}

.lang-option[data-value="en"] { color: #ffffff; }
.lang-option[data-value="uk"] { color: #1a1a1a; }

.lang-toggle[data-lang="en"] .lang-option[data-value="en"],
.lang-toggle[data-lang="uk"] .lang-option[data-value="uk"] {
  color: #0c0c0e;
}

.lang-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: #ffffff;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.25s ease;
}

.lang-toggle[data-lang="uk"] .lang-thumb {
  transform: translateX(100%);
}

/* ---------- main / tagline ---------- */

main {
  flex: 1;
  padding: 0 clamp(20px, 5vw, 56px) 28px;
}

.tagline {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: clamp(14px, 1.6vw, 17px);
}

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  /* On the homepage (6 cols x 4 rows, square tiles), cap the grid's width
     based on viewport height so 4 rows of tiles plus the header/tagline/
     footer chrome fit without scrolling on shorter screens — width is the
     free variable here since tiles are square (aspect-ratio 1/1), so
     capping width also caps the height the grid takes up. Falls back to
     full width on tall/narrow viewports where that's not the constraint. */
  max-width: min(100%, calc(150vh - 340px));
  margin: 0 auto;
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(3, 1fr); max-width: 100%; }
}

/* clickable tiles render as <a> instead of <div> — reset link styling and
   make sure it still behaves as a normal block grid item */
a.tile {
  display: block;
  color: inherit;
  text-decoration: none;
}

/* smaller version of the grid used at the top of tile-N.html pages, so
   people can browse to other tiles without leaving the detail page.
   Deliberately kept at 6 columns (same as the main homepage grid, not its
   own 8/4 column count) — tiles 9/10/15/16 are laid out as a 2x2 block
   that only lines back up into one image at exactly 6 columns, so this
   mini strip needs to match the homepage's column count or the montage
   falls apart when browsing from a tile-N.html page. Below 1100px the
   homepage grid itself drops columns (and the montage is no longer
   aligned there either), so there's nothing to stay in sync with — this
   strip instead keeps 6 columns and a small max-width all the way down,
   so it stays a compact nav strip instead of ballooning into oversized
   tiles that push the actual page content below the fold. */
.grid--mini {
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-width: 420px;
  margin: 0 auto 28px;
}

@media (max-width: 480px) {
  .grid--mini { grid-template-columns: repeat(4, 1fr); max-width: 280px; }
}

/* Mini-grid tiles are far too small (~90px) for overlay text or fallback
   captions to stay legible, so all custom text overlays (front and back —
   e.g. the "Coming soon" placeholders) and the fallback caption are hidden
   in this strip; full text still shows normally on the homepage grid and
   in the profile section. */
.grid--mini .tile-overlay,
.grid--mini .text-overlay .tile-caption {
  display: none;
}

@media (max-width: 620px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* ---------- tile ---------- */

.tile {
  aspect-ratio: 1 / 1;
  perspective: 1000px;
}

.tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
}

.tile-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: 12px;
}

/* Each face gets its own explicit resting/flipped angle rather than
   relying on a rotated parent + a locally-rotated child cancelling out.
   That nested-rotation composition is the "textbook" flip-card recipe, but
   some browser/GPU combos mis-render the settled 360deg state (the back
   face only flashes into view mid-transition, never staying visible) —
   almost certainly a floating point / compositing quirk. Rotating each
   face directly to an explicit target avoids relying on that cancellation
   entirely and is more broadly reliable. */
.tile-front {
  transform: rotateY(0deg);
  background:
    linear-gradient(150deg, rgba(0,0,0,0.05), rgba(0,0,0,0.35)),
    linear-gradient(135deg, hsl(var(--h1), 62%, 40%), hsl(var(--h2), 62%, 22%));
}

.tile-inner.flipped .tile-front {
  transform: rotateY(180deg);
}

/* <video> elements notoriously ignore backface-visibility:hidden in several
   browsers, so the front video can bleed through (mirrored) over the back
   face. Force-hide it explicitly whenever the card is flipped, as a
   reliable fallback that doesn't depend on that browser behavior. */
.tile-inner.flipped .tile-front video.tile-photo {
  visibility: hidden;
}

.tile-back {
  transform: rotateY(180deg);
}

.tile-inner.flipped .tile-back {
  transform: rotateY(360deg);
}

.tile-back.photo-back {
  background:
    linear-gradient(150deg, rgba(0,0,0,0.05), rgba(0,0,0,0.35)),
    linear-gradient(135deg, hsl(var(--h3), 62%, 40%), hsl(var(--h4), 62%, 22%));
}

.tile-back.text-back {
  background: var(--bg-alt);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px;
}

/* fallback: front photo dimmed + caption, used when no back photo exists */
.tile-back.text-overlay {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px;
}

.tile-back.text-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.15), rgba(0,0,0,0.78));
  z-index: 1;
}

.tile-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  pointer-events: none;
}

.tile-index {
  position: relative;
  z-index: 2;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.tile-caption {
  position: relative;
  z-index: 2;
  font-size: clamp(12px, 1.4vw, 14px);
  line-height: 1.4;
  color: #ffffff;
}

/* subtle lift on flip */
.tile-inner:hover,
.tile-inner.flipped {
  filter: brightness(1.03);
}

/* ---------- custom text overlays (see TILE_OVERLAYS in script.js) ---------- */

.tile-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  padding: 12px;
  pointer-events: none;
}

.tile-overlay span {
  font-size: clamp(11px, 1.3vw, 13px);
  font-weight: 700;
  line-height: 1.35;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.85), 0 0 14px rgba(0,0,0,0.55);
  max-width: 100%;
}

.tile-overlay.pos-top-left     { align-items: flex-start; justify-content: flex-start; text-align: left; }
.tile-overlay.pos-top-center   { align-items: flex-start; justify-content: center;      text-align: center; }
.tile-overlay.pos-top-right    { align-items: flex-start; justify-content: flex-end;    text-align: right; }
.tile-overlay.pos-center-left  { align-items: center;     justify-content: flex-start;  text-align: left; }
.tile-overlay.pos-center       { align-items: center;     justify-content: center;      text-align: center; }
.tile-overlay.pos-center-right { align-items: center;     justify-content: flex-end;    text-align: right; }
.tile-overlay.pos-bottom-left  { align-items: flex-end;   justify-content: flex-start;  text-align: left; }
.tile-overlay.pos-bottom-center{ align-items: flex-end;   justify-content: center;      text-align: center; }
.tile-overlay.pos-bottom-right { align-items: flex-end;   justify-content: flex-end;    text-align: right; }

/* ---------- tile detail pages (tile-N.html) ---------- */

.detail-main {
  flex: 1;
  padding: 0 clamp(20px, 5vw, 56px) 56px;
}

.back-link {
  display: inline-block;
  margin: 0 0 32px;
  color: var(--text-dim);
  font-size: 14px;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.profile {
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
}

.profile-photo {
  display: block;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  margin: 0 auto 28px;
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
}

.profile-name {
  margin: 0 0 16px;
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 700;
}

.profile-bio {
  margin: 0;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.7;
  text-align: left;
}

/* ---------- media / sources page (e.g. tile-10.html) ---------- */

.media-page {
  max-width: 720px;
  margin: 0 auto;
}

.media-page > h2 {
  margin: 0 0 12px;
  font-size: clamp(24px, 4vw, 32px);
}

.media-intro {
  margin: 0 0 36px;
  color: var(--text-dim);
  line-height: 1.6;
}

.citation {
  padding: 22px 0;
  border-top: 1px solid var(--tile-border);
}

.citation:last-child {
  padding-bottom: 0;
}

.citation h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.citation-meta {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

.citation blockquote {
  margin: 0 0 10px;
  padding-left: 16px;
  border-left: 2px solid var(--ua-yellow);
  color: var(--text);
  line-height: 1.6;
}

.citation-translation {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

.citation-summary {
  margin: 0 0 14px;
  color: var(--text);
  line-height: 1.6;
}

.citation-link {
  display: inline-block;
  color: var(--ua-yellow);
  font-size: 14px;
  text-decoration: none;
}

.citation-link:hover {
  text-decoration: underline;
}

.media-page h3 {
  margin: 32px 0 12px;
  font-size: 18px;
}

.export-list {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.export-list li {
  padding: 10px 0;
  border-top: 1px solid var(--tile-border);
}

.export-list li:last-child {
  border-bottom: 1px solid var(--tile-border);
}

.references-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 20px;
  font-size: 14px;
}

.references-table th,
.references-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--tile-border);
  vertical-align: top;
}

.references-table th {
  color: var(--text-dim);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.references-table td:last-child {
  white-space: nowrap;
}

/* photo + caption block — see the example on tile-4.html */
.photo-block {
  margin: 0 0 28px;
}

.photo-block-img,
.photo-block-placeholder {
  display: block;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  margin: 0 auto;
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
}

.photo-block-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2a2a30, #17171a);
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 16px;
}

/* variant for screenshots that must stay uncropped (e.g. Telegram post
   captures where cropping a fixed 4:3 box would cut off the timestamp) —
   shows the whole image at its own aspect ratio instead of cover-cropping */
.photo-block-img--full {
  aspect-ratio: auto;
  object-fit: contain;
  background: #000;
}

/* further cap for tall portrait document scans (e.g. the decree on
   tile-7.html) — --full alone still stretches to the full 480px column
   width, which makes a tall A4-shaped scan tower over the surrounding
   text; this keeps it readable without dominating the page */
.photo-block-img--doc {
  max-width: 280px;
  background: #fff;
}

.photo-block-caption {
  max-width: 480px;
  margin: 10px auto 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

/* ---------- assessment block (site's own analysis, distinct from citations — see tile-7.html) ---------- */

.assessment {
  margin: 40px 0 0;
  padding: 24px clamp(18px, 4vw, 28px);
  background: var(--bg-alt);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
}

.assessment > h3 {
  margin: 0 0 6px;
  font-size: 19px;
}

.assessment-intro {
  margin: 0 0 24px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

.assessment-point {
  padding: 18px 0;
  border-top: 1px solid var(--tile-border);
}

.assessment-point:first-of-type {
  padding-top: 0;
  border-top: none;
}

.assessment-point h4 {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.assessment-point p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}

.assessment-links {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.assessment-links li {
  margin: 0 0 4px;
}

.assessment-links a {
  color: var(--ua-yellow);
  text-decoration: none;
}

.assessment-links a:hover {
  text-decoration: underline;
}

.assessment-note {
  margin: 20px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--tile-border);
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
  line-height: 1.6;
}

/* ---------- footer ---------- */

.site-footer {
  padding: 10px clamp(20px, 5vw, 56px) 18px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}
