/* Watching Paintings - website. Colours are the Roku app's. */

:root {
  --purple: #B46CFF;      /* artist, titles */
  --lilac: #CFA6FF;       /* title, list rows */
  --dim: #9A72D6;         /* date and source, hints */
  --mv: #C9A0FF;          /* movement line */
  --panel: rgba(14, 7, 22, 0.95);
  --rowFocus: #D9BEFF;
  --rowFocusText: #26083F;
  --band: rgba(0, 0, 0, 0.816);
  --cream: #D8CCA8;

  --padX: clamp(16px, 4.7vw, 90px);
  --fArtist: clamp(20px, min(2.2vw, 3.9vh), 46px);
  --fTitle: clamp(17px, min(1.75vw, 3.1vh), 36px);
  --fSmall: clamp(14px, min(1.4vw, 2.5vh), 28px);
  --fToast: clamp(16px, min(1.65vw, 2.9vh), 34px);
  --fRow: clamp(17px, min(1.6vw, 2.8vh), 32px);
  --rowH: clamp(46px, 5.6vh, 64px);
}

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

button { font: inherit; }

/* ---------- the painting ---------- */

body.calm #stage { cursor: none; }

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background: #000;
  cursor: default;
}

#frame {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#frame img {
  position: absolute;
  display: block;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

#frame img.detail {
  /* placed in painting coordinates by the script */
  width: auto;
  height: auto;
}

/* ---------- title screen ---------- */

/* David's title picture, whole, on black (the picture's own black, so its edges never show), above
   everything else until it fades into the first painting */
#splash {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.8s ease;
  touch-action: none;  /* a swipe on the title arrives as a swipe (it skips the title) */
}
#splash.gone { opacity: 0; pointer-events: none; }

#titleImg {
  display: block;
  width: auto;
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Only for a slow start or a problem: comes up after 4 s */
#splashStatus {
  position: absolute;
  bottom: 3vh;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--dim);
  font-size: var(--fSmall);
  white-space: pre-line;
  padding: 0 var(--padX);
  text-shadow: 0 0 6px #000, 2px 2px 0 #000;
  opacity: 0;
  animation: statusIn 0.6s ease 4s forwards;
}
@keyframes statusIn { to { opacity: 1; } }

/* ---------- caption and explanation ---------- */

#info {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
  pointer-events: none;
}

#caption, #explain {
  background: var(--band);
  padding: clamp(10px, 2.2vh, 26px) var(--padX) clamp(12px, 2.6vh, 30px);
  pointer-events: none; /* taps go through to the painting, which decides what they do */
}

#artistLabel, #titleLabel, #dateLabel, #movementLabel, #explainTitle, #explainText { white-space: pre-wrap; }

#explain { padding-bottom: clamp(8px, 1.6vh, 20px); }

#caption { padding-right: calc(var(--padX) + 2 * var(--ctl) + 4px); }  /* clear of the favourite and i buttons */

#artistLabel {
  color: var(--purple);
  font-weight: 700;
  font-size: var(--fArtist);
  line-height: 1.25;
}

#titleLabel {
  color: var(--lilac);
  font-size: var(--fTitle);
  line-height: 1.25;
  margin-top: 0.3em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#dateLabel {
  color: var(--dim);
  font-size: var(--fSmall);
  margin-top: 0.55em;
}

#movementLabel {
  color: var(--mv);
  font-size: var(--fSmall);
  margin-top: 0.35em;
}

#movementLabel:empty { display: none; }

#explainTitle {
  color: var(--purple);
  font-weight: 700;
  font-size: var(--fTitle);
}

#explainText {
  color: var(--lilac);
  font-size: var(--fSmall);
  line-height: 1.35;
  margin-top: 0.5em;
  max-width: 76em;
}

/* ---------- messages ---------- */

#toast {
  position: fixed;
  left: calc(3.1vw + 30px);
  top: calc(5.5vh + 10px);
  max-width: 80vw;
  color: var(--purple);
  font-size: var(--fToast);
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.85), 0 0 3px rgba(0, 0, 0, 0.75), 0 0 9px rgba(0, 0, 0, 0.55);
  z-index: 20;
  pointer-events: none;
  white-space: pre-wrap;
}

#note {
  position: fixed;
  left: 3.1vw;
  bottom: 4.6vh;
  max-width: min(68vw, 1300px);
  background: rgba(0, 0, 0, 0.784);
  padding: clamp(10px, 1.7vh, 18px) clamp(14px, 1.6vw, 30px);
  z-index: 15;
  pointer-events: none;
}

#noteLabel { color: var(--purple); font-size: var(--fTitle); }
#noteDetail { color: var(--dim); font-size: var(--fSmall); margin-top: 0.4em; }

/* ---------- buttons on the painting ---------- */

:root { --ctl: clamp(44px, 5.6vh, 60px); --edge: 6px; }

.ctl {
  position: fixed;
  width: var(--ctl);
  height: var(--ctl);
  padding: calc(var(--ctl) * 0.2);
  border: none;
  background: transparent;
  color: var(--purple);
  cursor: pointer;
  z-index: 25;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7)) drop-shadow(0 0 3px rgba(0, 0, 0, 0.6));
  touch-action: manipulation;
}

.ctl svg { display: block; width: 100%; height: 100%; }
.ctl:active { transform: scale(0.92); }
.ctl:focus { outline: none; }
.ctl:focus-visible { outline: 2px solid var(--rowFocus); outline-offset: -2px; border-radius: 8px; }
@media (hover: hover) { .ctl:hover { color: var(--lilac); } }

#fsBtn { top: max(var(--edge), env(safe-area-inset-top)); right: max(var(--edge), env(safe-area-inset-right)); }
#infoBtn { bottom: max(var(--edge), env(safe-area-inset-bottom)); right: max(var(--edge), env(safe-area-inset-right)); }

/* Favourite: left of the i button. Circle with a plus; a favourite: filled circle with a check */
#favBtn { bottom: max(var(--edge), env(safe-area-inset-bottom)); right: calc(max(var(--edge), env(safe-area-inset-right)) + var(--ctl) + 4px); }
#favBtn .favOn, .inl .favOn { display: none; }
#favBtn.on .favOn { display: inline; }
#favBtn.on .favOff { display: none; }
#favBtn.pop svg { animation: favPop 0.32s ease; }

/* Full screen: like YouTube, the buttons and words fade away a few seconds after the last tap (or,
   with a mouse, after it stops moving) and a tap brings them back. Out of full screen they stay. */
#fsBtn, #favBtn, #infoBtn, #shuffleBtn { transition: opacity 0.5s; }
body.fs.calm #fsBtn, body.fs.calm #favBtn, body.fs.calm #infoBtn, body.fs.calm #shuffleBtn, body.fs.calm .guide {
  opacity: 0;
  pointer-events: none;
}
@keyframes favPop { 40% { transform: scale(1.22); } 100% { transform: scale(1); } }

/* The menu button sits left of the full-screen button and shows for a few seconds after a touch */
#menuBtn {
  top: max(var(--edge), env(safe-area-inset-top));
  right: calc(max(var(--edge), env(safe-area-inset-right)) + var(--ctl) + 4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
#menuBtn.show { opacity: 1; pointer-events: auto; }
/* No full-screen button (iPhones): the menu button moves into the corner */
body.noFs #menuBtn { right: max(var(--edge), env(safe-area-inset-right)); }

/* Back to shuffle: top left, while in a run */
#shuffleBtn {
  position: fixed;
  top: max(var(--edge), env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  min-height: var(--ctl);
  padding: 0 clamp(8px, 1vw, 14px);
  border: none;
  background: transparent;
  color: var(--purple);
  font-size: var(--fToast);
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.85), 0 0 3px rgba(0, 0, 0, 0.75), 0 0 9px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  z-index: 25;
  touch-action: manipulation;
}
#shuffleBtn:focus { outline: none; }
#shuffleBtn:active { transform: scale(0.96); }
@media (hover: hover) { #shuffleBtn:hover { color: var(--lilac); } }

/* Messages move down a line while Back to shuffle is showing */
body.inRun #toast { top: calc(5.5vh + 10px + var(--ctl)); }

/* Swipe guides along the bottom, left and right, for the first paintings. Words only:
   touches go straight through to the painting, so swiping anywhere (even on them) works. */
.guide {
  position: fixed;
  bottom: calc(max(var(--edge), env(safe-area-inset-bottom)) + clamp(10px, 1.6vh, 18px));
  max-width: min(40vw, calc(50vw - var(--ctl) - 20px));
  padding: 0 clamp(6px, 0.8vw, 12px);
  color: var(--purple);
  font-size: var(--fToast);
  line-height: 1.25;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.85), 0 0 3px rgba(0, 0, 0, 0.75), 0 0 9px rgba(0, 0, 0, 0.55);
  white-space: pre-wrap;
  pointer-events: none;
  z-index: 22;
  transition: opacity 0.6s;
}
#guideL { left: max(10px, env(safe-area-inset-left)); text-align: left; }
#guideR { right: calc(max(var(--edge), env(safe-area-inset-right)) + 2 * var(--ctl) + 10px); text-align: right; }
.guide.gone { opacity: 0; }
/* Narrow screens (phones held upright): not enough width beside the favourite and i buttons, so the
   guides sit just above them, one at each side */
@media (max-width: 699px) {
  .guide { bottom: calc(max(var(--edge), env(safe-area-inset-bottom)) + var(--ctl) + 10px); max-width: 42vw; }
  #guideR { right: max(10px, env(safe-area-inset-right)); }
}

/* Computers: back and next at the sides, shown while the mouse moves and faded when it rests,
   like YouTube's controls */
.navArrow {
  position: fixed;
  top: 50%;
  width: clamp(48px, 5vw, 72px);
  height: clamp(76px, 12vh, 124px);
  margin-top: calc(clamp(76px, 12vh, 124px) / -2);
  padding: clamp(10px, 1.1vw, 16px) clamp(8px, 0.9vw, 14px);
  border: none;
  background: transparent;
  color: var(--purple);
  cursor: pointer;
  z-index: 24;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7)) drop-shadow(0 0 3px rgba(0, 0, 0, 0.6));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
.navArrow svg { display: block; width: 100%; height: 100%; }
.navArrow.show { opacity: 1; pointer-events: auto; }
.navArrow:active { transform: scale(0.94); }
.navArrow:focus { outline: none; }
@media (hover: hover) { .navArrow:hover { color: var(--lilac); } }
#navPrev { left: max(4px, env(safe-area-inset-left)); }
#navNext { right: max(4px, env(safe-area-inset-right)); }

/* Small icons inside the "How to use" text */
.inl { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -0.22em; color: var(--purple); }

/* ---------- panels: menu, favourites, browse ---------- */

#panelWrap {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
}

#panel {
  background: var(--panel);
  width: min(94vw, 1400px);
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: clamp(14px, 2.6vh, 34px) clamp(14px, 3vw, 60px) clamp(12px, 2vh, 26px);
}

#panel.narrow { width: min(94vw, 960px); }

#panelHead {
  display: flex;
  align-items: center;
  gap: 12px;
}

#panelTitle {
  flex: 1;
  color: var(--purple);
  font-weight: 700;
  font-size: var(--fTitle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre;
}

#panel.big #panelTitle { font-size: var(--fArtist); }

#panelHead button {
  flex: none;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--lilac);
  font-size: 26px;
  cursor: pointer;
  border-radius: 6px;
}

#panelHead button:hover, #panelHead button:focus-visible {
  background: var(--rowFocus);
  color: var(--rowFocusText);
  outline: none;
}

#panelBack { font-size: 34px !important; line-height: 1; }

#panelHint {
  color: var(--dim);
  font-size: var(--fSmall);
  margin: 0.4em 0 0.7em;
}

#panelHint:empty { display: none; }

#panelList {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  flex: 1;
  min-height: 0;
}

.row {
  display: block;
  width: 100%;
  min-height: var(--rowH);
  box-sizing: border-box;
  padding: 0.35em 0.6em;
  margin: 0 0 4px;
  border: none;
  background: transparent;
  color: var(--lilac);
  font-size: var(--fRow);
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1.3;
  white-space: pre-wrap;
}

.row:focus { outline: none; }

.row:focus-visible, .row.kbd:focus, .row.sel {
  background: var(--rowFocus);
  color: var(--rowFocusText);
}

@media (hover: hover) {
  .row:hover { background: var(--rowFocus); color: var(--rowFocusText); }
}

.row.sep {
  cursor: default;
  color: var(--dim);
  text-align: center;
  pointer-events: none;
}

/* ---------- first visit ---------- */

#hint {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

#hintBox {
  background: var(--panel);
  width: min(92vw, 900px);
  box-sizing: border-box;
  padding: clamp(18px, 3.4vh, 40px) clamp(18px, 3.4vw, 54px);
}

#hintTitle {
  color: var(--purple);
  font-weight: 700;
  font-size: var(--fArtist);
  margin-bottom: 0.6em;
}

#hintText {
  color: var(--lilac);
  font-size: var(--fRow);
  line-height: 1.5;
}

#hintText div { margin: 0.25em 0; }

#hintGo {
  color: var(--dim);
  font-size: var(--fSmall);
  margin-top: 1.2em;
}
