:root {
  --paper: #f4eee1;
  --paper-deep: #e9e0cd;
  --card: #fffdf7;
  --ink: #332d25;
  --ink-soft: #6f6455;
  --line: rgba(122, 102, 72, 0.16);
  --accent: #7b8b5f;
  --accent-warm: #c98a3c;
  --danger: #b5563f;
  --shadow-soft: 0 18px 40px -26px rgba(84, 62, 34, 0.55);
  --shadow-lift: 0 26px 54px -24px rgba(84, 62, 34, 0.6);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.paper {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(120% 80% at 18% 6%, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 55%),
    radial-gradient(90% 70% at 88% 100%, rgba(176, 148, 106, 0.22), rgba(176, 148, 106, 0) 60%),
    linear-gradient(180deg, #f7f2e7 0%, #f1e9da 55%, #e9dfcb 100%);
}

.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='0.35'/></svg>");
  mix-blend-mode: multiply;
}

.app {
  max-width: 1060px;
  margin: 0 auto;
  padding: 30px 22px 56px;
}

/* Верхняя строка: «Назад» (только на сайте) и языки EN / עברית / RU. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.lang-switch {
  display: inline-flex;
  margin-inline-start: auto;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--line);
}

.lang-switch button {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--ink-soft);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.lang-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: #f8f3e7;
}

.site-back { text-decoration: none; display: inline-block; }
.site-back[hidden] { display: none; }

.head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(28px, 4.4vw, 40px);
  font-weight: 600;
  letter-spacing: 0.012em;
  color: var(--ink);
}

.tagline {
  margin: 6px 0 0;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.head-tools {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--line);
}

.seg {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.seg small {
  display: block;
  font-size: 10.5px;
  opacity: 0.75;
}

.seg.is-active {
  background: var(--ink);
  color: #f8f3e7;
}

.stats {
  display: flex;
  gap: 18px;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 22px;
  margin: 0 0 16px;
}

.statusbar .timer { flex: 1; margin: 0; }

.lives { color: var(--danger); letter-spacing: 0.08em; }

.select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.select-label { letter-spacing: 0.1em; text-transform: uppercase; font-size: 11px; }

.select-wrap select {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  font-size: 17px;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  cursor: pointer;
}

.btn-icon .sound-off { display: none; }
.btn-icon.is-muted .sound-on { display: none; }
.btn-icon.is-muted .sound-off { display: inline; }

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.stat-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stat-value {
  font-family: var(--serif);
  font-size: 21px;
  color: var(--ink);
}

.btn-ghost {
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 17px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.btn-ghost:hover {
  background: #fff;
  border-color: rgba(122, 102, 72, 0.32);
  transform: translateY(-1px);
}

.timer {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 16px;
}

.timer-track {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(140, 118, 84, 0.16);
  overflow: hidden;
}

.timer-fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #8fa173, #b8a45c);
  transition: background 0.4s ease, width 0.1s linear;
}

.timer.is-low .timer-fill {
  background: linear-gradient(90deg, #c98a3c, #d4683f);
}

.timer.is-critical .timer-fill {
  background: linear-gradient(90deg, #c9703f, #b5452f);
}

.timer.is-off .timer-track { visibility: hidden; }
.timer.is-off .timer-time { font-family: var(--sans); font-size: 13px; }

.timer-time {
  min-width: 34px;
  text-align: right;
  font-family: var(--serif);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.timer.is-low .timer-time { color: var(--accent-warm); }
.timer.is-critical .timer-time { color: var(--danger); }

.board {
  display: flex;
  justify-content: center;
  width: 100%;
}

/* Сцена: размер задаёт JS строго в пропорции исходника (Logic.fitStage),
   поэтому картинка, отверстие и деталь используют одни координаты — доли
   ширины и высоты исходника. Никаких object-fit/полей внутри. */
.stage {
  position: relative;
  direction: ltr;     /* координаты детали физические: в RTL ничего не отражается */
  margin: 0;
  width: 300px;
  max-width: 100%;
  aspect-ratio: 3 / 4;
  flex: 0 0 auto;
  border-radius: 18px;
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow-lift), 0 0 0 1px rgba(255, 255, 255, 0.7) inset;
}

.stage img {
  position: absolute;
  display: block;
  max-width: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.stage .scene-img {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transition: opacity 0.3s ease;
}

.stage.is-loading .scene-img,
.stage.is-loading .hole { opacity: 0; }

.stage .hole.is-filled { visibility: hidden; }

.stage .piece { opacity: 0; }
.stage .piece.is-placed { opacity: 1; }

.stage.is-complete {
  box-shadow: var(--shadow-lift), 0 0 0 3px rgba(123, 139, 95, 0.45);
  transition: box-shadow 0.4s ease;
}

.flying {
  position: fixed;
  z-index: 60;
  margin: 0;
  max-width: none;
  max-height: none;
  pointer-events: none;
  transform-origin: 0 0;
  transform: translate(0, 0) scale(1, 1);
  filter: drop-shadow(0 14px 16px rgba(60, 44, 24, 0.42));
  transition-property: transform, filter;
  transition-timing-function: cubic-bezier(0.22, 0.75, 0.2, 1);
}

.flying.is-landing {
  filter: drop-shadow(0 0 0 rgba(60, 44, 24, 0));
}

.options {
  display: grid;
  grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr));
  gap: 14px;
  margin: 22px auto 0;
  max-width: 880px;
}

.options[data-count="3"] { max-width: 520px; }

.option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, opacity 0.25s ease;
}

.option:hover:not(.is-locked) {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
  border-color: rgba(122, 102, 72, 0.3);
}

.option:active:not(.is-locked) {
  transform: translateY(-1px);
}

.option img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 150px;
  pointer-events: none;
}

.option:focus-visible,
.lang-switch button:focus-visible,
.seg:focus-visible,
.btn:focus-visible,
.btn-ghost:focus-visible,
.btn-icon:focus-visible {
  outline: 3px solid rgba(123, 139, 95, 0.6);
  outline-offset: 2px;
}

.option.is-locked {
  cursor: default;
}

.option.is-dim {
  opacity: 0.42;
}

.option:disabled { color: inherit; }

.option.is-correct {
  border-color: rgba(123, 139, 95, 0.75);
  box-shadow: 0 0 0 2px rgba(123, 139, 95, 0.35), var(--shadow-soft);
}

.option.is-wrong {
  border-color: rgba(181, 86, 63, 0.7);
  animation: shake 0.42s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.option .mark {
  position: absolute;
  top: 9px;
  inset-inline-end: 11px;
  font-size: 17px;
  line-height: 1;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.option.is-correct .mark { opacity: 1; transform: scale(1); color: var(--accent); }
.option.is-wrong .mark { opacity: 1; transform: scale(1); color: var(--danger); }

.hint.is-error { color: var(--danger); }

.hint {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13.5px;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(58, 46, 32, 0.32);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fade 0.28s ease;
}

.overlay[hidden] { display: none; }

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.card {
  width: min(420px, 100%);
  padding: 34px 32px 30px;
  text-align: center;
  background: var(--card);
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 34px 70px -30px rgba(48, 34, 18, 0.7);
  animation: rise 0.34s cubic-bezier(0.2, 0.8, 0.25, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.card-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 27px;
  color: #fbf6ea;
  background: var(--accent);
}

.card.is-loss .card-mark { background: var(--danger); }

.card h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
}

.card p {
  margin: 0 0 22px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.btn {
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.03em;
  color: #f8f3e7;
  background: var(--ink);
  border: 0;
  border-radius: 999px;
  padding: 13px 30px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.btn-soft {
  color: var(--ink);
  background: var(--paper-deep);
}

.btn-soft:hover { background: #e2d7c0; }

.btn:hover {
  background: #443c31;
  transform: translateY(-1px);
}

.toast {
  position: fixed;
  left: 50%;
  top: 26px;
  z-index: 50;
  transform: translateX(-50%);
  padding: 11px 22px;
  border-radius: 999px;
  background: rgba(51, 45, 37, 0.94);
  color: #f7f2e6;
  font-size: 14px;
  letter-spacing: 0.04em;
  box-shadow: 0 16px 34px -18px rgba(40, 28, 14, 0.8);
  animation: drop 0.32s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.toast[hidden] { display: none; }

@keyframes drop {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  .app { padding: 20px 14px 40px; }
  .head { align-items: flex-start; }
  .head-tools { width: 100%; justify-content: space-between; gap: 12px; }
  .options { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
  .option { min-height: 0; padding: 8px; }
  .stage { border-radius: 14px; }
  .topbar { margin-bottom: 8px; }
  .brand h1 { font-size: 26px; }
  .tagline { margin-top: 2px; font-size: 13px; }
  .head { gap: 10px; margin-bottom: 12px; }
  /* на телефоне подсказка «Верно!» снизу, чтобы не закрывать верхние кнопки */
  .toast { top: auto; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
  .statusbar { gap: 14px; }
  .card { padding: 28px 22px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .option, .option.is-wrong { animation: none; transition: none; }
}

@media (max-width: 420px) {
  .stats { gap: 12px; }
  .statusbar { flex-wrap: wrap; }
  .statusbar .timer { flex-basis: 100%; }
  .seg { padding: 7px 11px; font-size: 12px; }
}
