/*
 * wave.css - the WAVE screen (the timeline): where the tree of
 * app/screens/wave/wave-panels.js and the two canvases (wave-field.js,
 * wave-sun.js) stand.
 *
 * RULE (as in app.css): no colour and no font family here, only the custom
 * properties generated from app/design/tokens.js.
 *
 *   .wave                       a column
 *     .wave-head                WAVE, and the "go to" field beside it
 *     .wave-moment              .moment-caption (MOMENT ... NOW) · .wave-stamp (nine .tumbler.term) or
 *                               .wave-out (outside the catalogue) · .wave-earth (EARTH: the date-time
 *                               line, six .tumbler.civil)
 *     .wave-sun                 .sun-caption · .sun-lane (canvas, a slider)
 *     .wave-main                .field-caption · .wave-field (canvas, a slider; it takes the height left)
 *     .limb-straight            the scale
 *     .wave-next                NEXT THRESHOLDS, .next-row x up to 8
 *
 * Phone (below 700 px): the positions of DESIGN.md section 7 on a 393 x 852 screen (hold them with
 * tools/measure.mjs): title 85, stamp 136, Sun lane axis 232, wave axis 380, threshold rule 468, limb 522,
 * list from 583 at pitch 22.4. The MOMENT caption stands 10 px higher than in the render (y 105), so that
 * the ghost above ANY selected tumbler is clear of it. A shorter screen takes rows from the list first,
 * then height from the wave. Desktop: the same column, larger, the wave across the whole screen, the list
 * in two columns.
 */

.wave {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
  overflow: hidden;
}

/* ------------------------------------------------------- title, go to */

.wave-head {
  position: relative;
  flex: 0 0 auto;
  height: 10px;
  margin-top: calc(var(--inset-top) - 14.5px);
}

.wave-title {
  margin: 0;
  font-size: 8.5px;
  line-height: 10px;
  color: var(--c-ash);
}

.wave-goto {
  position: absolute;
  left: 96px;
  top: -5px;
  width: min(36vw, 136px);
  /* the field inside is drawn scaled (below): the form keeps the drawn height */
  height: 18px;
}

/*
 * The field is set in 16 px type and drawn scaled to the engraved size (11 px on a phone, 12.5 px on a
 * desktop, --goto-scale = size / 16). Mobile Safari zooms the whole page into any field whose type is under
 * 16 px when it takes focus, and the instrument's fixed layout would stay zoomed. Every length inside is
 * divided by the scale, so what is drawn is the design's.
 */
.goto-input {
  --goto-scale: 0.6875;
  position: relative;
  display: block;
  width: calc(100% / var(--goto-scale));
  height: calc(18px / var(--goto-scale));
  padding: 0 0 calc(2px / var(--goto-scale));
  border: 0;
  border-bottom: calc(0.75px / var(--goto-scale)) solid var(--c-etch2);
  border-radius: 0;
  background: none;
  color: var(--c-bone);
  font: inherit;
  font-size: 16px;
  line-height: calc(16px / var(--goto-scale));
  transform: scale(var(--goto-scale));
  transform-origin: 0 0;
  caret-color: var(--c-lumen);
  /* nothing blinks (design ruling 11): a steady caret where the engine can draw one (shell/steady-caret.js
     draws it itself elsewhere) */
  caret-animation: manual;
  appearance: none;
}

.goto-input::placeholder {
  color: var(--c-etch3);
  font-family: var(--font-caps);
  font-weight: var(--w-caps);
  font-size: calc(6.8px / var(--goto-scale));
  letter-spacing: var(--track-caps);
  opacity: 1;
}

/* the steady caret drawn by shell/steady-caret.js where the engine has no caret-animation */
.steady-caret {
  position: absolute;
  top: 2px;
  width: 1px;
  height: 13px;
  background: var(--c-lumen);
  pointer-events: none;
}

.goto-input:focus-visible {
  outline: none;
  border-bottom-color: var(--c-lumen);
}

.goto-note {
  position: absolute;
  left: 0;
  top: calc(100% + 3px);
  font-size: 7px;
  line-height: 8px;
  color: var(--c-ash);
}

/* ------------------------------------------------------- the moment */

.wave-moment {
  height: 93px;
  margin-top: 12px;
}

.moment-caption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 8px;
  font-size: 6.8px;
  line-height: 8px;
  color: var(--c-etch3);
}

/* NOW: lit while the present is shown; away from it, how far, and the way back */
.wave-now {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--c-ash);
}

.wave-now.lit {
  color: var(--c-lumen);
  cursor: default;
}

.wave-now .caps {
  /* the last letter's tracking hangs off the right */
  margin-right: calc(var(--track-caps) * -1);
}

.wave-now .ring {
  position: relative;
  width: 8px;
  height: 8px;
  border: 0.9px solid currentColor;
  border-radius: 50%;
}

.wave-now .ring::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: currentColor;
}

.wave-now .offset {
  order: -1;
  margin-right: 4px;
  font-family: var(--font-reading);
  font-weight: var(--w-value);
  font-size: 11px;
  line-height: 8px;
  letter-spacing: 0;
  color: var(--c-bone);
  white-space: nowrap;
}

.wave-stamp {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  margin-top: 15.3px;
}

.wave-out {
  margin-top: 15.3px;
  font-size: 13px;
  line-height: 18px;
  padding-bottom: 5.2px;
  white-space: nowrap;
}

/* a tumbler: one term that turns on its own */
.tumbler {
  position: relative;
  display: block;
  text-align: center;
  white-space: nowrap;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tumbler .value {
  display: block;
}

.tumbler .ghost {
  position: absolute;
  left: -6px;
  right: -6px;
  display: none;
  color: var(--c-etch3);
  pointer-events: none;
}

.tumbler .ghost .u {
  color: inherit;
}

.tumbler.selected .ghost {
  display: block;
}

.tumbler:focus-visible {
  outline-offset: 1px;
}

.tumbler.term {
  padding-bottom: 5.2px;
  font-size: 15px;
  line-height: 18px;
}

/* the line a term stands on; lumen under the selected one */
.tumbler.term::after {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 0;
  border-top: 0.75px solid var(--c-etch2);
}

.tumbler.term.selected::after {
  border-top: 1.2px solid var(--c-lumen);
}

.tumbler.term .ghost {
  font-size: 12px;
  line-height: 14px;
}

.tumbler.term .ghost.previous {
  top: -15.5px;
}

.tumbler.term .ghost.next {
  top: 30.5px;
}

/* EARTH: the date-time line; its fields turn like the terms above */
.wave-earth {
  margin-top: 23px;
  font-size: 10.5px;
  line-height: 13px;
}

.wave-earth .lead {
  white-space: pre;
}

.tumbler.civil {
  display: inline-block;
}

.tumbler.civil .value {
  display: inline;
}

.tumbler.civil.selected {
  color: var(--c-bone);
}

.tumbler.civil .ghost {
  font-size: 9px;
  line-height: 10px;
  font-style: normal;
  color: var(--c-etch3);
}

.tumbler.civil .ghost.previous {
  top: -10px;
}

.tumbler.civil .ghost.next {
  top: 13px;
}

/* ------------------------------------------------------- the Sun's lane */

.wave-top {
  flex: 0 0 auto;
}

.sun-caption,
.field-caption {
  display: flex;
  justify-content: space-between;
  height: 8px;
  font-size: 6.8px;
  line-height: 8px;
}

.sun-caption {
  color: var(--c-sol-label);
}

/* its height is set by wave-sun.js from the size of its arcs: 66 px on the reference phone */
.sun-lane {
  position: relative;
  height: 66px;
  margin: 5.5px -2px 0;
  cursor: ew-resize;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.sun-lane canvas,
.wave-field canvas {
  position: absolute;
  left: 0;
  top: 0;
}

.sun-lane:focus-visible,
.wave-field:focus-visible {
  outline-offset: -1px;
}

/* ------------------------------------------------------- the wave */

.wave-main {
  flex: 1 1 220px;
  min-height: 130px;
  max-height: 330px;
  display: flex;
  flex-direction: column;
  margin-top: 5.5px;
}

.field-caption {
  flex: 0 0 auto;
  color: var(--c-ash);
}

.field-caption .made {
  color: var(--c-etch3);
}

/* the wave runs from edge to edge of the screen */
.wave-field {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 2.5px -20px 0;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.wave-field:active {
  cursor: grabbing;
}

.wave .limb-straight {
  flex: 0 0 auto;
  margin-top: -10px;
}

/* ------------------------------------------------------- next thresholds */

.wave-next {
  flex: 0 10 196.5px;
  min-height: 60px;
  margin-top: 1.5px;
  overflow: hidden;
}

.next-title {
  margin: 0;
  font-size: 6.8px;
  line-height: 8px;
  color: var(--c-ash);
}

.next-rows {
  margin-top: 5.8px;
}

.next-row {
  display: grid;
  grid-template-columns: 20px 22px auto 1fr auto 74px;
  align-items: center;
  height: 22.4px;
  break-inside: avoid;
}

#app[data-mode='earth'] .next-row {
  grid-template-columns: 20px 22px auto 1fr auto 105px;
}

.next-row .quarter-mark {
  grid-column: 1;
  margin-left: -2px;
  transform: translateY(1px);
}

.next-row .symbol {
  grid-column: 2;
  justify-self: center;
  font-size: 15px;
}

.next-row .caps {
  grid-column: 3;
  margin-left: 8px;
  font-size: 7.5px;
  color: var(--c-ash);
}

.next-row.sun-row .caps {
  color: var(--c-sol-label);
}

/* list leader: 1 on / 4 off */
.next-row .leader {
  grid-column: 4;
  height: 1px;
  margin: 0 14px;
  background: repeating-linear-gradient(to right, var(--c-etch1) 0 1px, transparent 1px 5px);
}

.next-row .earth {
  grid-column: 5;
  justify-self: end;
  font-size: 10px;
}

.next-row .span {
  grid-column: 6;
  justify-self: end;
  font-size: 15px;
  white-space: nowrap;
}

/* ------------------------------------------------------- phone */

/*
 * The last rows of the list stand in the air above the sigils (which app.css draws from y 772): the
 * screen reaches down to there, past its own box. The wave has its own NOW mark, beside MOMENT, so the
 * shell's (top centre on a phone) is not shown twice.
 */
#app[data-layout='phone'][data-screen='wave'] #screen {
  overflow: visible;
}

#app[data-layout='phone'] .wave {
  bottom: calc(var(--v) * -25);
}

/* in EARTH mode app.css draws the sigils' box 19.1 v higher (its marks stay where they are) */
#app[data-layout='phone'][data-mode='earth'] .wave {
  bottom: calc(var(--v) * -5.9);
}

#app[data-layout='phone'][data-screen='wave'] .now-mark {
  display: none;
}

/* ------------------------------------------------------- desktop */

#app[data-layout='desktop'] .wave {
  padding: 0 56px 26px 54px;
}

#app[data-layout='desktop'] .wave-head {
  margin-top: clamp(20px, 6.2dvh, 50px);
}

#app[data-layout='desktop'] .wave-goto {
  left: 118px;
  width: 220px;
}

#app[data-layout='desktop'] .goto-input {
  --goto-scale: 0.78125;
}

#app[data-layout='desktop'] .goto-input::placeholder {
  font-size: calc(7.2px / var(--goto-scale));
}

#app[data-layout='desktop'] .moment-caption,
#app[data-layout='desktop'] .sun-caption,
#app[data-layout='desktop'] .field-caption,
#app[data-layout='desktop'] .next-title {
  font-size: 7.2px;
}

/* the moment and the Sun side by side; the Sun goes under the moment where the screen is narrow */
#app[data-layout='desktop'] .wave-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  column-gap: 72px;
  margin-top: clamp(14px, 3.6dvh, 29px);
}

#app[data-layout='desktop'] .wave-moment {
  flex: 1 1 468px;
  max-width: 612px;
  min-width: 0;
  height: 112px;
  margin-top: 0;
}

#app[data-layout='desktop'] .wave-sun {
  flex: 1 1 280px;
  max-width: 560px;
  margin: 12px 0 8px auto;
}

#app[data-layout='desktop'] .wave-stamp,
#app[data-layout='desktop'] .wave-out {
  margin-top: 21px;
}

#app[data-layout='desktop'] .tumbler.term {
  padding-bottom: 7px;
  font-size: 22px;
  line-height: 26px;
}

#app[data-layout='desktop'] .wave-out {
  font-size: 19px;
  line-height: 26px;
}

#app[data-layout='desktop'] .tumbler.term::after {
  left: 7px;
  right: 7px;
}

#app[data-layout='desktop'] .tumbler.term .ghost {
  font-size: 14px;
  line-height: 16px;
}

#app[data-layout='desktop'] .tumbler.term .ghost.previous {
  top: -17px;
}

#app[data-layout='desktop'] .tumbler.term .ghost.next {
  top: 38px;
}

#app[data-layout='desktop'] .wave-now .offset {
  font-size: 12.5px;
}

#app[data-layout='desktop'] .wave-earth {
  margin-top: 24px;
  font-size: 11.5px;
  line-height: 14px;
}

#app[data-layout='desktop'] .wave-main {
  flex: 1 1 300px;
  max-height: 470px;
  margin-top: 10px;
}

#app[data-layout='desktop'] .wave-field {
  margin: 4px -56px 0 -54px;
}

#app[data-layout='desktop'] .wave .limb-straight {
  width: min(100%, 620px);
  align-self: center;
}

#app[data-layout='desktop'] .wave-next {
  flex: 0 10 126px;
  margin-top: 4px;
}

#app[data-layout='desktop'] .next-rows {
  margin-top: 8px;
  column-count: 2;
  column-gap: 84px;
}

#app[data-layout='desktop'] .next-row {
  height: 26px;
}

/* a narrow desktop window: the two columns of the list would cut their spans, so the rows stand in one */
@media (max-width: 1000px) {
  #app[data-layout='desktop'] .wave-next {
    flex-basis: 230px;
  }

  #app[data-layout='desktop'] .next-rows {
    column-count: 1;
  }
}

/*
 * A SHORT desktop window (a phone held sideways, a window at 200 % zoom): the moment and the Sun must stand
 * side by side, or the two of them, one under the other, leave the wave a strip a few px tall. They are set
 * closer and smaller so that both fit in the 654 px a 852 px window gives; the wave takes what is left and
 * the list (the first thing a short screen gives up) is not shown.
 */
@media (max-height: 560px) {
  #app[data-layout='desktop'] .wave-top {
    column-gap: 28px;
    margin-top: 6px;
  }

  #app[data-layout='desktop'] .wave-moment {
    flex: 1 1 350px;
    height: 96px;
  }

  #app[data-layout='desktop'] .wave-sun {
    flex: 1 1 230px;
    margin-top: 6px;
  }

  #app[data-layout='desktop'] .wave-stamp,
  #app[data-layout='desktop'] .wave-out {
    margin-top: 16px;
  }

  #app[data-layout='desktop'] .tumbler.term {
    font-size: 18px;
    line-height: 22px;
  }

  #app[data-layout='desktop'] .tumbler.term .ghost.next {
    top: 32px;
  }

  #app[data-layout='desktop'] .wave-earth {
    margin-top: 18px;
  }

  #app[data-layout='desktop'] .wave-next {
    display: none;
  }
}

/*
 * Touch targets on the phone (app.css): the mode, "go to", NOW and the stamp stand within 50 px of height here,
 * so their hit areas are set side by side instead of centred: the mode and "go to" reach up into the free
 * inset, NOW reaches up to the mode's box and down to the stamp, and wide to its left across the empty caption,
 * and a tumbler reaches down over its ghost and the gap below the stamp.
 */
#app[data-layout='phone'][data-screen='wave'] .mode-toggle,
#app[data-layout='phone'][data-screen='wave'] .wave-goto {
  --hit-top: -24px;
  --hit-bottom: -2px;
}

#app[data-layout='phone'] .wave-now {
  --hit-top: -7px;
  --hit-bottom: -14px;
  --hit-left: -64px;
  --hit-right: -12px;
}

#app[data-layout='phone'] .tumbler.term {
  --hit-top: 0px;
  --hit-bottom: -21px;
}
