:root {
  color-scheme: light;
  font-family: Georgia, "Times New Roman", serif;
  font-synthesis: none;
  color: #493a35;
  background: #f6efe6;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgb(255 255 255 / 55%), transparent 34%),
    radial-gradient(circle at 84% 88%, rgb(186 143 112 / 12%), transparent 38%),
    #f6efe6;
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.experience {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  padding:
    max(1.5rem, env(safe-area-inset-top))
    max(1.25rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
}

.screen {
  display: grid;
  min-height: calc(
    100vh - max(1.5rem, env(safe-area-inset-top)) -
      max(1.5rem, env(safe-area-inset-bottom))
  );
  min-height: calc(
    100dvh - max(1.5rem, env(safe-area-inset-top)) -
      max(1.5rem, env(safe-area-inset-bottom))
  );
  place-items: center;
  opacity: 1;
  transition: opacity 420ms ease, transform 420ms ease;
}

.screen__content {
  display: flex;
  width: min(100%, 30rem);
  flex-direction: column;
  align-items: center;
  gap: clamp(2.25rem, 7vh, 4.5rem);
  text-align: center;
}

.heart {
  color: #9f6f61;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.5rem, 5vw, 2rem);
  line-height: 1;
  animation: breathe 4.5s ease-in-out infinite;
}

.welcome-copy {
  display: grid;
  gap: 1.1rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 13ch;
  color: #3f302c;
  font-size: clamp(2.25rem, 9vw, 4.25rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.08;
  text-wrap: balance;
}

p {
  max-width: 29ch;
  color: #75625b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(1rem, 3.8vw, 1.15rem);
  line-height: 1.65;
  text-wrap: balance;
}

.primary-button {
  min-width: min(100%, 12rem);
  min-height: 3.5rem;
  padding: 0.9rem 2rem;
  border: 1px solid #6f5048;
  border-radius: 999px;
  color: #fffaf4;
  background: #6f5048;
  box-shadow: 0 0.65rem 1.5rem rgb(83 57 49 / 16%);
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.035em;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 160ms ease, box-shadow 160ms ease,
    transform 160ms ease;
}

.primary-button:focus-visible {
  outline: 3px solid rgb(111 80 72 / 34%);
  outline-offset: 4px;
}

.primary-button:active {
  background: #5f443d;
  box-shadow: 0 0.3rem 0.8rem rgb(83 57 49 / 16%);
  transform: translateY(2px) scale(0.985);
}

.primary-button:disabled {
  cursor: default;
}

.screen--reveal {
  opacity: 0;
  transform: translateY(0.5rem);
}

.screen--reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.screen.is-leaving {
  opacity: 0;
  transform: translateY(-0.5rem);
  pointer-events: none;
}

.screen__content--compact {
  gap: 1.25rem;
}

.screen__content--compact h2 {
  max-width: 18ch;
  color: #3f302c;
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.12;
  text-wrap: balance;
}

.screen__content--compact h2:focus {
  outline: none;
}

.password-content {
  gap: clamp(1.25rem, 4vh, 2rem);
}

.password-form {
  display: flex;
  width: min(100%, 18rem);
  flex-direction: column;
  gap: 1rem;
}

.password-field {
  width: 100%;
  min-height: 3.5rem;
  padding: 0.8rem 1rem;
  border: 1px solid rgb(112 82 72 / 32%);
  border-radius: 0.9rem;
  appearance: none;
  -webkit-appearance: none;
  background: rgb(255 252 247 / 78%);
  color: #493a35;
  font: inherit;
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-align: center;
  touch-action: manipulation;
  transition: border-color 180ms ease, box-shadow 180ms ease,
    background-color 180ms ease;
}

.password-field:focus {
  border-color: rgb(112 82 72 / 72%);
  outline: 2px solid transparent;
  box-shadow: 0 0 0 3px rgb(112 82 72 / 14%);
  background: rgb(255 252 247 / 96%);
}

.password-field[aria-invalid="true"] {
  border-color: rgb(142 76 71 / 68%);
}

.password-form .primary-button {
  width: 100%;
}

.password-error {
  max-width: 22rem;
  margin: -0.35rem 0 0;
  color: #805651;
  font-size: 0.9rem;
  line-height: 1.5;
  text-wrap: balance;
}

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

.puzzle-screen {
  padding-block: 0.5rem;
}

.puzzle-layout {
  display: flex;
  width: min(100%, 30rem);
  flex-direction: column;
  align-items: center;
  gap: clamp(1.25rem, 3.5vh, 2rem);
  text-align: center;
}

.puzzle-intro {
  display: grid;
  gap: 0.4rem;
  transition: opacity 350ms ease;
}

.puzzle-intro h2 {
  margin: 0;
  color: #3f302c;
  font-size: clamp(1.4rem, 5.8vw, 2rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-wrap: balance;
}

.puzzle-intro h2:focus {
  outline: none;
}

.puzzle-intro p {
  font-size: clamp(0.92rem, 3.5vw, 1.05rem);
}

.puzzle-board {
  display: grid;
  width: min(100%, 22rem);
  aspect-ratio: 3 / 4;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 0.22rem;
  padding: 0.22rem;
  overflow: hidden;
  border-radius: 1rem;
  background: rgb(111 80 72 / 14%);
  box-shadow: 0 1rem 2.5rem rgb(74 51 44 / 16%);
  transition: gap 420ms ease, padding 420ms ease, box-shadow 420ms ease;
  isolation: isolate;
}

.puzzle-piece {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0.35rem;
  appearance: none;
  opacity: 1;
  background-color: #d9c9bb;
  background-image: url("assets/images/puzzle-photo.png");
  background-repeat: no-repeat;
  background-position: var(--piece-x) var(--piece-y);
  background-size: 200% 500%;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 18%);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-radius 420ms ease, box-shadow 180ms ease,
    filter 180ms ease, opacity 180ms ease;
}

.puzzle-piece:focus-visible {
  z-index: 3;
  outline: 3px solid #fffaf4;
  outline-offset: -5px;
  box-shadow: inset 0 0 0 7px rgb(111 80 72 / 78%);
}

.puzzle-piece.is-pressed {
  filter: brightness(1.04);
}

.puzzle-piece.is-selected {
  z-index: 2;
  box-shadow:
    inset 0 0 0 4px #fffaf4,
    inset 0 0 0 7px #8a6156;
  filter: brightness(1.05);
}

.puzzle-piece.is-dragging {
  z-index: 5;
  cursor: grabbing;
  opacity: 0.9;
  filter: brightness(1.06);
  box-shadow: 0 0.8rem 1.5rem rgb(56 38 33 / 28%);
  pointer-events: none;
  transition: box-shadow 140ms ease, filter 140ms ease, opacity 140ms ease;
}

.puzzle-piece.is-drop-target {
  z-index: 2;
  box-shadow:
    inset 0 0 0 4px rgb(255 250 244 / 92%),
    inset 0 0 0 7px #a17062;
  filter: brightness(1.08);
}

.puzzle-piece.is-swapping {
  animation: settle-piece 260ms ease;
}

.puzzle-board.is-solved {
  gap: 0;
  padding: 0;
  box-shadow: 0 1.15rem 2.8rem rgb(74 51 44 / 18%);
}

.puzzle-board.is-solved .puzzle-piece {
  border-radius: 0;
  cursor: default;
  pointer-events: none;
}

.puzzle-screen.is-complete .puzzle-intro {
  opacity: 0.58;
}

.completion-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 420ms ease, transform 420ms ease;
}

.completion-message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.completion-message p {
  color: #594640;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 4.5vw, 1.4rem);
  line-height: 1.55;
}

.completion-heart {
  color: #9f6f61;
  font-size: 1.4rem;
  line-height: 1;
}

.completion-message .primary-button {
  min-height: 3.25rem;
}

.word-search-screen {
  place-items: start center;
  padding-block: 0.5rem;
}

.word-search-layout {
  display: flex;
  width: min(100%, 30rem);
  flex-direction: column;
  align-items: center;
  gap: clamp(1rem, 3vh, 1.6rem);
  text-align: center;
}

.word-search-intro {
  display: grid;
  gap: 0.4rem;
  max-width: 28rem;
}

.word-search-intro h2 {
  margin: 0;
  color: #3f302c;
  font-size: clamp(1.35rem, 5.5vw, 2rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-wrap: balance;
}

.word-search-intro h2:focus {
  outline: none;
}

.word-search-intro p {
  font-size: clamp(0.92rem, 3.5vw, 1.05rem);
}

.word-progress {
  padding: 0.4rem 0.8rem;
  border: 1px solid rgb(111 80 72 / 16%);
  border-radius: 999px;
  color: #6f5048;
  background: rgb(255 250 244 / 52%);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  line-height: 1.2;
}

.word-grid {
  display: grid;
  width: min(100%, 27rem);
  aspect-ratio: 1;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: clamp(0.08rem, 0.45vw, 0.18rem);
  padding: clamp(0.22rem, 1vw, 0.4rem);
  border: 1px solid rgb(111 80 72 / 13%);
  border-radius: 0.9rem;
  background: rgb(255 250 244 / 48%);
  box-shadow: 0 0.9rem 2.4rem rgb(74 51 44 / 12%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.word-grid__row {
  display: contents;
}

.word-cell {
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: clamp(0.15rem, 0.7vw, 0.3rem);
  place-items: center;
  appearance: none;
  opacity: 1;
  color: #55423c;
  background: rgb(255 255 255 / 42%);
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(0.75rem, 3.2vw, 0.98rem);
  font-weight: 650;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 140ms ease, background-color 140ms ease,
    box-shadow 140ms ease, transform 140ms ease;
}

.word-cell:focus-visible {
  z-index: 3;
  outline: 2px solid #6f5048;
  outline-offset: 1px;
}

.word-cell.is-active {
  color: #3f302c;
  background: #d8bdb0;
  box-shadow: inset 0 0 0 1px rgb(111 80 72 / 28%);
  transform: scale(1.04);
}

.word-cell.is-found {
  color: #fffaf4;
  background: #93675b;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 20%);
}

.word-cell.is-found.is-active {
  background: #805a50;
}

.word-cell.is-invalid {
  animation: invalid-selection 260ms ease;
}

.word-grid.is-complete {
  box-shadow:
    0 0 0 3px rgb(159 111 97 / 12%),
    0 1rem 2.6rem rgb(74 51 44 / 14%);
}

.word-grid.is-complete .word-cell {
  cursor: default;
}

.word-bank {
  width: min(100%, 27rem);
}

.word-bank h3 {
  margin: 0 0 0.65rem;
  color: #75625b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.word-list {
  display: grid;
  margin: 0;
  padding: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 1rem;
  list-style: none;
  text-align: left;
}

.word-list li {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.4rem;
  color: #594640;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(0.76rem, 3vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.055em;
  transition: color 180ms ease, opacity 180ms ease;
}

.word-list li span {
  width: 0.8rem;
  color: #8f655a;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 180ms ease, transform 180ms ease;
}

.word-list li.is-found {
  color: #75625b;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.word-list li.is-found span {
  opacity: 1;
  transform: scale(1);
}

.word-search-completion {
  max-width: 27rem;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

.word-search-completion p {
  font-size: clamp(1.1rem, 4.4vw, 1.35rem);
}

.final-letter-screen {
  display: block;
}

.letter {
  width: min(100%, 38rem);
  margin-inline: auto;
  padding:
    clamp(1.25rem, 6vh, 3.5rem)
    clamp(0.2rem, 1.5vw, 0.75rem)
    max(5rem, calc(3rem + env(safe-area-inset-bottom)));
}

.letter-header {
  margin-bottom: clamp(2rem, 7vh, 3.75rem);
}

.letter-salutation {
  max-width: none;
  color: #3f302c;
  font-size: clamp(2.35rem, 10vw, 3.75rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.1;
  text-align: left;
}

.letter-salutation:focus {
  outline: none;
}

.letter-body {
  display: grid;
  gap: clamp(1.5rem, 5vh, 2.25rem);
}

.letter-body p {
  max-width: none;
  color: #51403a;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.06rem, 4.2vw, 1.2rem);
  line-height: 1.82;
  text-align: left;
  text-wrap: wrap;
}

.letter-divider {
  display: grid;
  margin-block: clamp(2.75rem, 8vh, 4.5rem) 2rem;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  color: #9f6f61;
}

.letter-divider::before,
.letter-divider::after {
  height: 1px;
  background: linear-gradient(to right, transparent, rgb(111 80 72 / 24%));
  content: "";
}

.letter-divider::after {
  background: linear-gradient(to left, transparent, rgb(111 80 72 / 24%));
}

.letter-divider span {
  font-size: 1.25rem;
  line-height: 1;
}

.letter-signature {
  max-width: none;
  color: #6f5048;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 4.8vw, 1.5rem);
  font-style: italic;
  line-height: 1.5;
  text-align: right;
  text-wrap: wrap;
}

.letter-ending {
  margin-top: clamp(4.5rem, 14vh, 8rem);
  text-align: center;
}

.letter-ending p {
  max-width: none;
  color: #6f5048;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 4.6vw, 1.4rem);
  letter-spacing: 0.015em;
  line-height: 1.6;
  text-wrap: balance;
}

@keyframes invalid-selection {
  0%,
  100% {
    background: rgb(255 255 255 / 42%);
    transform: scale(1);
  }

  50% {
    background: #decac0;
    transform: scale(0.96);
  }
}

@keyframes settle-piece {
  0% {
    opacity: 0.72;
    transform: scale(0.97);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.72;
    transform: scale(1);
  }

  50% {
    opacity: 1;
    transform: scale(1.06);
  }
}

@media (max-width: 32rem) {
  .word-search-screen {
    width: calc(100% + 1rem);
    margin-inline: -0.5rem;
  }
}

@media (orientation: landscape) and (max-height: 32rem) {
  .experience {
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .screen {
    min-height: calc(
      100dvh - max(1rem, env(safe-area-inset-top)) -
        max(1rem, env(safe-area-inset-bottom))
    );
  }

  .screen__content {
    gap: 1.25rem;
  }

  h1 {
    font-size: clamp(2rem, 7vw, 3rem);
  }

  .puzzle-layout {
    gap: 0.8rem;
  }

  .puzzle-board {
    width: min(100%, 15rem);
  }

  .puzzle-intro {
    gap: 0.2rem;
  }

  .word-search-layout {
    gap: 0.8rem;
  }

  .word-grid {
    width: min(100%, 19rem);
  }
}

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