:root {
  color-scheme: dark;
  font-family: "Segoe UI", sans-serif;
  color: #f4e8d0;
  background: #0c171c;
  --ink: #271b20;
  --paper: #faedce;
  --gold: #efcb82;
  --line: #ae884f;
  --panel: #17241f;
  --rail-inset: clamp(1rem, calc((100vw - 150svh) / 2 + 1rem), 5vw);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }

.card {
  --scene-width: min(100%, 150svh);
  min-height: 100svh;
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  background: radial-gradient(ellipse at 50% 70%, #47302c, #10232d 58%, #0c171c 88%);
}

.scene-wrap {
  grid-area: 1 / 1;
  width: var(--scene-width);
  aspect-ratio: 3 / 2;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 60px #060e15a6;
}

#scene { width: 100%; height: 100%; touch-action: none; }
#scene canvas { display: block; }
.scene-wrap:has(#scene:focus-visible)::after { content: ""; position: absolute; inset: 3px; border: 2px solid #ffd88c; pointer-events: none; }
#tree-selection { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#flight { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#trash-gutter {
  position: fixed;
  inset: 0 auto 0 0;
  width: calc((100% - var(--scene-width)) / 2 + var(--scene-width) * .17);
  z-index: 1;
  pointer-events: none;
  display: grid;
  align-items: end;
  border-right: 1px dashed #e2ba76a8;
  color: #ffe4ab;
  background: linear-gradient(90deg, #6e2b3a87, #642a3640);
}
#trash-gutter[data-over] { background: linear-gradient(90deg, #a1465bdd, #9d3e507a); }
#trash-gutter > span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .8rem .35rem;
  margin: 0 .45rem 1rem;
  background: #351e2492;
  font: .9rem Georgia, serif;
  text-align: center;
}

.greeting {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  align-items: center;
  justify-items: start;
  padding: 2rem clamp(1.25rem, 11vw, 11rem);
  background: linear-gradient(90deg, #090e16a8, #090e1638 62%, #090e1612);
}

.letter {
  width: min(100%, 30rem);
  color: var(--ink);
  padding: clamp(1.45rem, 4vw, 2.8rem);
  background: radial-gradient(at 15% 0%, #fff8e4, #f8ebcd 80%);
  border: 1px solid #b8945f;
  box-shadow: 0 0 0 4px #f4dfb54d, 0 20px 70px #08080bb3;
  position: relative;
}

.letter::before {
  content: "";
  inset: 7px;
  position: absolute;
  border: 1px solid #b088558a;
  pointer-events: none;
}

h1, h2, .signoff, .primary, #toggle-agents {
  font-family: Georgia, "Times New Roman", serif;
}

h1 { margin: 0 0 1.05rem; font-size: clamp(1.85rem, 3.3vw, 2.65rem); font-weight: normal; color: #611b2b; }
h2 { font-size: 1.3rem; margin: 0 0 .6rem; font-weight: normal; }
p { line-height: 1.55; }
.letter p { margin: 0 0 1rem; }
.letter .signoff { font-size: 1.06rem; font-style: italic; margin-bottom: 1.2rem; }
.letter .loading { margin: .55rem 0 0; font-size: .79rem; }

button {
  color: inherit;
  border: 1px solid #9a805575;
  background: #27382f;
  border-radius: 6px;
  padding: .6rem .8rem;
  font: .99rem "Segoe UI", sans-serif;
  cursor: pointer;
}

button:hover:enabled { background: #30453d; }
button:disabled { opacity: .48; cursor: default; }
.primary { color: #281a18; background: linear-gradient(#ffe6a9, #dcac62); border-color: #ffde9a; font-weight: bold; box-shadow: inset 0 1px #fff3cc; }
.primary:hover:enabled { background: #ffe0a2; }
.letter .primary { background: #76263a; color: #fff3da; border-color: #76263a; }
.letter .primary:hover:enabled { background: #922f48; }
:focus-visible { outline: 2px solid #ffd88c; outline-offset: 3px; }
.letter :focus-visible { outline-color: #76263a; }

.rail, .tree-actions {
  position: absolute;
  color: #f7e9c9;
  background: radial-gradient(ellipse at 42% 0%, #394637, var(--panel) 64%, #11201c);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 3px #22281f, inset 0 0 0 4px #a0804470, 0 0 0 2px #33271f9c, 0 11px 26px #0b130fb0;
  border-radius: 12px;
}

.rail { top: 50%; transform: translateY(-50%); padding: 1.15rem; }
.tray { left: var(--rail-inset); width: 10.1rem; text-align: center; }
.agents { right: var(--rail-inset); width: 14.25rem; }
.agents h2, .tray h2 { color: #f5d992; text-shadow: 0 1px #241c12; }
.tray h2 { margin-bottom: .65rem; }
.placement-guide { color: #f7e9c9; font-size: .79rem; line-height: 1.35; margin: 0 0 .65rem; text-align: left; }
.touch-guide { display: none; }
.agent-heading { display: flex; align-items: center; justify-content: space-between; gap: .45rem; margin-bottom: .62rem; }
.agent-heading h2 { margin: 0; }
#toggle-agents { display: none; }
#agent-count { margin-left: auto; font-size: .73rem; white-space: nowrap; color: #f5d992; }
#stop-agents { padding: .3rem .42rem; font-size: .74rem; }
.agent-list {
  --agent-row: 2.55rem;
  max-height: calc(5 * var(--agent-row));
  overflow: hidden auto;
  scrollbar-width: thin;
  scrollbar-color: #b89556 #212f25;
}
.ornaments {
  --ornament-image: clamp(1.425rem, 7.8svh, 3rem);
  --ornament-slot: max(clamp(2.5rem, 9.4svh, 4.65rem), calc(var(--ornament-image) + 1.65rem));
  --slot-gap: .42rem;
  display: grid;
  gap: var(--slot-gap);
  justify-items: stretch;
  grid-auto-rows: var(--ornament-slot);
  max-height: calc(4.24 * var(--ornament-slot) + 4 * var(--slot-gap));
  overflow: hidden auto;
  padding-right: .18rem;
  scrollbar-width: thin;
  scrollbar-color: #b89556 #212f25;
}
.ornament { display: grid; justify-items: center; align-content: center; gap: .08rem; padding: .15rem .1rem; font-size: .79rem; line-height: 1.1; touch-action: pan-y; user-select: none; background: #203027; cursor: grab; }
.ornament img { width: var(--ornament-image); height: var(--ornament-image); object-fit: contain; pointer-events: none; filter: drop-shadow(0 3px 4px #10150e85); }
.ornament[aria-pressed="true"] { border-color: #ffe8ad; background: #394138; box-shadow: inset 0 0 0 1px #e6ca82; }
.ornament.pickup, .ornaments.pickup { animation: pickup .42s ease-out; }
.rail-pager { width: 100%; margin-top: .5rem; padding: .34rem .15rem; color: #f5d992; font-size: .74rem; }
.rail-pager::after { content: ""; display: inline-block; vertical-align: .15em; margin-left: .48em; width: .36em; height: .36em; border: solid currentColor; border-width: 0 1px 1px 0; transform: rotate(45deg); }
.rail-pager[data-end]::after { transform: rotate(225deg); vertical-align: -.1em; }
@keyframes pickup {
  35% { box-shadow: inset 0 0 13px #eec45d, 0 0 9px #f7d17d8c; }
}
.trash { display: flex; width: 100%; gap: .43rem; align-items: center; justify-content: center; margin-top: .65rem; padding: .43rem .2rem; background: #1b2822; border-style: dashed; }
.trash:disabled { opacity: .53; }
.trash:enabled { color: #ffe4ab; border-color: #e2ba76; }
.trash[data-over] { background: #743846; border-color: #ffcc87; }
.bin-icon { width: .62rem; height: .66rem; border: 1px solid currentColor; border-radius: 0 0 2px 2px; position: relative; }
.bin-icon::before { content: ""; height: 1px; background: currentColor; position: absolute; inset: -3px -3px auto; }
.rule { display: flex; align-items: center; justify-content: space-between; gap: .3rem; min-height: var(--agent-row); padding: .3rem .3rem .3rem 0; cursor: pointer; border-top: 1px solid #b598633d; font-size: .86rem; line-height: 1.14; }
.rule input { appearance: none; margin: 0; width: 2.55rem; height: 1.23rem; border: 1px solid #997948; border-radius: 1rem; background: #101914; position: relative; flex-shrink: 0; cursor: pointer; }
.rule input::after { content: ""; position: absolute; left: 2px; top: 2px; width: .78rem; height: .78rem; border-radius: 50%; background: #c6ad7c; }
.rule:has(input:checked) { color: #ffe8ad; }
.rule input:checked { background: #705318; border-color: #f4d18c; }
.rule input:checked::before { content: "On"; position: absolute; left: .34rem; top: .13rem; color: #fff1c8; font: 600 .65rem/1.2 "Segoe UI", sans-serif; }
.rule input:checked::after { left: auto; right: 2px; background: #ffe3a2; }
.tree-actions { display: flex; align-items: center; gap: .4rem; bottom: 1.1rem; right: var(--rail-inset); padding: .55rem; flex-wrap: wrap; }
#reveal-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #10191c9c;
}
.card:has(#finished:not([hidden]) > .reveal-editor:not([hidden])) > #reveal-backdrop { display: block; }
.reveal-panel { display: grid; grid-template-areas: "actions" "feedback"; gap: .7rem; z-index: 3; }
.reveal-panel:has(.reveal-editor[hidden]) :is(#copy, #save) { display: none; }
.reveal-panel:has(.reveal-editor:not([hidden])) {
  position: relative;
  inset: auto;
  grid-area: 1 / 1;
  grid-template:
    "preview fields" 1fr
    "preview actions" auto
    "preview feedback" 1fr
    / minmax(0, clamp(18.75rem, 55svh, 22.5rem)) minmax(0, 1fr);
  width: min(44rem, calc(100% - 1.3rem));
  margin: 1rem auto;
  padding: clamp(.85rem, 2.5vw, 1.5rem);
  column-gap: clamp(1rem, 2.5vw, 1.5rem);
}
.reveal-editor { display: contents; }
#card-preview { grid-area: preview; box-shadow: 0 4px 12px #08080ba6; }
#card-preview canvas { display: block; width: 100%; height: auto; }
.card-fields { grid-area: fields; align-self: end; display: grid; gap: .32rem; min-width: 0; }
.card-fields label { font-size: .83rem; color: #ffdfa3; }
.card-fields label span { color: #dccba6; }
.card-fields input {
  min-width: 0;
  width: 100%;
  margin-bottom: .35rem;
  padding: .56rem .54rem;
  font: 1rem Georgia, "Times New Roman", serif;
  color: #fff1d2;
  background: #192720;
  border: 1px solid #a68a57;
  border-radius: 5px;
}
.reveal-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: .4rem; }
.reveal-actions button { padding-inline: .62rem; }
.reveal-feedback { grid-area: feedback; align-self: start; }
.share-status { margin: 0; font-size: .78rem; color: var(--gold); }
.share-status:empty { position: absolute; }
.noscript { position: fixed; bottom: 2rem; left: 1rem; background: #76263a; padding: 1rem; }

@media (1100px <= width <= 1300px) and (height >= 600px) {
  .card { --rail-inset: clamp(.65rem, calc((100vw - 150svh) / 2 + .75rem), 2vw); }
  .rail { padding: .9rem; }
  .tray { width: 9.5rem; }
  .agents { width: 13.75rem; }
}

@media (width < 1100px), (height < 600px) {
  .card { --scene-width: min(100%, 112svh); display: block; min-height: 100svh; padding-bottom: 1rem; }
  .scene-wrap { margin-inline: auto; }
  #scene { touch-action: pan-y; }
  .greeting { position: relative; display: block; padding: 0 1rem 1rem; margin-top: -1.5rem; background: none; }
  .letter { margin: 0 auto; }
  .rail, .tree-actions { position: relative; inset: auto; transform: none; width: auto; margin: .65rem; }
  .tray, .agents, #tree-actions { width: min(calc(100% - 1.3rem), 42rem); margin-inline: auto; }
  .rail { padding: .75rem; }
  .ornaments { grid-auto-flow: column; grid-auto-rows: minmax(calc(var(--ornament-image) + 2.3rem), auto); grid-auto-columns: calc((100% - 4 * var(--slot-gap)) / 4.24); max-height: none; overflow: auto hidden; padding: 0 0 .18rem; }
  .ornament { touch-action: pan-x; overflow-wrap: anywhere; }
  #more-ornaments::after { transform: rotate(-45deg); vertical-align: .1em; }
  #more-ornaments[data-end]::after { transform: rotate(135deg); vertical-align: .1em; }
  .agent-heading { margin: 0; }
  .agent-heading h2 { flex: 1; }
  .agent-heading h2 span, #more-agents, .agents:has(#toggle-agents[aria-expanded="false"]) .agent-list { display: none; }
  #toggle-agents { display: flex; align-items: center; gap: .5rem; width: 100%; border: 0; background: none; color: inherit; padding: .25rem 0; font: inherit; }
  #toggle-agents::after { content: ""; width: .36rem; height: .36rem; border: solid currentColor; border-width: 0 1px 1px 0; transform: rotate(45deg); }
  #toggle-agents[aria-expanded="true"]::after { transform: rotate(225deg); translate: 0 .2rem; }
  .agent-list { --agent-row: 2.75rem; max-height: none; overflow: visible; }
  #tree-actions #light { margin-inline-start: auto; }
  .reveal-panel { width: max-content; max-width: calc(100% - 1.3rem); margin-inline: auto; }
  .card:has(#finished:not([hidden]) > .reveal-editor:not([hidden])) { padding-top: 1px; }
  .card:has(#finished:not([hidden]) > .reveal-editor:not([hidden])) .scene-wrap { position: absolute; inset: 0 0 auto; }
}

@media (max-width: 700px) {
  .reveal-panel:has(.reveal-editor:not([hidden])) { grid-template: "preview" "fields" "actions" "feedback" / minmax(0, 1fr); }
  #card-preview { width: min(100%, 20rem); justify-self: center; }
  .reveal-actions .primary { flex-basis: 100%; }
}

@media (max-width: 600px) {
  .card:has(#greeting[hidden]) .scene-wrap { aspect-ratio: var(--portrait-ratio); }
  .card:has(#greeting[hidden]) #scene { position: absolute; width: var(--portrait-scene-width); left: 50%; transform: translateX(-50%); }
  #trash-gutter { width: calc((100% - var(--scene-width)) / 2 + var(--scene-width) * .065); }
  #trash-gutter > span { display: none; }
}

@media (pointer: coarse) {
  .pointer-guide { display: none; }
  .touch-guide { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  .ornament.pickup, .ornaments.pickup { animation: none; }
}
