@font-face {
  font-family: "Dancing Script";
  src: url("/assets/dancing-script-medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Letter Handwriting";
  src: url("/assets/prize-handwriting-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --background: #0c1425;
  --panel: #152138;
  --raised: #1b2941;
  --inset: #0f192d;
  --line: #34445e;
  --text: #f0eee9;
  --muted: #bdc9db;
  --accent: #f5d9a8;
  --accent-line: #887355;
  --danger: #ffb2b4;
  --handwriting: "Letter Handwriting", "Kaiti SC", KaiTi, STKaiti, serif;
  font-family: var(--handwriting);
  scroll-behavior: smooth;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(ellipse 64rem 44rem at 71% 0, #22304d, transparent 85%), var(--background);
  font-size: 16px;
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
button, a, .upload-button { -webkit-tap-highlight-color: transparent; }
button, select, .upload-button { cursor: pointer; }
button:disabled, .upload-button:has(:disabled) { opacity: .48; cursor: default; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

h1, h2, h3, p { margin: 0; }

.workspace {
  display: grid;
  gap: 18px;
  max-width: 1188px;
  margin-inline: auto;
  padding: 27px 24px 55px;
}

.letter-cover {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  min-height: 350px;
  overflow: hidden;
  border: 1px solid #7d83905c;
  border-radius: 21px;
  background: radial-gradient(ellipse at 77% 51%, #425779 0%, transparent 60%),
    radial-gradient(ellipse at 23% 94%, #33283b91, transparent 55%), #131d32;
  box-shadow: 0 15px 36px #050a1869;
}

.letter-cover::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 7px;
  border: 1px solid #f4d4a432;
  border-radius: 15px;
  pointer-events: none;
  mask-image: linear-gradient(125deg, #000, transparent 37%, transparent 71%, #000);
}

.preview-scene {
  position: absolute;
  z-index: -1;
  inset: 0 0 0 51%;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 57% 84%, #e7b57945, transparent 58%);
  pointer-events: none;
}

.preview-window {
  position: relative;
  width: auto;
  height: 88%;
  max-width: 86%;
  aspect-ratio: .82;
  overflow: hidden;
  border: 1px solid #e9c78b9e;
  border-radius: 49% 49% 6px 6px / 29% 29% 6px 6px;
  background: #17283f;
  box-shadow: 0 0 0 4px #efd19a18, 0 0 0 5px #efd19a33, 0 12px 36px #071020ad;
}

.preview-window::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #17223724, transparent 38%, transparent 70%, #101a2c5e);
}

.preview-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 44%;
}

.preview-scene::after {
  content: "";
  position: absolute;
  right: 1%;
  bottom: -4%;
  width: 78%;
  height: 80%;
  background: url('/assets/maker-light-ribbon.png') center / contain no-repeat;
  opacity: .45;
  transform: translateX(9%) rotate(7deg);
  mask-image: linear-gradient(100deg, transparent, #000 32%);
}

.page-intro { width: 57%; padding: 34px 0 39px clamp(28px, 5.4vw, 69px); }
.cover-ornament {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.cover-ornament::before {
  content: "";
  width: 25px;
  aspect-ratio: 1;
  background: url('/assets/moonlit-snowflake.webp') center / contain no-repeat;
  filter: drop-shadow(0 0 5px #abc8ff9c);
}

.cover-ornament::after { content: ""; width: 79px; height: 1px; background: linear-gradient(90deg, #e8c692a0, transparent); }
.page-intro h1 {
  color: #fff0d1;
  font-size: clamp(36px, 6.3vw, 73px);
  font-weight: 400;
  line-height: 1.14;
  letter-spacing: .015em;
  text-shadow: 0 3px 21px #1c1121c9;
  white-space: nowrap;
}
.title-ta { color: #f5d2a1; font: 500 1.09em/.8 "Dancing Script", var(--handwriting); }
.cover-copy { max-width: 25em; margin-top: 14px; color: #e1e5ee; font-size: clamp(16px, 2.2vw, 20px); line-height: 1.65; text-wrap: pretty; }
.cover-copy span { display: block; }

.preview-details {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 15px;
  margin-top: 21px;
}
.preview-details p { color: var(--muted); font-size: 14px; }

.letter-form {
  --space: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: var(--space);
  min-width: 0;
}
.form-aside { display: grid; align-self: start; gap: var(--space); min-width: 0; }
.section {
  min-width: 0;
  padding: 17px 21px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(139deg, #1c2a43, var(--panel) 72%);
}

.section-heading, .item-heading, .draw-field, .dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.section-heading { margin-bottom: 12px; }
.section-heading h2 { display: flex; align-items: center; gap: 9px; color: #faecd1; font-size: 23px; font-weight: 400; line-height: 1.35; }
.section-heading h2::before {
  content: "";
  flex: 0 0 6px;
  height: 6px;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: 0 0 8px #f8d7a548;
}
.section-heading p, .quality-panel p, .draw-field small, .link-card p, .dialog-heading p {
  color: var(--muted);
  font-size: 14px;
}
.section-heading p { margin-top: 4px; }

.section-count {
  flex-shrink: 0;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: #101b2dc4;
  color: #dfcaa7;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

input:not([type="file"]), select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 45px;
  padding: 9px 12px;
  border: 1px solid #4a5c77;
  border-radius: 9px;
  background: var(--inset);
  color: var(--text);
}

input::placeholder, textarea::placeholder { color: #a5b5cc; opacity: 1; }
input[type="number"] { font-variant-numeric: tabular-nums; }
textarea { display: block; resize: vertical; }

.button, .upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
}

.button:hover:not(:disabled), .upload-button:hover:not(:has(:disabled)) { filter: brightness(1.16); }
.button-secondary { border-color: var(--accent-line); background: #3a3237; color: var(--accent); }
.button-primary {
  border-color: #f9e3bf;
  background: linear-gradient(145deg, #ffebc0, #d8b17b);
  color: #332518;
  box-shadow: inset 0 0 0 2px #fff3d548, 0 3px 12px #03081180;
}

.button-add, .upload-button {
  border-color: #73819b;
  border-style: dashed;
  color: #e2eaff;
  background: #111e34;
}

.upload-button { position: relative; width: max-content; max-width: 100%; }
.upload-button:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }
.upload-button input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: system-ui, sans-serif;
  cursor: inherit;
  opacity: 0;
}

.upload-icon, .button-add span { color: var(--accent); line-height: 1; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(89px, 1fr));
  gap: 8px;
  margin: 0 0 11px;
  padding: 0;
  list-style: none;
}

.photo-grid:empty, .field-note:empty { display: none; }
.photo {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1.15;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--inset);
}

.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo img:not([src]) { display: none; }
.photo-state { padding: 8px; color: var(--muted); text-align: center; font-size: 13px; }
.photo-state:empty { display: none; }

.remove-photo, .dialog-close {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #8492a7;
  border-radius: 50%;
  background: #0a1528ec;
  color: #fff;
  font-size: 21px;
  line-height: 1;
}

.remove-photo { position: absolute; top: 3px; right: 3px; width: 29px; height: 29px; }
.remove-photo:focus-visible { outline-offset: -2px; }
.photo:has(.photo-state:not(:empty)) .remove-photo { top: auto; bottom: 3px; }
.dialog-close { flex: 0 0 44px; height: 44px; }
.field-note { margin-top: 8px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.error { color: var(--danger) !important; }

.music-preview { display: grid; gap: 6px; min-width: 0; margin-bottom: 10px; }
.music-preview p { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.music-preview audio { display: block; width: 100%; }
.music-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }

.items {
  --list-height: 21rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  block-size: min(var(--list-height), 64vh);
  block-size: min(var(--list-height), 64dvh);
  margin-bottom: 10px;
  padding: 7px;
  overflow-y: auto;
  scroll-padding-block: 7px;
  scrollbar-color: #7386a3 var(--inset);
  scrollbar-gutter: stable;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--inset);
}

#tasks { --list-height: 16rem; }
.items-empty { margin: auto; color: var(--muted); font-size: 14px; }
.items-empty:not(:only-child) { display: none; }
.item {
  display: grid;
  flex: 0 0 auto;
  gap: 11px;
  min-width: 0;
  padding: 10px 13px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--raised);
}

.item-heading { align-items: center; }
.item-heading h3 { color: var(--accent); font-size: 17px; font-weight: 400; }
.button-remove { color: var(--muted); font-size: 14px; }
.button-remove:hover:not(:disabled) { color: var(--danger); }
.item-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(80px, .34fr);
  align-items: end;
  gap: 9px;
}

.field { display: grid; gap: 4px; min-width: 0; }
.field > span { color: #d8e0ed; font-size: 14px; }
.ending-fields { display: grid; gap: 10px; }
.item-image { display: grid; gap: 7px; justify-items: start; }
.item-image img { width: 80px; height: 60px; object-fit: cover; border: 1px solid var(--line); border-radius: 7px; }
.item-image-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.item-image .field-note { margin: 0; }

.quality-panel {
  min-width: 0;
  margin: 19px 0 0;
  padding: 10px 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.quality-panel legend { padding-inline: 5px; color: #f5e2c0; }
.qualities { display: grid; gap: 7px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 8px; }
.quality {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 5px;
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 2px 0 color-mix(in srgb, var(--quality-color) 50%, transparent);
  background: var(--raised);
}

.quality-blue { --quality-color: #96cffb; }
.quality-pink { --quality-color: #ffaed6; }
.quality-gold { --quality-color: #f3d39b; }
.quality-label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.quality-label i { width: 7px; height: 7px; flex: 0 0 7px; transform: rotate(45deg); background: var(--quality-color); }
.quality input { grid-column: 1 / -1; grid-row: 2; padding-inline: 6px; }
.quality-chance { justify-self: end; color: var(--quality-color); font-size: 13px; font-variant-numeric: tabular-nums; }
.draw-field { align-items: center; margin-top: 16px; }
.draw-field strong, .draw-field small { display: block; }
.draw-field strong { font-weight: 400; }
.draw-field input { flex: 0 0 80px; width: 80px; }

.form-actions { grid-column: 1 / -1; display: grid; gap: 6px; justify-items: end; }
.form-actions p { text-align: end; }
.action-row { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.share-dialog {
  width: min(calc(100% - 26px), 595px);
  max-height: calc(100% - 20px);
  padding: 20px 21px;
  border: 1px solid var(--accent-line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 28px 100px #000c;
}

.share-dialog::backdrop { background: #050b19cc; }
.dialog-heading h2 { color: var(--accent); font-size: 31px; font-weight: 400; line-height: 1.25; }
.dialog-heading p { margin-top: 5px; }
.link-card { margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--inset); }
.link-card label { color: #f5e2c0; }
.link-controls { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.link-controls input { flex: 1; }
.link-controls a, .link-controls button { flex: 0 0 auto; }
.button-text { color: var(--accent); }

@media (max-width: 850px) {
  .workspace { gap: 11px; padding: 13px 13px 34px; }
  .letter-cover { min-height: 267px; border-radius: 15px; }
  .letter-cover::before { inset: 5px; border-radius: 11px; }
  .page-intro { width: 62%; padding: 23px 0 27px clamp(17px, 4vw, 37px); }
  .preview-scene { left: 53%; }
  .preview-details { margin-top: 13px; }
  .letter-form { --space: 10px; }
  .section { padding: 13px 14px 15px; border-radius: 12px; }
  .section-heading h2 { font-size: 20px; }
}

@media (max-width: 660px) {
  .letter-form { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 540px) {
  .letter-cover { min-height: 233px; }
  .page-intro { width: 63%; padding-top: 17px; padding-bottom: 19px; }
  .page-intro h1 { font-size: clamp(21px, 7.65vw - 1px, 40px); }
  .cover-copy { margin-top: 7px; font-size: 15px; line-height: 1.5; }
  .cover-copy span { display: inline; }
  .preview-scene { left: 65%; }
  .preview-window { height: auto; max-width: 79%; width: 100%; }
  .preview-scene::after { right: -9%; bottom: 2%; width: 100%; }
  .cover-ornament { margin-bottom: 5px; }
  .cover-ornament::before { width: 19px; }
  .cover-ornament::after { width: 54px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .workspace { gap: 9px; padding-top: 8px; }
  .letter-cover { min-height: 0; }
  .page-intro { padding-top: 13px; padding-bottom: 15px; }
  .page-intro h1 { font-size: clamp(29px, 5.6vw, 47px); }
  .cover-copy { margin-top: 6px; font-size: 16px; line-height: 1.46; }
  .cover-ornament { margin-bottom: 5px; }
  .cover-ornament::before { width: 19px; }
  .preview-details { margin-top: 9px; }
  .section { padding-top: 11px; }
  .section-heading { margin-bottom: 6px; }
}

@media (max-width: 550px) and (max-height: 330px) and (orientation: landscape) {
  .preview-scene { left: 66%; }
  .preview-window { width: auto; max-width: 82%; height: 87%; }
  .cover-ornament { display: none; }
  .page-intro { width: 68%; }
  .cover-copy { font-size: 14px; }
  .cover-copy span { display: block; }
}

@media (pointer: coarse) {
  .remove-photo { width: 44px; height: 44px; }
  .photo:has(.photo-state:not(:empty)) .remove-photo { top: auto; bottom: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  :root { scroll-behavior: auto; }
}
