.welcome-view {
  position: relative;
  isolation: isolate;
  display: grid;
  justify-items: center;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2.4vw, 28px);
  margin: clamp(18px, 4vw, 42px) auto;
  padding: clamp(22px, 3.8vw, 44px);
  color: #fff3e1;
  background: radial-gradient(ellipse at 2% 0%, #664332, transparent 70%), linear-gradient(132deg, #442a20, #281812);
  border: 1px solid #9a7242;
  border-radius: 22px;
  box-shadow: 0 16px 38px #42281d29;
}
.welcome-view::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 9px;
  border: 1px solid #c39b676e;
  border-radius: 14px;
  pointer-events: none;
}
.welcome-heading { text-align: center; }
.welcome-kicker {
  margin: 0 0 9px;
  color: #f0cea0;
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .16em;
}
.welcome-heading h1 {
  margin: 0;
  color: #fff1dc;
  font: normal clamp(2rem, 5vw, 3.8rem)/1.06 var(--serif);
  letter-spacing: -.04em;
  text-wrap: balance;
}
.welcome-portrait {
  width: min(100%, 364px);
  margin: 0;
  padding: 5px;
  background: #d7b785;
  border: 1px solid #f1d3a6;
  border-radius: 48% 48% 10px 10px / 18% 18% 10px 10px;
}
.welcome-portrait img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: inherit;
}
.welcome-letter { width: min(100%, 590px); }
.welcome-letter h2 { margin: 0 0 10px; color: #f4d6ad; text-align: center; font: italic clamp(1.34rem, 2.55vw, 1.8rem)/1.2 var(--serif); }
.welcome-letter > p { margin: 0 0 .85em; font-size: .96rem; line-height: 1.6; }
.welcome-letter .welcome-signature { color: #f4d6ad; text-align: right; font: italic 1.13rem/1.4 var(--serif); }
.welcome-signature span { font-size: 1.24em; }
.welcome-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; }
.welcome-actions .primary { min-width: 0; }
.welcome-actions .secondary { min-height: 47px; border-color: #b48b5e; color: #fae7cd; }
.welcome-actions .secondary:hover { background: #634434; }
.welcome-actions button:focus-visible { outline-color: #f1d3a6; }
@media (max-width: 700px) {
  .welcome-heading h1 { font-size: clamp(2rem, 8.5vw, 3.2rem); }
}
@media (max-width: 400px) {
  .welcome-actions > button { width: 100%; }
}

[data-route-key="1"] { --route-key: url("assets/keys/key-1.webp"); }
[data-route-key="2"] { --route-key: url("assets/keys/key-2.webp"); }
[data-route-key="3"] { --route-key: url("assets/keys/key-3.webp"); }
[data-route-key="4"] { --route-key: url("assets/keys/key-4.webp"); }
[data-route-key="5"] { --route-key: url("assets/keys/key-5.webp"); }
[data-route-key="6"] { --route-key: url("assets/keys/key-6.webp"); }
.welcome-key-list summary::before, button.route-key-button::before {
  content: "";
  width: 94px;
  height: 39px;
  flex: 0 0 auto;
  background: var(--route-key) center / contain no-repeat;
}
.welcome-keys {
  width: min(100%, 790px);
  margin-top: 6px;
  padding-top: clamp(16px, 3vw, 26px);
  text-align: center;
  border-top: 1px solid #bb925c73;
}
.welcome-keys h2 { margin: 0; color: #f4d6ad; font: italic clamp(1.7rem, 3.6vw, 2.45rem)/1.2 var(--serif); }
.welcome-keys > p { margin: 7px auto 16px; max-width: 45ch; font-size: .94rem; text-wrap: balance; }
.welcome-key-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.welcome-key-list details {
  border: 1px solid #a87b4d80;
  border-radius: 12px;
  background: #eabe7710;
}
.welcome-key-list summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 84px;
  padding: 8px 5px;
  border-radius: 11px;
  color: #ffe4bb;
  font: 1.07rem/1.18 var(--serif);
  cursor: pointer;
  text-wrap: balance;
}
.welcome-key-list summary::-webkit-details-marker { display: none; }
.welcome-key-list summary::after { content: ""; width: 4px; height: 4px; border: solid #f4d6ad; border-width: 0 1px 1px 0; transform: rotate(45deg); }
.welcome-key-list details[open] summary::after { transform: rotate(225deg); }
.welcome-key-list summary:hover, .welcome-key-list details[open] summary { background: #eabe7719; }
.welcome-key-list summary:focus-visible { outline: 2px solid #f1d3a6; outline-offset: 3px; }
.welcome-key-list details p { margin: 6px 8px 11px; font-size: .86rem; overflow-wrap: anywhere; }
button.route-key-button:is(.primary, .secondary) {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
  align-items: center;
  gap: 8px;
  padding: 4px 11px 4px 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #603c21;
  background: transparent;
  font-weight: 650;
  line-height: 1.25;
  text-align: left;
}
button.route-key-button::before { width: 78px; height: 34px; }
button.route-key-button:is(.primary, .secondary):hover {
  border-color: #dcc29a;
  background: #f7e9d2;
  text-decoration: underline;
  text-underline-offset: 3px;
}
@media (max-width: 570px) {
  .welcome-key-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .welcome-key-list summary::before { width: 74px; }
}

.farewell-song {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(100%, 520px);
  margin: 0 auto 16px;
  padding: 18px clamp(12px, 4vw, 24px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--cream);
}
.farewell-song h2 { margin: 0; font: 1.65rem/1.2 var(--serif); }
.farewell-song label { color: var(--muted); font-size: .9rem; }
.farewell-song select {
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid #c9ab87;
  border-radius: 8px;
  background: #fffdfa;
  color: inherit;
  font: inherit;
}
.farewell-song audio { display: block; width: min(100%, 340px); }
[data-song-toggle] { white-space: nowrap; }
.header:has([data-song-toggle]:not([hidden])),
.dialog-head:has([data-song-toggle]:not([hidden])),
.coloring-heading:has([data-song-toggle]:not([hidden])) { flex-wrap: wrap; gap: 8px 12px; }

.letter-paper {
  position: relative;
  isolation: isolate;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(24px, 6vw, 58px);
  color: #4a2d21;
  background: radial-gradient(ellipse at center, #fff8e4 25%, #f5dfb9 100%);
  border: 1px solid #ad794c;
  border-radius: 6px;
  box-shadow: inset 0 0 26px #9f62202b, 0 12px 30px #4e291b22;
  font: italic 1.12rem/1.6 var(--serif);
  overflow-wrap: anywhere;
}
.letter-paper::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 9px;
  border: 3px double #a77a4f;
  border-radius: 16px 3px;
  pointer-events: none;
}
.letter-paper h1 {
  margin: 0.2em 0;
  text-align: center;
  font: italic 500 clamp(2.4rem, 8vw, 4.1rem)/1.07 "Palatino Linotype", var(--serif);
}
.letter-paper > p { margin: 1rem 0; }
.letter-ornament { text-align: center; color: #8d5f31; font: 2rem/1 var(--serif); }
#letter-content h2 { margin: 1em 0 0.25em; font-size: 1.2em; }
#letter-content p { margin: 0.25em 0; white-space: pre-wrap; }
#letter-content ul { margin: 0.2em 0; padding-inline-start: 1.3em; }
.letter-signature { text-align: right; }
.letter-signature span { font-size: 1.5em; }
.author-letter { width: min(100%, 620px); margin-block: 0 18px; text-align: left; }
.author-letter h1 { margin: .25em 0; text-align: center; font: italic clamp(1.85rem, 4vw, 2.45rem)/1.2 var(--serif); }
.author-letter .letter-signature span { font-size: 1.15em; }
.finale-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
#gratitude-dialog .dialog-head h2 { font: 1.65rem/1.15 var(--serif); }
#gratitude-dialog .journal-field { margin: 0 0 10px; }
#gratitude-dialog .journal-field span, .gratitude-storage { font-size: .88rem; color: var(--muted); }
#gratitude-dialog textarea { min-height: 60px; }
.gratitude-dates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 8px 14px;
  margin: 14px 0;
}
.gratitude-dates label { display: grid; gap: 4px; font-size: .9rem; }
.gratitude-dates :is(input, select) {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  font: inherit;
  color: inherit;
  background: #fffdfa;
  border: 1px solid #c9ab87;
  border-radius: 8px;
}
.gratitude-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.coloring-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(9px, 3vw, 22px);
  max-width: 670px;
  margin-inline: auto;
}
.coloring-back-card {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 2 / 3;
  padding: 6px;
  overflow: hidden;
  color: #ffebbf;
  background: radial-gradient(ellipse at center, #846044, #4a3027 77%);
  border: 1px solid #a87d45;
  border-radius: clamp(8px, 2vw, 16px);
  box-shadow: 0 6px 12px #3521182e;
}
.coloring-back-card::before, .coloring-back-card::after {
  content: "";
  position: absolute;
  inset: 7%;
  border: 3px double #d0a56a;
  border-radius: 10px 2px;
  pointer-events: none;
}
.coloring-back-card::after { inset: 12%; border-width: 1px; border-radius: 50%; opacity: .7; }
.coloring-back-card span { font: clamp(1.7rem, 7vw, 4.7rem)/1 var(--serif); }
.coloring-back-card.has-progress { background: radial-gradient(ellipse at center, #826454, #4a3027 77%); }
#coloring-editor {
  position: fixed;
  inset: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: 0;
  background: var(--paper);
  padding: clamp(10px, 3vw, 22px);
  color: var(--ink);
  overscroll-behavior: contain;
}
.coloring-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 0 auto 10px;
  max-width: 850px;
}
.coloring-heading h2 { margin: 0; font: 1.45rem/1.2 var(--serif); }
.coloring-palette { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; max-width: 720px; margin-inline: auto; }
.coloring-swatch {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid #a3826d;
  border-radius: 50%;
  background: var(--swatch);
}
.coloring-swatch[aria-pressed="true"], #coloring-eraser[aria-pressed="true"] { border: 2px solid #4a2d21; box-shadow: inset 0 0 0 2px white; }
#coloring-instructions, #coloring-status { text-align: center; margin: 5px 0; font-size: .88rem; }
.coloring-keys { text-align: center; margin: 4px 0; font-size: .82rem; color: var(--muted); }
@media (pointer: coarse) { .coloring-keys { display: none; } }
#coloring-status:empty { display: none; }
.coloring-tools { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px; }
.coloring-tools select, #coloring-paper {
  font: inherit;
  color: inherit;
  background: #fffdfa;
  border: 1px solid #c9ab87;
  border-radius: 8px;
  padding: 5px 8px;
}
.coloring-board {
  position: relative;
  isolation: isolate;
  width: min(100%, max(340px, calc((100dvh - 245px) * .72)), 620px);
  margin: 8px auto 12px;
  background: white;
}
#coloring-canvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; }
#coloring-outline { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; mix-blend-mode: multiply; }
#coloring-canvas:focus-visible { outline: 2px solid #aa7436; }
#coloring-cursor {
  display: none;
  position: absolute;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border: 2px solid #482b1b;
  border-radius: 50%;
  box-shadow: 0 0 0 2px white;
  pointer-events: none;
}
#coloring-canvas:focus-visible ~ #coloring-cursor { display: block; }
#finale-print { display: none; }
@page coloring-a4 { size: A4 portrait; margin: 11mm; }
@page coloring-a5 { size: A5 portrait; margin: 9mm; }
@media print {
  body[data-finale-print] { background: white; }
  body[data-finale-print] > :not(#finale-print) { display: none !important; }
  body[data-finale-print] > #finale-print { display: block; }
  #finale-print .letter-paper { box-shadow: none; background: white; max-width: none; }
  #finale-print .letter-paper h2 { break-after: avoid; }
  #finale-print .letter-paper li { break-inside: avoid; }
  #finale-print img { display: block; width: auto; max-width: 100%; object-fit: contain; margin: 0 auto; }
  #finale-print .coloring-a4 { page: coloring-a4; height: 270mm; }
  #finale-print .coloring-a5 { page: coloring-a5; height: 188mm; }
}
