:root {
  --paper: #fffaf4;
  --cream: rgba(255, 250, 244, 0.9);
  --cream-strong: #fffaf4;
  --ink: #2e2026;
  --muted: #6a575e;
  --berry: #971454;
  --berry-deep: #780a40;
  --berry-dark: #4f072b;
  --blush: #f8d7e3;
  --coral: #e94f1d;
  --button-border: rgba(255, 255, 255, 0.5);
  --button-shadow: 0 14px 34px rgba(79, 7, 43, 0.16);
  --card-shadow: 0 18px 42px rgba(79, 7, 43, 0.16);
  --panel-width: min(1120px, calc(100vw - 36px));
  --font-display: "Alegreya Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-smallcaps: "Alegreya Sans SC", "Alegreya Sans", ui-sans-serif, system-ui, sans-serif;
  --font-text: Alegreya, Georgia, "Times New Roman", serif;
  --radius-panel: 28px;
  --radius-control: 22px;
  --radius-image: 24px;
}

* {
  box-sizing: border-box;
}

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

html {
  background-color: var(--berry);
}

body {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  background-color: transparent;
  color: var(--ink);
  font-family: var(--font-display);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 255, 255, 0.36), transparent 34%),
    radial-gradient(circle at 18% 88%, rgba(255, 221, 170, 0.18), transparent 28%),
    linear-gradient(145deg, var(--blush) 0%, #d995c5 48%, var(--berry) 100%);
  pointer-events: none;
}

button,
a {
  font: inherit;
}

.container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100svh;
  width: 100%;
  padding: clamp(26px, 6vh, 64px) 18px 18px;
}

.page {
  width: var(--panel-width);
  margin: auto 0;
}

.exercise {
  display: grid;
  gap: clamp(22px, 3vw, 34px);
}

.lesson-heading {
  position: relative;
  color: white;
  text-align: center;
  text-shadow: 0 8px 24px rgba(79, 7, 43, 0.2);
}

.lesson-title-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}

.lesson-kicker-row {
  position: relative;
  width: min(100%, 420px);
  margin: 0 auto 14px;
}

.lesson-kicker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 42px;
  margin: 0 auto;
  padding: 10px 22px;
  border: 1px solid var(--button-border);
  border-radius: 9999px;
  background: var(--cream);
  color: var(--berry-deep);
  box-shadow: var(--button-shadow);
  font-size: 20px;
  font-weight: 800;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.lesson-heading h1 {
  width: 100%;
  margin: 0;
  color: white;
  font-size: clamp(42px, 7vw, 66px);
  font-weight: 900;
  line-height: 1.04;
}

.lesson-heading h1 span {
  display: block;
  margin-top: 10px;
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 900;
}

.qr-toggle {
  position: absolute;
  top: 50%;
  left: calc(50% + 78px);
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--button-border);
  border-radius: 50%;
  background: var(--cream);
  color: var(--berry-deep);
  box-shadow: 0 10px 24px rgba(79, 7, 43, 0.12);
  cursor: pointer;
  transition:
    transform 0.22s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}

.qr-toggle::before {
  content: "";
  width: 10px;
  height: 10px;
  border-right: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.22s ease;
}

.qr-toggle:hover {
  background: var(--coral);
  color: white;
  transform: translateY(-50%) scale(1.04);
}

.lesson-heading.qr-open .qr-toggle::before {
  transform: translateY(2px) rotate(225deg);
}

.qr-panel {
  position: absolute;
  top: 58px;
  left: calc(50% + 176px);
  z-index: 5;
  width: min(260px, calc(100vw - 36px));
  opacity: 0;
  transform: translate(-100%, -8px) scale(0.98);
  transform-origin: top right;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.lesson-heading.qr-open .qr-panel {
  opacity: 1;
  transform: translate(-100%, 0) scale(1);
  pointer-events: auto;
}

.qr-card {
  width: 100%;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 20px;
  background: rgba(255, 250, 247, 0.96);
  box-shadow: 0 18px 45px rgba(79, 7, 43, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.qr-card img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto 12px;
  border-radius: 14px;
  opacity: 1;
  mix-blend-mode: normal;
  background: #fffaf7;
  box-shadow:
    0 0 0 1px rgba(151, 20, 84, 0.06),
    0 10px 24px rgba(79, 7, 43, 0.08);
}

.qr-url {
  margin: 0;
  padding: 0 4px 2px;
  color: rgba(106, 87, 94, 0.9);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
  text-align: center;
  text-shadow: none;
  overflow-wrap: anywhere;
}

.qr-url a {
  color: inherit;
  text-decoration: none;
}

.exercise__header,
.preview {
  border: 1px solid rgba(255, 255, 255, 0.44);
  border-radius: var(--radius-panel);
  background: var(--cream);
  box-shadow: var(--button-shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.exercise__header {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 3vw, 28px);
}

.title-pill {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  min-height: 52px;
  padding: 12px 24px;
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--berry) 0%, var(--berry-deep) 100%);
  color: white;
  box-shadow: 0 14px 34px rgba(79, 7, 43, 0.18);
  font-size: clamp(28px, 4vw, 44px);
  font-style: italic;
  font-weight: 900;
  line-height: 1.05;
}

.title-pill__fr {
  display: inline-block;
  font-family: var(--font-smallcaps);
  font-size: 1em;
  font-style: oblique 12deg;
  font-weight: 900;
  letter-spacing: 0.012em;
  transform: skewX(-7deg);
  transform-origin: center;
}

.title-pill span {
  font-size: 0.8em;
  font-style: normal;
  font-weight: 650;
}

.intro {
  max-width: 980px;
  font-family: var(--font-text);
}

.intro p {
  margin: 0;
  color: var(--ink);
  font-size: clamp(22px, 2.6vw, 31px);
  font-weight: 400;
  line-height: 1.55;
}

.intro p + p {
  margin-top: 8px;
  color: var(--muted);
}

.exercise__content {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr);
  gap: clamp(18px, 3vw, 28px);
  align-items: start;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 18px);
}

.card {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: none;
  border-radius: var(--radius-image);
  cursor: pointer;
  box-shadow: var(--card-shadow);
  background-color: #ddd;
  background-image:
    linear-gradient(180deg, rgba(18, 14, 13, 0.08), rgba(18, 14, 13, 0.03)),
    var(--card-image);
  background-repeat: no-repeat;
  background-size: var(--bg-size, cover);
  background-position: var(--bg-pos-x, 50%) var(--bg-pos-y, 50%);
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease,
    border-color 0.22s ease;
}

.card:hover,
.card:focus-visible,
.card.is-active {
  transform: translateY(-4px);
  box-shadow:
    0 0 0 3px rgba(255, 250, 244, 0.82),
    0 22px 52px rgba(79, 7, 43, 0.22);
}

.card:focus-visible {
  outline: 2px solid rgba(255, 221, 170, 0.95);
  outline-offset: 3px;
}

.card__label {
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--button-border);
  border-radius: 50%;
  background: var(--cream-strong);
  color: var(--berry-deep);
  box-shadow: 0 10px 22px rgba(79, 7, 43, 0.14);
  font-size: 18px;
  font-weight: 800;
}

.preview {
  display: grid;
  gap: 16px;
  padding: clamp(14px, 2vw, 18px);
}

.preview__frame {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  min-height: 0;
  border-radius: var(--radius-control);
  background:
    linear-gradient(135deg, rgba(151, 20, 84, 0.12), rgba(255, 221, 170, 0.2)),
    rgba(255, 255, 255, 0.72);
}

.preview__frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.preview__frame img[hidden] {
  display: none;
}

.preview__placeholder {
  max-width: 420px;
  padding: 34px 24px;
  color: var(--muted);
  text-align: center;
}

.preview__placeholder p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.preview__placeholder-title {
  margin-top: 0;
  color: var(--berry-deep);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
}

.preview:not(.is-empty) .preview__placeholder {
  display: none;
}

.preview__copy {
  padding: 0 2px 2px;
}

.preview__eyebrow {
  margin: 0 0 6px;
  color: var(--berry-deep);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.preview__copy h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
  line-height: 1.15;
}

.preview__hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-family: var(--font-text);
  font-size: 17px;
  line-height: 1.55;
}

footer {
  width: min(86vw, 520px);
  margin-top: auto;
  padding-top: clamp(24px, 6vh, 54px);
  color: white;
  text-align: center;
  font-size: 14px;
  text-shadow: 0 8px 24px rgba(79, 7, 43, 0.2);
}

footer hr {
  width: 100%;
  margin: 0 auto 18px;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.54);
}

.footer-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 50px;
  margin: 0 auto 10px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  padding: 0;
  border: 1px solid var(--button-border);
  border-radius: 50%;
  background: var(--cream);
  color: var(--berry-deep);
  box-shadow: var(--button-shadow);
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition:
    transform 0.22s ease,
    background-color 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease,
    border-color 0.22s ease;
}

.icon-button:hover {
  transform: scale(1.06);
  background: var(--coral);
  color: white;
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 18px 42px rgba(79, 7, 43, 0.22);
}

.icon-button:focus-visible {
  outline: 2px solid rgba(255, 221, 170, 0.95);
  outline-offset: 3px;
}

.home-icon {
  width: 19px;
  height: 19px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11.5L12 4l9 7.5'/%3E%3Cpath d='M5.5 10.5V20h13v-9.5'/%3E%3Cpath d='M9.5 20v-6h5v6'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11.5L12 4l9 7.5'/%3E%3Cpath d='M5.5 10.5V20h13v-9.5'/%3E%3Cpath d='M9.5 20v-6h5v6'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}

@media (max-width: 920px) {
  .page {
    margin: 0;
  }

  .exercise__content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  :root {
    --panel-width: min(100%, calc(100vw - 20px));
  }

  .container {
    padding: 22px 10px 16px;
  }

  .lesson-heading h1 {
    font-size: clamp(36px, 11vw, 48px);
  }

  .qr-toggle {
    left: calc(50% + 72px);
  }

  .qr-panel {
    left: calc(50% + 146px);
  }

  .exercise__header {
    padding: 16px;
  }

  .title-pill {
    min-height: 48px;
    padding: 11px 18px;
  }

  .intro p {
    font-size: 20px;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .card__label {
    top: 9px;
    left: 9px;
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .preview__frame {
    aspect-ratio: 4 / 3;
  }
}

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