/* Kuresaka's chrome is made of the village's own materials: paper plaques, ink lines, a vermilion seal. */

:root {
  --paper: #f4ecd9;
  --paper-shade: #e4d7bb;
  --ink: #2a2522;
  --ink-soft: #5d534a;
  --vermilion: #b8392a;
  --indigo: #2b4477;
  --serif: "Kuresaka Mincho", "Noto Serif CJK JP", "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "Songti SC", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  /* the host's share bar owns this corner */
  --corner: 380px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  opacity: 0;
}

#scene:active {
  cursor: grabbing;
}

/* The village develops out of the paper once the first frame is on screen. */
.is-ready #scene {
  opacity: 1;
  transition: opacity 0.7s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .is-ready #scene {
    transition: none;
  }
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.hud button {
  pointer-events: auto;
  font: inherit;
  color: var(--ink);
}

.hud button:focus-visible,
.clock__strip:focus-visible {
  outline: 2px solid var(--vermilion);
  outline-offset: 2px;
}

/* ---- plaques ---------------------------------------------------------------------------------- */

.mark,
.entry,
.keys,
.clock,
.gaze {
  background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

/* ---- name and entry --------------------------------------------------------------------------- */

.mark {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 10px 6px;
  line-height: 1;
}

.mark__kanji {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.mark__roman {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* kept left of the street so the view into the village stays open */
.entry {
  position: absolute;
  left: 6%;
  top: 15%;
  width: max-content;
  max-width: min(60vw, 430px);
  margin: 0;
  padding: 14px 26px 16px;
  text-align: center;
  display: grid;
  justify-items: center;
  row-gap: 4px;
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.entry__title {
  font-size: clamp(38px, 7.5vh, 58px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0.14em;
  margin-left: 0.14em;
}

.entry__name {
  font-size: 13px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  margin-left: 0.34em;
  color: var(--vermilion);
}

.entry__line {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.is-walking .entry {
  opacity: 0;
  transform: translateY(-8px);
}

/* ---- keys ------------------------------------------------------------------------------------- */

kbd {
  font: inherit;
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.25em;
  margin: 0 1px;
  text-align: center;
  font-size: 0.92em;
  border: 1px solid var(--ink);
  box-shadow: 0 1px 0 var(--ink);
  border-radius: 2px;
  background: var(--paper);
}

/* sits above the clock's height so the two never meet, even on a middling screen */
.keys {
  position: absolute;
  left: 14px;
  bottom: 150px;
  margin: 0;
  padding: 7px 12px;
  font-size: 12.5px;
  line-height: 1.7;
  display: grid;
}

.keys__touch,
.stick,
.clock__hours {
  display: none;
}

/* ---- the thing being looked at ---------------------------------------------------------------- */

.gaze {
  position: absolute;
  left: 50%;
  top: 56%;
  transform: translate(-50%, 0);
  max-width: min(70vw, 360px);
  padding: 7px 12px 8px;
  opacity: 0;
  transition: opacity 0.25s ease;
  display: grid;
  row-gap: 2px;
}

.gaze.is-shown {
  opacity: 1;
}

.gaze__name {
  font-size: 14.5px;
  font-weight: 600;
}

.gaze__note {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* ---- the clock -------------------------------------------------------------------------------- */

.clock {
  position: absolute;
  left: 12px;
  right: var(--corner);
  bottom: 12px;
  width: min(100%, 470px);
  margin: 0 auto;
  padding: 8px 12px 10px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  column-gap: 12px;
  row-gap: 8px;
}

.clock__run {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
}

.clock__run svg {
  fill: var(--paper);
}

.clock__run:hover {
  background: var(--vermilion);
  border-color: var(--vermilion);
}

.clock__run .clock__icon--play,
.clock.is-paused .clock__run .clock__icon--pause {
  display: none;
}

.clock.is-paused .clock__run .clock__icon--play {
  display: block;
  margin-left: 1px;
}

.clock__reading {
  display: grid;
  line-height: 1.1;
}

.clock__time {
  font-size: 25px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.clock__hour {
  font-size: 11.5px;
  color: var(--ink-soft);
}

.clock__speed {
  justify-self: end;
  padding: 4px 9px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 2px;
  cursor: pointer;
}

.clock__speed:hover {
  background: var(--paper-shade);
}

.clock__strip {
  grid-column: 1 / -1;
  position: relative;
  height: 64px;
  margin-top: 4px;
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none;
}

.clock__sky {
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  height: 10px;
  border: 1px solid var(--ink);
}

.clock__ticks {
  position: absolute;
  left: 0.5px;
  right: 0.5px;
  top: 6px;
  height: 10px;
  display: flex;
  justify-content: space-between;
}

.clock__ticks i {
  width: 1px;
  height: 100%;
  background: var(--ink);
  opacity: 0.35;
}

.clock__presets {
  position: absolute;
  inset: 0;
}

.preset {
  position: absolute;
  top: 0;
  width: 0;
  height: 20px;
  overflow: visible;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
}

/* Labels that would collide take turns on a lower line. */
.preset::after {
  content: attr(data-name);
  position: absolute;
  top: 24px;
  left: 0;
  transform: translateX(-50%);
  width: max-content;
  font-size: 11.5px;
  line-height: 1;
  color: var(--ink-soft);
  padding: 3px 2px;
}

.preset[data-line="1"]::after {
  top: 37px;
}

.preset[data-line="2"]::after {
  top: 50px;
}

.preset:first-child::after {
  transform: none;
}

.preset.is-near::after,
.preset:hover::after {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.clock__sun {
  position: absolute;
  top: 7px;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--vermilion);
  border: 1px solid var(--ink);
}

.clock__sun.is-night {
  background: #e9e3d3;
}

/* ---- thumbs ----------------------------------------------------------------------------------- */

@media (pointer: coarse), (max-width: 720px) {
  :root {
    --corner: 12px;
  }

  .keys__mouse,
  .keys kbd {
    display: none;
  }

  .keys__touch {
    display: inline;
  }

  .stick {
    display: block;
    position: absolute;
    left: 16px;
    bottom: 128px;
    width: 108px;
    height: 108px;
    border-radius: 50%;
    background: var(--paper);
    border: 1px solid var(--ink);
    box-shadow: 3px 3px 0 var(--ink);
    pointer-events: auto;
    touch-action: none;
  }

  .stick__knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border-radius: 50%;
    background: var(--ink);
  }

  .clock {
    right: 44px;
    padding: 6px 10px 8px;
    column-gap: 8px;
  }

  .clock__speed {
    padding: 6px 8px;
    min-height: 32px;
  }

  .clock__strip {
    height: 20px;
  }

  .keys {
    bottom: 96px;
  }

  .preset::after {
    display: none;
  }

  .preset {
    height: 20px;
    width: 28px;
    margin-left: -14px;
  }

  .clock__hours {
    display: block;
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    padding: 7px 12px;
    background: var(--paper);
    border: 1px solid var(--ink);
    box-shadow: 3px 3px 0 var(--ink);
    font-size: 13px;
    cursor: pointer;
  }

  .clock__sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 6px);
    display: none;
    padding: 6px;
    background: var(--paper);
    border: 1px solid var(--ink);
    box-shadow: 3px 3px 0 var(--ink);
    pointer-events: auto;
  }

  .clock.is-open .clock__sheet {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .clock.is-open .clock__hours {
    display: none;
  }

  .sheet__hour {
    min-height: 44px;
    padding: 6px 4px;
    font-size: 12.5px;
    line-height: 1.25;
    background: transparent;
    border: 1px solid var(--ink);
    cursor: pointer;
    display: grid;
    align-content: center;
    row-gap: 2px;
  }

  .sheet__hour small {
    font-size: 11px;
    color: var(--ink-soft);
  }

  .sheet__hour.is-current {
    background: var(--ink);
    color: var(--paper);
  }

  .sheet__hour.is-current small {
    color: var(--paper-shade);
  }

  .entry {
    left: 50%;
    top: 12%;
    transform: translateX(-50%);
    padding: 14px 18px 16px;
  }

  .is-walking .entry {
    transform: translate(-50%, -8px);
  }

  .entry__line {
    font-size: 13.5px;
  }

  .mark {
    display: none;
  }
}

@media (max-width: 420px) {
  .keys {
    display: none;
  }
}

/* ---- shown small in a frame, before anyone clicks ---------------------------------------------- */

/* The catalogue's peek opens the village in a small frame with no one at the controls: the picture,
   the village's name and a small clock are what it should hold. */
.is-peek .entry,
.is-peek .keys,
.is-peek .stick,
.is-peek .gaze,
.is-peek .clock__hours,
.is-peek .clock__sheet,
.is-peek .clock__presets {
  display: none;
}

.is-peek .mark {
  display: flex;
}

.is-peek .clock {
  left: 10px;
  right: auto;
  bottom: 10px;
  width: min(calc(100% - 76px), 280px);
  margin: 0;
  padding: 5px 8px 6px;
  column-gap: 8px;
  row-gap: 5px;
  box-shadow: 2px 2px 0 var(--ink);
}

.is-peek .clock__run {
  width: 24px;
  height: 24px;
}

.is-peek .clock__time {
  font-size: 17px;
}

.is-peek .clock__hour {
  font-size: 9.5px;
}

.is-peek .clock__speed {
  white-space: nowrap;
  min-height: 0;
  padding: 3px 6px;
  font-size: 10px;
}

.is-peek .clock__strip {
  height: 12px;
}

/* ---- quiet and still -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  #scene,
  .entry,
  .gaze {
    transition: none;
  }
}

.fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 17px;
  line-height: 1.5;
}

.fallback[hidden] {
  display: none;
}
