/* LOOM — gen 2 UI. Appliqué cloth: indigo ground, cream bands, running stitches. */
:root {
  --indigo-0: #0d1226; --indigo-1: #151c38; --indigo-2: #22305a; --indigo-3: #3a4f86;
  --bark: #8a6a4a; --bark-dk: #5a4330; --cream: #efe6d2; --snow: #f6f3ec;
  --vermilion: #c2412d; --ember: #e8833a; --gold: #d9a440; --silver: #c9d2dc;
  --moss: #5b6b45; --sea: #1f4a5a; --sea-lt: #4f8a94;
  --f-display: 'Cormorant Garamond', 'EB Garamond', Georgia, serif;
  --f-text: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --stitch: repeating-linear-gradient(90deg, var(--cream) 0 7px, transparent 7px 13px);
}
html, body { margin: 0; height: 100%; background: var(--indigo-0); color: var(--cream); overflow: hidden; }
body { font-family: var(--f-text); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }

.loom { position: fixed; inset: 0; overflow: hidden; background: var(--indigo-0); user-select: none; -webkit-user-select: none; --loom-size: 1; }
.loom.loading::after { content: ''; position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; border: 2px dashed var(--cream); opacity: .5; animation: loom-spin 6s linear infinite; }
@keyframes loom-spin { to { transform: rotate(360deg); } }
.loom-stage { position: absolute; inset: 0; }
.loom-stage > svg { width: 100%; height: 100%; display: block; }

.loom-ui { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .8s; cursor: pointer; }
.loom-ui.on { opacity: 1; pointer-events: auto; }

/* ---------- the verse box ---------- */
.loom-box {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  width: min(1060px, calc(100% - 32px)); transform: translate(-50%, 14px);
  min-height: calc(8.4em * var(--loom-size)); box-sizing: border-box;
  padding: 1.35em 2.1em 1.45em; opacity: 0; transition: opacity .55s, transform .55s;
  background:
    radial-gradient(120% 140% at 50% 0%, rgba(58,79,134,.28), transparent 60%),
    linear-gradient(180deg, rgba(21,28,56,.94), rgba(13,18,38,.97));
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--indigo-0), 0 0 0 4px rgba(239,230,210,.82), 0 0 0 7px var(--indigo-1), 0 18px 50px rgba(0,0,0,.55);
}
.loom-box.on { opacity: 1; transform: translate(-50%, 0); }
.loom-box::before { /* inner running stitch */
  content: ''; position: absolute; inset: 8px; border-radius: 3px; pointer-events: none;
  border: 1.5px dashed rgba(239,230,210,.42);
}
.loom-box::after { /* aiushi corner ornaments */
  content: ''; position: absolute; inset: -14px; pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M4 36 V12 Q4 4 12 4 H36 M12 36 V20 Q12 12 20 12 H36 M20 28 Q20 20 28 20' fill='none' stroke='%23efe6d2' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") left top / 34px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M36 36 V12 Q36 4 28 4 H4 M28 36 V20 Q28 12 20 12 H4 M20 28 Q20 20 12 20' fill='none' stroke='%23efe6d2' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") right top / 34px no-repeat;
  opacity: .8;
}
.loom-name {
  position: absolute; left: 1.6em; top: 0; transform: translateY(-62%);
  padding: .32em 1.1em .36em; background: var(--name-bg, var(--bark-dk)); border-radius: 4px;
  box-shadow: 0 0 0 2px var(--indigo-0), 0 0 0 3.5px var(--who, var(--cream));
  font-family: var(--f-display); font-weight: 600; letter-spacing: .06em; font-size: calc(1.08rem * var(--loom-size));
  color: var(--snow); transition: opacity .3s;
}
.loom-name::before { content: ''; position: absolute; inset: 4px; border: 1px dashed rgba(239,230,210,.45); border-radius: 2px; pointer-events: none; }
.loom-box.narration .loom-name { background: var(--indigo-2); font-style: italic; font-weight: 500; }
.loom-name.empty { opacity: 0; }
.loom-text {
  position: relative; font-size: calc(clamp(1.06rem, 1.55vw + .55rem, 1.42rem) * var(--loom-size)); line-height: 1.5;
  color: var(--snow); text-shadow: 0 1px 2px rgba(0,0,0,.5); min-height: 4.5em;
}
.loom-text .ln { display: block; padding-left: 1.2em; text-indent: -1.2em; }
.loom-box.narration .loom-text { color: #efe9da; }
.loom-text .c { opacity: 0; transition: opacity .18s; }
.loom-text .c.on { opacity: 1; }
.loom-text em { font-style: italic; color: #f3dfb0; }
.loom-text strong { font-weight: 600; color: #f6e6c2; }
.loom-note {
  display: inline-block; vertical-align: super; font-size: .62em; line-height: 1; margin: 0 .12em; padding: .18em .38em .12em;
  border: 1px solid rgba(217,164,64,.7); border-radius: 999px; background: rgba(217,164,64,.15); color: var(--gold); cursor: help;
}
.loom-note:hover, .loom-note:focus-visible { background: var(--gold); color: var(--indigo-0); outline: none; }
.loom-gloss { background: none; border: 0; padding: 0; cursor: help; color: inherit; border-bottom: 1px dotted rgba(217,164,64,.85); font-style: inherit; }
.loom-next { position: absolute; right: 1.4em; bottom: .9em; width: 14px; height: 14px; opacity: 0; transition: opacity .3s; }
.loom-next::before { content: ''; position: absolute; inset: 0; background: var(--gold); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); animation: loom-bob 1.8s ease-in-out infinite; }
.loom-box.done .loom-next { opacity: .9; }
@keyframes loom-bob { 50% { transform: translateY(4px); } }

/* ---------- sakehe band ---------- */
.loom-band {
  position: absolute; left: 50%; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 9.6em * var(--loom-size)); transform: translate(-50%, 8px);
  width: min(1060px, calc(100% - 32px)); text-align: center; opacity: 0; transition: opacity .7s, transform .7s; pointer-events: none;
}
.loom-band.on { opacity: 1; transform: translate(-50%, 0); }
.loom-band.on.dim { opacity: .5; }
.loom-ui:not(:has(.loom-box.on)) .loom-band.on { bottom: 34vh; }
.loom-band-line { border-radius: 999px; background: radial-gradient(closest-side, rgba(13,18,38,.62), rgba(13,18,38,.35) 70%, transparent); display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 0 .02em; font-family: var(--f-display); font-style: italic; font-weight: 500;
  font-size: calc(clamp(1.5rem, 3.6vw, 2.9rem) * var(--loom-size)); letter-spacing: .03em; padding: .2em .8em; }
.loom-band-gloss { font-family: var(--f-display); font-style: italic; font-size: calc(clamp(1rem, 1.8vw, 1.35rem) * var(--loom-size)); color: #f3dfb0; opacity: .85; margin-top: .1em; }
.syl { color: rgba(239,230,210,.22); transition: color .35s, text-shadow .5s; white-space: pre; }
.syl.lit { color: var(--snow); text-shadow: 0 0 18px rgba(217,164,64,.65), 0 0 2px rgba(255,255,255,.6); }

/* ---------- cards ---------- */
.loom-card { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity .9s; background: radial-gradient(70% 60% at 50% 50%, rgba(13,18,38,.62), rgba(13,18,38,.9)); }
.loom-card.on { opacity: 1; pointer-events: auto; }
.loom-card-inner { text-align: center; padding: 2rem 1.5rem; max-width: 46rem; }
.loom-card h2 { font-family: var(--f-display); font-weight: 500; font-size: clamp(1.7rem, 4.2vw, 3.2rem); margin: .6rem 0 .3rem; letter-spacing: .03em; color: var(--snow); text-wrap: balance; }
.loom-card-sub { font-family: var(--f-display); font-style: italic; font-size: clamp(1.05rem, 2.2vw, 1.6rem); color: #f3dfb0; text-wrap: balance; }
.loom-card-inner.end { background: radial-gradient(closest-side, rgba(13,18,38,.94), rgba(13,18,38,.86) 75%, rgba(13,18,38,0)); padding: 2.5rem 3rem; border-radius: 50%; }
.loom-card-inner.end h2 { font-size: clamp(2rem, 5vw, 3.6rem); }
.loom-card-inner.end p { font-size: clamp(1rem, 1.6vw, 1.22rem); line-height: 1.6; color: #e9e1cf; margin: .8rem auto; max-width: 38rem; }
.loom-card-inner.end p.couplet { font-family: var(--f-display); font-style: italic; font-size: clamp(1.15rem, 2vw, 1.5rem); color: #f3dfb0; }

/* ---------- ornament (moreu) ---------- */
.loom-orn { width: 220px; height: 54px; margin: 0 auto; opacity: .9;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 220 54'%3E%3Cg fill='none' stroke='%23efe6d2' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M110 50 V30 M110 30 C110 12 92 6 82 14 C72 22 80 36 92 30 C99 26 96 18 90 20'/%3E%3Cpath d='M110 30 C110 12 128 6 138 14 C148 22 140 36 128 30 C121 26 124 18 130 20'/%3E%3Cpath d='M70 40 H20 Q8 40 8 28 Q8 18 18 18 Q26 18 26 26' /%3E%3Cpath d='M150 40 H200 Q212 40 212 28 Q212 18 202 18 Q194 18 194 26'/%3E%3C/g%3E%3Cg fill='none' stroke='%23d9a440' stroke-width='1.6' stroke-dasharray='4 4'%3E%3Cpath d='M70 46 H24 Q2 46 2 28'/%3E%3Cpath d='M150 46 H196 Q218 46 218 28'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat; }
.loom-orn.small { width: 150px; height: 38px; }

/* ---------- top bar ---------- */
.loom-bar { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 4px; opacity: .55; transition: opacity .3s; }
.loom-bar:hover { opacity: 1; }
.loom-bar button { background: rgba(13,18,38,.55); border: 1px solid rgba(239,230,210,.3); border-radius: 4px; padding: .3em .7em; font-size: .86rem; letter-spacing: .04em; cursor: pointer; }
.loom-bar button:hover, .loom-bar button.on { border-color: var(--gold); color: var(--gold); }
.loom-ui.hidden-text .loom-box, .loom-ui.hidden-text .loom-band, .loom-ui.hidden-text .loom-bar { opacity: 0 !important; }

/* ---------- popover ---------- */
.loom-pop { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(8,10,22,.55); opacity: 0; pointer-events: none; transition: opacity .35s; z-index: 30; }
.loom-pop.on { opacity: 1; pointer-events: auto; }
.loom-pop-inner { position: relative; max-width: 34rem; max-height: 80vh; overflow: auto; padding: 1.5rem 1.7rem 1.1rem; background: #f1e8d3; color: #2a2116; border-radius: 4px;
  box-shadow: 0 0 0 3px #f1e8d3, 0 0 0 5px var(--bark-dk), 0 20px 60px rgba(0,0,0,.6); font-size: 1.08rem; line-height: 1.55; }
.loom-pop-inner::before { content: ''; position: absolute; inset: 7px; border: 1.5px dashed rgba(90,67,48,.45); border-radius: 2px; pointer-events: none; }
.pop-head { font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; letter-spacing: .04em; color: var(--vermilion); margin-bottom: .45rem; }
.pop-body em { color: #6b3a1c; }
.pop-foot { margin-top: .9rem; font-size: .8rem; opacity: .55; text-align: right; font-style: italic; }

/* ---------- panels ---------- */
.loom-panel { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(8,10,22,.7); opacity: 0; pointer-events: none; transition: opacity .4s; z-index: 20; }
.loom-panel.on { opacity: 1; pointer-events: auto; }
.loom-panel-inner { position: relative; width: min(720px, 100%); max-height: 86vh; overflow: auto; box-sizing: border-box; padding: 1.8rem 2rem 1.6rem;
  background: linear-gradient(180deg, var(--indigo-1), var(--indigo-0)); border-radius: 6px; box-shadow: 0 0 0 2px var(--indigo-0), 0 0 0 4px rgba(239,230,210,.75), 0 30px 80px rgba(0,0,0,.6); }
.loom-panel-inner::before { content: ''; position: absolute; inset: 9px; border: 1.5px dashed rgba(239,230,210,.35); border-radius: 3px; pointer-events: none; }
.loom-panel h2 { font-family: var(--f-display); font-weight: 500; font-size: 2rem; margin: 0 0 1rem; text-align: center; letter-spacing: .06em; }
.loom-close { position: absolute; top: .6rem; right: .8rem; width: 2.2rem; height: 2.2rem; border: 0; background: none; font-size: 1.7rem; line-height: 1; cursor: pointer; opacity: .7; }
.loom-close:hover { opacity: 1; color: var(--gold); }
.loom-contents { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.loom-contents li + li { border-top: 1px dashed rgba(239,230,210,.18); }
.loom-contents button { display: grid; grid-template-columns: 1fr auto; gap: .1rem .8rem; width: 100%; text-align: left; background: none; border: 0; padding: .7rem .4rem; cursor: pointer; }
.loom-contents button:hover { background: rgba(239,230,210,.06); }
.c-title { font-family: var(--f-display); font-size: 1.22rem; font-weight: 600; }
.c-sub { grid-column: 1; font-style: italic; color: #f3dfb0; font-size: 1rem; opacity: .85; }
.c-mark { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--gold); font-size: .8rem; }
.loom-settings label { display: grid; grid-template-columns: 11rem 1fr; align-items: center; gap: 1rem; margin: .7rem 0; }
.loom-settings label.ck { grid-template-columns: auto 1fr; gap: .6rem; }
.loom-settings input[type=range] { accent-color: var(--gold); width: 100%; }
.loom-settings input[type=checkbox] { accent-color: var(--gold); width: 1.1rem; height: 1.1rem; }
.loom-keys { opacity: .6; font-size: .9rem; margin-top: 1.3rem; text-align: center; }
.loom-log { max-height: 62vh; overflow: auto; padding-right: .4rem; }
.log-item { padding: .6rem 0; border-bottom: 1px dashed rgba(239,230,210,.14); }
.log-name { font-family: var(--f-display); font-weight: 600; color: var(--gold); font-size: .95rem; letter-spacing: .05em; }
.log-text { line-height: 1.45; opacity: .92; }
.loom-prose { line-height: 1.62; font-size: 1.08rem; }
.loom-prose p { margin: .7rem 0; }
.loom-prose a { color: var(--gold); }
.loom-prose h3 { font-family: var(--f-display); font-weight: 600; font-size: 1.3rem; margin: 1.4rem 0 .3rem; color: #f3dfb0; }

/* ---------- title ---------- */
.loom-title { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity 1.2s; z-index: 10; background: radial-gradient(46% 40% at 50% 50%, rgba(13,18,38,.86), rgba(13,18,38,.55) 70%, rgba(13,18,38,.4)); }
.loom-title.on { opacity: 1; pointer-events: auto; }
.loom-title-inner { text-align: center; padding: 1.5rem; }
.loom-title h1 { font-family: var(--f-display); font-weight: 500; font-size: clamp(2.6rem, 8vw, 6rem); letter-spacing: .08em; margin: .6rem 0 .2rem; color: var(--snow); text-shadow: 0 0 40px rgba(217,164,64,.35), 0 2px 4px rgba(0,0,0,.6); line-height: 1.05; }
.loom-title-sub { font-family: var(--f-display); font-style: italic; font-size: clamp(1.1rem, 2.6vw, 1.7rem); color: #f3dfb0; }
.loom-title-by { margin-top: .4rem; font-size: clamp(.95rem, 1.6vw, 1.1rem); opacity: .8; letter-spacing: .04em; }
.loom-title-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; margin-top: 2rem; }
.loom-title-nav button { background: rgba(13,18,38,.6); border: 0; border-radius: 4px; padding: .6em 1.3em; cursor: pointer; font-family: var(--f-display); font-size: 1.15rem; font-weight: 600; letter-spacing: .05em;
  box-shadow: 0 0 0 1.5px rgba(239,230,210,.55); position: relative; }
.loom-title-nav button::before { content: ''; position: absolute; inset: 4px; border: 1px dashed rgba(239,230,210,.3); border-radius: 2px; pointer-events: none; }
.loom-title-nav button:hover, .loom-title-nav button:focus-visible { box-shadow: 0 0 0 1.5px var(--gold); color: var(--gold); outline: none; }
.loom-title-foot { margin-top: 2.2rem; font-size: .85rem; opacity: .55; line-height: 1.6; }
.loom-title-foot a { color: inherit; }

.reduce-motion *, .reduce-motion *::before { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; }

@media (max-width: 640px) {
  .loom-box { padding: 1.15em 1.15em 1.25em; min-height: 9.5em; }
  .loom-name { left: 1em; }
  .loom-bar button { padding: .25em .5em; font-size: .78rem; }
  .loom-settings label { grid-template-columns: 1fr; gap: .2rem; }
  .loom-box::after { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .loom-box { min-height: 6em; padding: .8em 1.4em .9em; }
  .loom-text { font-size: calc(1rem * var(--loom-size)); min-height: 3em; }
}
