:root {
  color-scheme: dark;
  font-family: "DM Sans", system-ui, sans-serif;
  background: #201b32;
  color: #fff4eb;
  --paper: #30263f;
  --border: #6f5b80;
}
* { box-sizing: border-box; }
body { margin: 0; }
.intro, main, footer { width: min(100% - 2rem, 68rem); margin-inline: auto; }
.intro { padding-block: 2rem; }
h1 { font-family: Georgia, serif; font-style: italic; font-size: clamp(3rem, 11vw, 7rem); line-height: .84; letter-spacing: -.055em; color: #ffb8d6; margin: 1.25rem 0; }
h2 { margin: 0; font-size: clamp(1.9rem, 5vw, 3rem); letter-spacing: -.05em; }
h3 { margin: .2rem 0 .6rem; font-size: 1rem; }
p, label { line-height: 1.55; }
a { color: #ffd7ee; text-underline-offset: .25em; }
nav, .actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
nav a, button, summary {
  font: inherit; font-weight: 650; color: inherit; border: 1px solid var(--border);
  border-radius: .65rem; background: #30263f; padding: .52rem .7rem;
  min-height: 2.75rem; cursor: pointer;
}
nav a { text-decoration: none; }
button:hover, nav a:hover, summary:hover { background: #493659; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 3px solid #ffe8a9; outline-offset: 2px; }
.experiment {
  --accent: #ffc1da;
  background: var(--paper); border: 1px solid var(--border);
  border-top: 5px solid var(--accent); border-radius: 1rem;
  margin-bottom: 1.5rem; padding: clamp(.8rem, 3vw, 2rem); scroll-margin-top: 1rem;
}
#poetry { --accent: #bcebb0; }
#stitch { --accent: #ffdc9a; }
#flags { --accent: #cfc1ff; }
.experiment h2 { color: var(--accent); }
textarea, input, select {
  color: inherit; background: #241d32; border: 1px solid var(--border);
  font: inherit; font-size: 1rem; border-radius: .55rem; padding: .6rem;
}
textarea { display: block; width: 100%; margin: .55rem 0; resize: vertical; }
label { display: block; }
summary { width: fit-content; }
.source { margin-block: .8rem; }
.workbench { display: grid; gap: .7rem; }
.passage, .zone, .result, .flag-note {
  padding: .8rem; border-radius: .75rem; background: #241d32; border: 1px solid var(--border);
}
.passage-words { line-height: 2.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.word { display: inline; min-height: 0; padding: .24rem .18rem; border: 0; background: transparent; user-select: none; -webkit-user-select: none; }
.word[aria-pressed="true"] { color: #241d32; background: #ffdc9a; }
.word.flagged { text-decoration: underline 2px dotted #d0baff; text-underline-offset: .25em; }
.word.flagged[aria-pressed="true"] { text-decoration-color: #443068; }
.zone { min-width: 0; border-style: dashed; }
.zone.active-drop, .piece.active-drop { outline: 3px solid #ffe8a9; }
.zones { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .7rem; }
.pieces { display: flex; flex-wrap: wrap; align-items: start; gap: .5rem; min-height: 2rem; }
.stack > .pieces { display: grid; }
.piece { display: flex; align-items: start; gap: .25rem; min-width: 0; border-radius: .55rem; background: #3a2e49; border: 1px solid var(--border); }
.piece[data-armed="true"] { outline: 2px dashed #ffe8a9; }
.piece-text { min-width: 0; flex: 1; padding: .58rem .3rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.piece .small { font-size: .8rem; padding: .25rem .35rem; min-height: 2.75rem; }
#tape [data-tape-color] { --tape-fill: #ffd0e2; --tape-mark: #f6adc9; --tape-pattern: repeating-linear-gradient(135deg,var(--tape-fill) 0 11px,var(--tape-mark) 11px 22px); }
#tape [data-tape-color="mint"] { --tape-fill: #d7f4df; --tape-mark: #9fcdb0; }
#tape [data-tape-color="butter"] { --tape-fill: #fff0b4; --tape-mark: #dec583; }
#tape [data-tape-color="blue"] { --tape-fill: #d5ebff; --tape-mark: #a8c9ed; }
#tape [data-tape-color="lilac"] { --tape-fill: #eedcff; --tape-mark: #c9abe2; }
#tape [data-tape-color="peach"] { --tape-fill: #ffe2cc; --tape-mark: #e9b69a; }
#tape :is([data-tape-color="mint"],[data-tape-color="lilac"]) {
  --tape-pattern: radial-gradient(circle,var(--tape-mark) 1.5px,transparent 2px) 0 0 / 8px 8px var(--tape-fill);
}
#tape :is([data-tape-color="butter"],[data-tape-color="peach"]) {
  --tape-pattern: repeating-linear-gradient(0deg,transparent 0 9px,var(--tape-mark) 9px 10px),
    repeating-linear-gradient(90deg,transparent 0 9px,var(--tape-mark) 9px 10px) var(--tape-fill);
}
#tape .piece-text, #tape .tape-shelf [data-tape-color] { color: #251c2b; background: var(--tape-pattern, none); background-color: var(--tape-fill, #ffd0e2); }
#tape .piece-text { margin: .2rem 0; border-radius: .24rem; }
#tape .tape-shelf [data-tape-color][aria-pressed=true] { outline: 2px solid #fff4eb; outline-offset: 2px; }
.tape-shelf { padding: .65rem; border-bottom: 1px solid var(--border); }
.tape-shelf > .actions + .actions { margin-top: .55rem; }
.tape-shelf [data-tape-color] { padding: .32rem .55rem; font-size: .9rem; }
.tape-highlight { display: inline-flex; align-items: center; gap: .45rem; min-height: 2.75rem; }
[data-tape-paint=true] { outline: 2px dashed var(--accent); }
[data-tape-passage] .word { touch-action: none; -webkit-touch-callout: none; }
[data-tape-passage][data-continuous=true] .word[aria-pressed=true] { border-radius: 0; box-shadow: -.17em 0 #ffdc9a, .17em 0 #ffdc9a; }
#poetry .piece, #poetry .piece-text { background: var(--tile-fill, #e6f3d7); color: var(--tile-text, #24341e); }
#poetry .piece-text { border-color: var(--tile-edge, #6c795d); }
#stitch .piece-text { background: var(--tile-fill, #30263f); color: var(--tile-text, #fff4eb); }
:root[data-tile-palette="lavender"] { --tile-fill: #eee2ff; --tile-text: #302044; --tile-stripe: #dbbff8; --tile-edge: #73558e; }
:root[data-tile-palette="peach"] { --tile-fill: #ffe1c7; --tile-text: #462619; --tile-stripe: #ffc6a9; --tile-edge: #865641; }
:root[data-tile-palette="midnight"] { --tile-fill: #273d62; --tile-text: #f3f7ff; --tile-stripe: #314972; --tile-edge: #a4bee9; }
#tile-colors { margin-top: .8rem; }
#tile-colors button[aria-pressed="true"] { outline: 2px solid #ffe8a9; outline-offset: 2px; }
#tile-colors [data-palette="original"] { background: #e6f3d7; color: #24341e; }
#tile-colors [data-palette="lavender"] { background: #eee2ff; color: #302044; }
#tile-colors [data-palette="peach"] { background: #ffe1c7; color: #462619; }
#tile-colors [data-palette="midnight"] { background: #273d62; color: #f3f7ff; }
.primary { color: #27182e; background: var(--accent); border-color: transparent; }
.primary:hover { background: #fff1cc; }
.hint { color: #e3d0ec; font-size: .9rem; margin: 0; }
.flag-list { display:flex; flex-wrap:wrap; gap:.45rem; }
.flag-chip[data-color="clue"] { border-color:#ffdc9a; }
.flag-chip[data-color="timing"] { border-color:#bcebb0; }
.flag-chip[data-color="keep"] { border-color:#ffc1da; }
.flag-chip[aria-pressed="true"] { outline: 2px solid #fff4eb; }
.result { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
#status { position: fixed; pointer-events: none; bottom: max(.6rem, env(safe-area-inset-bottom)); right: .8rem; background: #fff4eb; color: #261b34; border-radius: .55rem; padding: .55rem .75rem; }
#status:empty { display: none; }
footer { padding: .6rem 0 2rem; }
@media(max-width: 620px) {
  .zones { grid-template-columns: 1fr; }
  .intro, main, footer { width: calc(100% - 1rem); }
  .intro { padding-inline: .5rem; }
}
@media (pointer: coarse) {
  #poetry .piece-text { min-width: 3.5rem; text-align: center; font-size: 1.12rem; }
}
.drag-ghost {
  position: fixed; top: 0; left: 0; z-index: 5; pointer-events: none;
  max-width: calc(100vw - 16px); overflow-wrap: anywhere; white-space: pre-wrap;
  padding: .6rem .7rem; color: #27182e; background: #ffe2ef; border-radius: .6rem;
  box-shadow: 0 .35rem .8rem #110d20a0;
}

#motion { margin-top: .7rem; }
#motion[aria-pressed="true"] { border-color: #ffb8d6; }
.piece { position: relative; }
button.piece-text {
  min-height: 2.75rem; text-align: left; font-weight: 650; line-height: 1.4;
  border-radius: .45rem; cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
button.piece-text:active { cursor: grabbing; }
:root[data-poetry-dragging], :root[data-poetry-dragging] * { cursor: grabbing !important; }
.being-dragged { opacity: .45; }
.piece.active-drop { outline: none; }
.piece[data-drop-side]::before, .piece[data-drop-side]::after {
  position: absolute; z-index: 6; pointer-events: none;
  background: #ffe8a9;
}
.piece[data-drop-side]::before {
  content: ""; inset-block: 0; width: 3px; border-radius: 2px;
  box-shadow: 0 0 0 1px #241d32;
}
.piece[data-drop-side="before"]::before { left: -6px; }
.piece[data-drop-side="after"]::before { right: -6px; }
.piece[data-drop-side]::after {
  content: attr(data-drop-side);
  background: #ffe8a9; color: #27182e; font-size: .75rem; font-weight: 750;
  text-transform: capitalize; border-radius: .3rem; padding: .12rem .35rem;
  top: -.55rem; left: -.3rem;
}
.piece[data-drop-side="after"]::after { left: auto; right: -.3rem; }
.stack .piece[data-drop-side]::before { inset: auto 0; width: auto; height: 3px; }
.stack .piece[data-drop-side="before"]::before { top: -6px; }
.stack .piece[data-drop-side="after"]::before { bottom: -6px; }
.stack .piece[data-drop-side="after"]::after { top: auto; bottom: -.55rem; }
.selection-preview { padding: .65rem .8rem; border-left: 3px solid var(--accent); background: #241d32; white-space: pre-wrap; }
.selection-preview small { margin-right: .4rem; color: var(--accent); }
.piece.cutting { flex-wrap: wrap; }
.piece .cut-points { flex: 1 0 100%; padding: .55rem; line-height: 2.8; }
.cut-point { min-width: 2rem; min-height: 2.75rem; margin: 0 .12rem; padding: .15rem .28rem; color: #302036; background: #ffe8a9; line-height: 1; border-radius: .25rem; vertical-align: middle; }
.cut-point:hover, .cut-point:focus-visible { background: #fff6df; }
.stitch-seam { justify-self: center; min-height: 2.75rem; border: 1px dashed #ffdc9a; color: #ffdc9a; margin-block: -.12rem; }
.stitch-seam::before { content: "┄ "; }
.stitch-seam::after { content: " ┄"; }
.word.current-flag { background: #492e67; color: #fff4eb; }
.word.current-flag[aria-pressed="true"] { background: #ffdc9a; color: #241d32; }
[data-motion="on"] .flag-note, [data-motion="on"] .selection-preview {
  animation: pop-in 200ms cubic-bezier(.2,.8,.25,1.12) both;
}
@keyframes pop-in { from { opacity: .35; scale: .96; } to { opacity: 1; scale: 1; } }

.zone-title, .zone-title:hover {
  min-height: 0; padding: 0; border: 0; border-radius: .15rem; background: transparent;
  font-weight: inherit; text-align: left;
}
.zone-title:disabled { opacity: 1; }
.ready-to-place .zone-title { text-decoration: underline; text-underline-offset: .2em; }
.placement-hint {
  position: fixed; z-index: 4; bottom: max(.75rem, env(safe-area-inset-bottom));
  left: 50%; translate: -50% 0; width: min(38rem, calc(100% - 1.25rem));
  padding: .6rem .75rem; border: 1px solid #ffdc9a; border-radius: .8rem;
  background: #30263f; box-shadow: 0 .3rem 1rem #110d20b0;
  pointer-events: none; margin: 0; font-size: .92rem;
}
.placement-hint strong { display: inline-block; max-width: 10rem; vertical-align: bottom; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body:has(.placement-hint) { padding-bottom: 6rem; }
body:has(.placement-hint) #status { bottom: 6rem; }
