:root {
  color-scheme: light;
  --bg: #f5f0e8;
  --bg-elevated: #fbf7f1;
  --surface: #f8f3ec;
  --text: #141414;
  --muted: rgba(20, 20, 20, 0.64);
  --line: rgba(20, 20, 20, 0.08);
  --line-strong: rgba(20, 20, 20, 0.16);
  --orbit-line: rgba(70, 63, 52, 0.055);
  --button-bg: #141414;
  --button-text: #f5f0e8;
  --shadow: 0 22px 60px rgba(20, 20, 20, 0.08);
  --card-width: clamp(18.75rem, 32vw, 31.25rem);
  --frame-width: min(calc(100vw - 2.5rem), 86rem);
  --grid-columns: 6;
  --grid-row: clamp(3.25rem, 7vh, 4.5rem);
  --transition: 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --bg-elevated: #171715;
  --surface: #1b1b19;
  --text: #f5f0e8;
  --muted: rgba(245, 240, 232, 0.7);
  --line: rgba(245, 240, 232, 0.08);
  --line-strong: rgba(245, 240, 232, 0.16);
  --orbit-line: rgba(245, 240, 232, 0.055);
  --button-bg: #f5f0e8;
  --button-text: #141414;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", "Helvetica Neue", Arial, sans-serif;
  transition:
    background-color var(--transition),
    color var(--transition);
}

button,
input,
textarea,
select {
  font: inherit;
}

.site-shell {
  position: relative;
  min-height: 100vh;
  overflow: clip;
  isolation: isolate;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.22), transparent 28%),
    var(--bg);
}

html[data-theme="dark"] .site-shell {
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.045), transparent 28%),
    var(--bg);
}

.page-grid {
  position: absolute;
  inset-block: 0;
  left: 50%;
  width: var(--frame-width);
  transform: translateX(-50%);
  border-inline: 1px solid var(--line);
  background-image:
    linear-gradient(to right, transparent calc(100% - 1px), var(--line) calc(100% - 1px)),
    linear-gradient(to bottom, transparent calc(100% - 1px), var(--line) calc(100% - 1px)),
    linear-gradient(to bottom right, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom left, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    radial-gradient(circle at 50% 48%, transparent 0 20rem, var(--orbit-line) 20rem 20.08rem, transparent 20.08rem),
    radial-gradient(circle at 50% 48%, transparent 0 30rem, var(--orbit-line) 30rem 30.08rem, transparent 30.08rem),
    linear-gradient(to right, transparent calc(50% - 0.5px), var(--line-strong) calc(50% - 0.5px), var(--line-strong) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px));
  background-size:
    calc(100% / var(--grid-columns)) 100%,
    100% var(--grid-row),
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%,
    100% 100%;
  background-repeat:
    repeat-x,
    repeat-y,
    no-repeat,
    no-repeat,
    no-repeat,
    no-repeat,
    no-repeat,
    no-repeat;
  pointer-events: none;
  opacity: 0.72;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  width: var(--frame-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
  column-gap: 0;
  padding: 1.15rem clamp(1.1rem, 2.4vw, 2.5rem) 0.75rem;
}

.brand-block {
  grid-column: 1 / span 2;
}

.brand-block h1,
.brand-block .eyebrow {
  margin: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.brand-block h1 {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(1.85rem, 4vw, 3.4rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 0.96;
}

.header-actions {
  grid-column: 5 / 7;
  justify-self: end;
  align-self: end;
}

.language-toggle,
.theme-toggle {
  justify-self: end;
  align-self: end;
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.08);
  transition:
    border-color var(--transition),
    background-color var(--transition),
    color var(--transition),
    transform var(--transition);
}

.language-toggle {
  grid-column: 5;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.theme-toggle {
  grid-column: 6;
}

.language-toggle:hover,
.language-toggle:focus-visible,
.theme-toggle:hover,
.theme-toggle:focus-visible,
[data-dive]:hover,
[data-dive]:focus-visible,
.draw-button:hover,
.draw-button:focus-visible {
  transform: translateY(-1px);
}

.language-toggle:focus-visible,
.theme-toggle:focus-visible,
[data-dive]:focus-visible,
.draw-button:focus-visible {
  outline: 1px solid var(--line-strong);
  outline-offset: 3px;
}

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

.theme-toggle__icon {
  width: 1rem;
  height: 1rem;
  display: block;
}

.main-layout {
  position: relative;
  z-index: 1;
  display: grid;
  width: var(--frame-width);
  margin: 0 auto;
  min-height: calc(100vh - 4.9rem);
  align-content: start;
  padding: clamp(0.8rem, 2vw, 1.6rem);
  padding-top: 0.15rem;
  padding-bottom: 1rem;
}

.card-stage {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  justify-items: stretch;
  gap: 1.35rem 0;
}

.deck-stack {
  grid-column: 2 / 6;
  position: relative;
  width: 100%;
  display: grid;
  justify-items: center;
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.deck-stack.is-animating .deck-stack__side--left {
  transform: translateX(0.5rem) rotate(-7deg);
}

.deck-stack.is-animating .deck-stack__side--right {
  transform: translateX(-0.5rem) rotate(7deg);
}

.deck-stack__side {
  position: relative;
  width: var(--card-width);
  height: 100%;
  display: block;
  pointer-events: none;
  inset: 0;
  margin: auto;
  position: absolute;
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.stack-card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(127, 127, 127, 0.04), transparent),
    var(--surface);
  box-shadow: 0 10px 24px rgba(20, 20, 20, 0.04);
  overflow: hidden;
  opacity: 1;
}

.stack-card--back::before {
  content: "";
  position: absolute;
  inset: 0.75rem;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at center, transparent 0 40%, var(--orbit-line) 40.3% 40.8%, transparent 41%),
    linear-gradient(to right, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.stack-card--preview {
  background: var(--bg-elevated);
}

.deck-stack__side--left .stack-card--back {
  transform: translateX(-12%) rotate(-4deg);
}

.deck-stack__side--left .stack-card--preview {
  transform: translateX(-9%) rotate(-2.8deg);
}

.deck-stack__side--right .stack-card--preview {
  transform: translateX(9%) rotate(2.8deg);
}

.deck-stack__side--right .stack-card--back {
  transform: translateX(12%) rotate(4deg);
}

.stack-card__visual {
  display: none;
}

.deck-card {
  position: relative;
  z-index: 2;
  width: var(--card-width);
  max-height: calc(100vh - 11.25rem);
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: clamp(0.5rem, 0.9vw, 0.75rem);
  padding: clamp(0.72rem, 1.4vw, 0.98rem);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition:
    background-color var(--transition),
    border-color var(--transition),
    transform var(--transition),
    opacity 220ms ease;
}

.deck-card.is-changing {
  opacity: 0;
  transform: translateY(6px) scale(0.988);
}

.deck-card__id {
  justify-self: center;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(0.875rem, 1.4vw, 1.125rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1;
  color: var(--text);
}

.deck-card__visual-frame {
  display: grid;
  place-items: center;
  width: 100%;
  padding: 0;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
}

.deck-card__visual {
  display: block;
  position: relative;
  width: 92%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  box-sizing: border-box;
  background: transparent;
  outline: none;
  border: 4px solid var(--button-bg);
  transform: translateZ(0);
  line-height: 0;
  overflow: hidden;
}

.deck-card__visual::before {
  display: none;
}

.deck-card__visual::after {
  display: none;
}

.deck-card__visual.has-image::before {
  display: none;
}

.deck-card__visual.has-image::after {
  display: none;
}

.deck-card__image {
  display: block;
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
  object-fit: contain;
  object-position: center;
  visibility: visible;
  padding: 0;
  opacity: 1;
}

.deck-card__visual.has-image .deck-card__image {
  opacity: 1;
}

.deck-card__body {
  display: grid;
  gap: clamp(0.85rem, 1.35vw, 1.15rem);
  align-content: center;
  justify-items: center;
  text-align: center;
  min-height: clamp(5.75rem, 11vh, 7rem);
}

.deck-card__title,
.deck-card__prompt {
  margin: 0;
}

.deck-card__title {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(1.625rem, 2.4vw, 2.5rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.03em;
  margin-bottom: 0.1rem;
  max-width: 12ch;
  white-space: nowrap;
}

html.lang-ru [data-card-title] {
  font-family: "Lora", serif;
  font-size: clamp(1.125rem, 1.75vw, 1.75rem);
  letter-spacing: 0;
}

.deck-card__prompt {
  width: 100%;
  max-width: 100%;
  color: var(--muted);
  font-size: clamp(0.8125rem, 1.05vw, 0.875rem);
  font-weight: 400;
  line-height: 1.2;
  opacity: 0.9;
}

.controls {
  grid-column: 3 / 5;
  display: grid;
  justify-items: center;
  gap: 0.85rem;
  padding-top: 0.7rem;
}

.draw-button {
  min-width: min(100%, 13.5rem);
  padding: 0.85rem 1.35rem;
  border: 1px solid var(--button-bg);
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  transition:
    transform var(--transition),
    background-color var(--transition),
    color var(--transition),
    border-color var(--transition);
}

[data-dive] {
  min-width: min(100%, 13.5rem);
  padding: calc(0.85rem - 0.5px) 1.35rem;
  border: 1.5px solid currentColor;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  transition:
    border-color var(--transition),
    background-color var(--transition),
    color var(--transition),
    transform var(--transition);
}

[data-dive-overlay] {
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(0, 0, 0, 0.5);
}

[data-dive-overlay][hidden] { display: none; }

[data-dive-modal] {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 200;
  width: min(480px, calc(100vw - 3rem));
  max-height: 80vh;
  overflow-y: auto;
  padding: 4rem 2rem 2rem;
  transform: translate(-50%, -50%);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

[data-dive-modal][hidden] { display: none; }

[data-dive-header] {
  position: absolute;
  z-index: 1;
  top: 1rem;
  right: 1rem;
  text-align: right;
}

[data-dive-close] {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.5;
  padding: 0;
}

[data-dive-close]:hover { opacity: 1; }

[data-dive-text] {
  color: var(--muted);
  font-family: "Manrope", "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.45;
  margin-bottom: 2.75rem;
}

[data-dive-interact] {
  position: relative;
  padding-top: 0;
  opacity: 0.6;
}

[data-dive-interact]:focus-within { opacity: 1; }

[data-dive-question] {
  flex: 0 0 100%;
  color: var(--text);
  margin: 0 2.5rem 1rem 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(1.5rem, 2.3vw, 2rem);
  font-weight: 400;
  line-height: 1.08;
}

html:not(.lang-ru) [data-dive-question] {
  font-size: clamp(1.8rem, 2.7vw, 2.4rem);
}

[data-dive-input] {
  width: 100%;
  min-height: 1.5rem;
  max-height: 8rem;
  resize: none;
  overflow: hidden;
  background: transparent;
  border: none;
  border-bottom: 1px solid currentColor;
  color: inherit;
  padding: 4px 48px 4px 0;
  font-size: 1rem;
  line-height: 1.45;
  font-family: inherit;
  outline: none;
  display: block;
}

[data-dive-send] {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  opacity: 0.5;
}
[data-dive-send]:hover { opacity: 1; }

[data-dive-response] {
  font-size: 0.75rem;
  font-style: italic;
  opacity: 0.5;
  margin-top: 0.5rem;
  line-height: 1.5;
  min-height: 1rem;
}

.site-footer {
  position: relative;
  z-index: 1;
  width: var(--frame-width);
  margin: 0 auto;
  padding: 0 clamp(1.1rem, 2.4vw, 2.5rem) 1.25rem;
}

.site-footer__links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  min-height: var(--grid-row);
}

.site-footer__link {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  color: var(--muted);
  text-decoration: none;
  transition:
    color var(--transition),
    opacity var(--transition),
    transform var(--transition);
}

.site-footer__link:hover,
.site-footer__link:focus-visible {
  color: var(--text);
  opacity: 0.92;
  transform: translateY(-1px);
}

.site-footer__link:focus-visible {
  outline: 1px solid var(--line-strong);
  outline-offset: 3px;
}

.site-footer__link iconify-icon {
  width: 24px;
  height: 24px;
  display: block;
  color: currentColor;
}

@media (min-width: 768px) {
  .site-footer {
    position: fixed;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    margin: 0;
    padding: 0;
  }

  .site-footer__links {
    flex-direction: column;
    gap: 16px;
    min-height: 0;
  }

}

@media (max-width: 700px) {
  .page-grid {
    width: min(calc(100vw - 1.6rem), 86rem);
    background-image:
      linear-gradient(to right, transparent calc(100% - 1px), var(--line) calc(100% - 1px)),
      linear-gradient(to bottom, transparent calc(100% - 1px), var(--line) calc(100% - 1px)),
      linear-gradient(to bottom right, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
      linear-gradient(to bottom left, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
      radial-gradient(circle at 50% 44%, transparent 0 11rem, var(--orbit-line) 11rem 11.06rem, transparent 11.06rem),
      linear-gradient(to right, transparent calc(50% - 0.5px), var(--line-strong) calc(50% - 0.5px), var(--line-strong) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
      linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px));
    background-size:
      25% 100%,
      100% 3.65rem,
      100% 100%,
      100% 100%,
      100% 100%,
      100% 100%;
  }

  .site-header {
    width: min(calc(100vw - 1.6rem), 86rem);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: center;
    padding-top: 1rem;
  }

  .brand-block {
    grid-column: 1 / span 2;
  }

  .header-actions {
    grid-column: 3 / 5;
    justify-self: end;
  }

  .language-toggle {
    width: 2.7rem;
    height: 2.7rem;
  }

  .theme-toggle {
    width: 2.7rem;
    height: 2.7rem;
  }

  .main-layout {
    width: min(calc(100vw - 1.6rem), 86rem);
    min-height: auto;
    padding-top: 4rem;
  }

  .card-stage {
    width: 100%;
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .deck-stack {
    grid-column: 1;
    width: 100%;
  }

  .deck-stack__side {
    display: block;
  }

  .deck-card {
    width: min(100%, 28rem);
    max-height: none;
  }

  .controls {
    grid-column: 1;
    width: min(100%, 28rem);
    justify-self: center;
  }

  .draw-button,
  [data-dive] {
    width: 100%;
  }

  [data-dive-modal] {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: calc(100dvh - 4rem);
    transform: none;
    border-radius: 16px 16px 0 0;
    padding: 1.25rem 1.25rem 2.5rem;
    overflow-y: auto;
  }

  [data-dive-modal]::before {
    content: "";
    display: block;
    width: 2.5rem;
    height: 3px;
    background: var(--line-strong);
    border-radius: 2px;
    margin: 0 auto 1.25rem;
  }

  [data-dive-close] {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  [data-dive-input] {
    font-size: 1rem;
  }

  [data-dive-send] {
    width: 32px;
    height: 32px;
  }

  .site-footer {
    width: min(calc(100vw - 1.6rem), 86rem);
    padding-bottom: 1rem;
  }

}

@media (max-width: 600px) {
  html.lang-ru [data-card-title] {
    font-size: clamp(1rem, 5.5vw, 1.5rem);
  }
}

@media (max-height: 840px) {
  .site-header {
    padding-bottom: 0.55rem;
  }

  .main-layout {
    padding-top: 0.2rem;
    padding-bottom: 0.8rem;
  }

  .deck-card {
    gap: 0.62rem;
    padding: 0.78rem;
    max-height: calc(100vh - 10.1rem);
  }

  .deck-card__body {
    min-height: 5.1rem;
  }
}

@media (max-width: 700px) and (max-height: 840px) {
  .main-layout {
    padding-top: 2.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
}
