:root {
  --bg: #f4efe6;
  --card: #ffffff;
  --ink: #1f1a17;
  --muted: #6f655c;
  --line: #e6ddd2;
  --orange: #e25b12;
  --orange-deep: #b8430c;
  --orange-soft: #fff1e6;
  --shadow: 0 12px 32px rgba(90, 52, 20, 0.08);
  --radius: 22px;
  color-scheme: light;
  font-size: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 50% -12%, #fff8f0 0%, transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Nunito", "Helvetica Neue", sans-serif;
}

html[dir="rtl"] body {
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Geeza Pro", sans-serif;
}

body {
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}

button, select { font: inherit; color: inherit; }

button { cursor: pointer; }

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

.app {
  width: min(1040px, 100%);
  margin: 0 auto;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px 8px;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--orange-deep);
  font-size: 0.95rem;
}

.lang {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 44px;
}

h1 {
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1.05;
  margin: 8px 0 6px;
}

.tag {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 1.05rem;
}

.layout {
  display: grid;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.mosaic-wrap { position: relative; }

canvas.mosaic {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 16px;
  background: #f7f1e8;
  image-rendering: pixelated;
  touch-action: manipulation;
}

.piece-label {
  margin: 10px 0 0;
  font-weight: 800;
  color: var(--orange-deep);
  font-size: 1.25rem;
}

.stats {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-top: 12px;
}

.pct { font-size: 1.35rem; font-weight: 800; }

.players { color: var(--muted); }

.bar {
  height: 12px;
  background: #f3ebe3;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--orange);
  width: 0%;
}

.primary, .ghost {
  border: 0;
  border-radius: 999px;
  min-height: 56px;
  padding: 14px 18px;
  font-weight: 800;
  width: 100%;
}

.primary {
  background: var(--orange);
  color: white;
  box-shadow: 0 8px 20px rgba(226, 91, 18, 0.28);
}

.ghost {
  background: var(--orange-soft);
  color: var(--orange-deep);
}

.row-actions { display: grid; gap: 8px; margin-top: 12px; }

.country {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 1.05rem;
}

.country:last-child { border-bottom: 0; }

.flag { font-size: 1.3rem; margin-inline-end: 8px; }

.streak {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--orange-soft);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 800;
}

.banner {
  background: var(--orange-soft);
  color: var(--orange-deep);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 700;
}

.note, .help, .countdown { color: var(--muted); }

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  touch-action: manipulation;
}

.tile {
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
}
.tile, .blank {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 0;
  min-height: 72px;
  font-weight: 800;
  font-size: 1.35rem;
  color: #1f1a17;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.blank {
  background: #f6f1ea;
  border: 2px dashed #e0d5c8;
}

.model-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 12px;
}

.model-row canvas {
  width: 96px;
  height: 96px;
  border-radius: 12px;
  image-rendering: pixelated;
  background: #f6f1ea;
}

.inset {
  width: 92px;
  height: 92px;
  border-radius: 14px;
  border: 3px solid var(--orange);
  image-rendering: pixelated;
}

.error {
  background: #fff4f0;
  color: var(--orange-deep);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(244, 239, 230, 0.82);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 5;
}

.modal .card { width: min(520px, 100%); }

#ad-banner { display: none; }
body.show-ads #ad-banner {
  display: block;
  min-height: 50px;
  margin-top: 12px;
}

.loading { padding: 48px 0; font-size: 1.2rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 880px) {
  .layout { grid-template-columns: 1.25fr 0.75fr; align-items: start; }
  .side { display: grid; gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
