/*
 * Cross-device finishing layer. Bundles the Hyd Ubuntu face (three weights from the fonts folder) and the
 * --desktop-font tokens the rest of the site reads; draws small control marks (play, pause, previous, next) as
 * CSS geometry instead of text glyphs or colour emoji; keeps editable fields at 16px so iOS Safari does not
 * zoom in; sets readable-contrast colours; and sizes the sound deck and pickers for touch. Several rules here
 * use !important on purpose; each group says why where it appears.
 */

/* Locally bundled classic Ubuntu: the same smooth desktop lettering on every device. */
@font-face {
  font-family: 'Hyd Ubuntu';
  src: url('fonts/ubuntu-latin-400-normal.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Hyd Ubuntu';
  src: url('fonts/ubuntu-latin-500-normal.woff2') format('woff2');
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: 'Hyd Ubuntu';
  src: url('fonts/ubuntu-latin-700-normal.woff2') format('woff2');
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

/* Font stacks are read everywhere as var(--desktop-font). All three tokens are the same stack today.
   --px is one sixteenth of the root size: text written calc(N * var(--px)) is N px at the default 16 px root and
   grows when the visitor asks the browser or phone for bigger text. Sheets use it for the desk’s icon labels, the
   u-turn strip, the byline, start here, recordings, the photo viewer, about, stickers, the time machine, the
   player and the four forms; the pixel wordmark, title-bar captions, icon art and the games stay in px.
   Registered as a length, --px computes to 1px at the default size, so `@container not style(--px: 1px)` holds
   only when the visitor asked for bigger text: start here’s area rows, the photo caption and the minimised
   player’s title wrap then instead of ending in an ellipsis, and the photo editor’s and time machine’s rows wrap
   (hyd-finder.css, hyd-reference-details.css, hyd-retro.css, hyd-photo-lab.css, hyd-time-machine.css). */
@property --px {
  syntax: '<length>';
  inherits: true;
  initial-value: 1px;
}

:root {
  --desktop-font: 'Hyd Ubuntu',Tahoma,'Lucida Grande',Arial,sans-serif;
  --desktop-label-font: 'Hyd Ubuntu',Tahoma,'Lucida Grande',Arial,sans-serif;
  --desktop-lettering: 'Hyd Ubuntu',Tahoma,'Lucida Grande',Arial,sans-serif;
  --px: 0.0625rem;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--desktop-font);
}

html[data-theme] :is(button, input, select, textarea),
html[data-theme]
  #world
  :is(
    .portal-brand h1,
    .manad-byline,
    .screen-corner,
    .player-app,
    .route-title,
    .route-caption,
    .deck-display b,
    .deck-display span,
    .mini-track,
    .desktop-status
  ) {
  /*
   * !important: many component rules in other sheets use the font shorthand with their own families (Tahoma,
   * Arial and so on), which would otherwise replace the bundled face on controls and these labels.
   */
  font-family: var(--desktop-font) !important;
}

html[data-theme] #world #home .desktop-icons > button > b {
  /*
   * !important (background and shadow): icon captions get no chip behind them, even where wallpaper rules such
   * as hyd-photo-wallpaper.css set one.
   */
  background: transparent !important;
  box-shadow: none !important;
  border: 0;
  color: var(--wallpaper-label-color,#fff);
  text-shadow: var(--wallpaper-label-shadow,0 1px 3px #000);
  border-radius: 0;
}

html[data-theme] #world #home .desktop-icons > button:focus-visible {
  outline: 2px solid #bfdcf3;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Draw small functional marks as geometry, never colour emoji. */
html[data-theme] #world .manad-byline > span {
  display: inline-block;
  position: relative;
  width: 11px;
  height: 11px;
  font-size: 0;
  vertical-align: baseline;
  margin-left: 3px;
}

#world .manad-byline > span:before {
  content: '';
  position: absolute;
  right: 1px;
  top: 1px;
  width: 7px;
  height: 7px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
}

#world .manad-byline > span:after {
  content: '';
  position: absolute;
  width: 11px;
  height: 1.5px;
  left: 0;
  top: 5px;
  background: currentColor;
  transform: rotate(-45deg);
}

html[data-theme] #world #home .wallpaper-switch {
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
  box-sizing: border-box;
  overflow: hidden;
}

html[data-theme] #world #home .wallpaper-switch > span {
  display: block;
  width: 13px;
  height: 13px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  font-size: 0;
  line-height: 1;
  border: 1px solid currentColor;
  background: repeating-linear-gradient(45deg, transparent 0 2px, currentColor 2px 3px);
  transform: none;
  translate: none;
}

/* Button text remains for accessibility. Absolutely positioned geometry avoids
   WebKit's native button content box and anonymous grid-text rows shifting it. */
html[data-theme] #world #home .entry-play {
  position: relative;
  display: block;
  /*
   * !important: font-size 0 hides the text label (kept in the markup for accessibility) so only the drawn
   * symbol shows, over any text size other rules give the button.
   */
  font-size: 0 !important;
  line-height: 0;
}

html[data-theme] #world #cinema :is(#previous-memory, #play-small, #skip-memory, #play-preview) {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  padding: 0;
  line-height: 0;
  /*
   * !important: same purpose as the entry play button above. The player transport sets a text size of its own
   * in hyd-player-layout.css (22px), which this overrides.
   */
  font-size: 0 !important;
}

html[data-theme] #world #cinema :is(#previous-memory, #play-small, #skip-memory) {
  position: relative;
}

html[data-theme] #world #home .entry-play:before,
html[data-theme]
  #world
  #cinema
  :is(#previous-memory, #play-small, #skip-memory, #play-preview):before {
  content: '';
  position: absolute;
  inset: auto;
  left: 50%;
  top: 50%;
  display: block;
  margin: 0;
  translate: none;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  pointer-events: none;
}

html[data-theme] #world #home .entry-play:before,
html[data-theme] #world #cinema :is(#play-small, #play-preview):before {
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-right: 0;
  border-left: 9px solid currentColor;
  transform: translate(calc(-50% + 1px), -50%);
}

html[data-theme] #world #home .entry-play:before {
  border-top-width: 5px;
  border-bottom-width: 5px;
  border-left-width: 8px;
}

html[data-theme] #world #cinema :is(#play-small, #play-preview)[aria-label^='Pause']:before {
  width: 10px;
  height: 13px;
  border: 0;
  border-inline: 3px solid currentColor;
  transform: translate(-50%, -50%);
}

html[data-theme] #world #cinema :is(#previous-memory, #skip-memory):before {
  width: 8px;
  height: 8px;
  border: 0;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translate(calc(-50% + 1px), -50%) rotate(45deg);
}

html[data-theme] #world #cinema #skip-memory:before {
  transform: translate(calc(-50% - 1px), -50%) rotate(225deg);
}

html[data-theme] #world #cinema .transport .auto-next input {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  width: 15px;
  height: 15px;
  min-width: 15px;
  margin: 0;
  border: 1px solid #788995;
  border-radius: 3px;
  background: linear-gradient(#fff, #d4dde4);
}

html[data-theme] #world #cinema .transport .auto-next input:checked {
  background: #567f9d;
  border-color: #426780;
}

html[data-theme] #world #cinema .transport .auto-next input:checked:after {
  content: '';
  width: 7px;
  height: 4px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg);
  margin-top: -2px;
}

/* Phone widths: entry window, wallpaper switch and the player action row. */
@media (max-width: 620px) {
  html[data-theme] #world #home .mobile-desktop .wallpaper-switch {
    top: 5px;
    right: 6px;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
  }

  html[data-theme] #world #home .mobile-desktop #desk-entry .visual-entry {
    grid-template-columns: minmax(90px, 0.72fr) minmax(0, 1.28fr);
    gap: 8px;
    padding: 9px 8px;
  }

  html[data-theme] #world #home .mobile-desktop .visual-entry .shuffle-object {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 11px;
    min-width: 0;
    width: 100%;
    padding: 8px 0;
    text-align: center;
  }

  html[data-theme] #world #home .mobile-desktop .visual-entry .shuffle-object b {
    display: block;
    width: 100%;
    margin: 0;
    text-align: center;
    font-size: calc(12 * var(--px));
    line-height: 1.35;
    text-wrap: balance;
  }

  html[data-theme] #world #home .mobile-desktop .visual-entry .shuffle-art {
    display: grid;
    place-items: center;
    width: 70px;
    height: 70px;
    flex: 0 0 70px;
    margin: 0;
    transform: none;
  }

  html[data-theme] #world #home .mobile-desktop .visual-entry .shuffle-art svg {
    display: block;
    width: 70px;
    height: 70px;
    margin: 0;
    translate: none;
  }

  html[data-theme] #world #home .mobile-desktop .entry-play {
    width: 46px;
    height: 28px;
    min-height: 28px;
    margin: 0;
    padding: 0;
  }

  /* A portrait window can be much narrower than the viewport. Let each action
    occupy a full row instead of squeezing two fixed labels into half a row. */
  html[data-theme] #world #cinema .player-extras {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
    padding: 9px;
  }

  html[data-theme]
    #world
    #cinema
    .player-extras
    :is([data-random], [data-player-return], .collection-link, .deck-launch) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 44px;
    height: 44px;
    padding: 7px 9px;
    line-height: 1.25;
    font-size: calc(12 * var(--px));
    text-align: center;
    white-space: normal;
    overflow-wrap: normal;
    grid-column: 1;
    grid-row: auto;
  }

  html[data-theme] #world #cinema .player-extras .journey-volume {
    grid-column: 1;
    grid-row: auto;
    justify-content: center;
    flex-wrap: wrap;
    gap: 7px;
    margin: 0;
    min-width: 0;
  }

  html[data-theme] #world #cinema .transport {
    padding: 8px;
    gap: 7px;
  }
}

html[data-theme] #world #home .portal-brand .manad-byline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: max-content;
  max-width: calc(100% - 32px);
  /* normal, not nowrap: in bigger text the byline wraps inside the title block instead of running off it. */
  white-space: normal;
}

html[data-theme] #world #home .portal-brand .manad-byline > span {
  flex: 0 0 11px;
  margin: 0;
  inset: auto;
}

/* The boot screen uses the same bundled face. */
#hyd-boot.hyd-boot,
#hyd-boot .hyd-boot-bar {
  font-family: var(--desktop-font);
}

/* Keep editable fields at Safari's non-zooming size, including touch tablets and landscape phones. */
@media (max-width: 620px), (any-pointer: coarse) {
  html[data-theme]
    :is(#world, dialog, .sound-deck, .uturn-question)
    :is(
      input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not(
          [type='hidden']
        ):not([type='button']):not([type='submit']):not([type='reset']):not([type='image']):not(
          [type='color']
        ),
      textarea,
      select
    ) {
    /*
     * !important: other sheets size individual fields below 16px (for example 11px and 13px in hyd-finder.css);
     * this floor has to hold for all of them.
     */
    font-size: calc(16 * var(--px)) !important;
  }

  /* The games keep px type, so their fields keep the plain 16px floor. */
  html[data-theme]
    :is(#hyd-solitaire, #hyd-bookcricket, #hyd-flyovers, #hyd-pinball, #hyd-jaali)
    :is(
      input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not(
          [type='hidden']
        ):not([type='button']):not([type='submit']):not([type='reset']):not([type='image']):not(
          [type='color']
        ),
      textarea,
      select
    ) {
    /* !important: the same floor as above, which is !important. */
    font-size: 16px !important;
  }
}

/* Window symbols use centered vectors, independently of text font metrics. */
html[data-theme] #world #cinema :is(#expand-screen, #close-player) {
  position: relative;
}

html[data-theme] #world #cinema :is(#expand-screen, #close-player) > svg {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 16px;
  height: 16px;
  margin: 0;
  transform: translate(-50%, -50%);
  display: block;
}

/* Keep map copy on the bundled UI face, including popup contents. */
html[data-theme]
  .leaflet-container
  :is(
    .leaflet-popup-content,
    .leaflet-popup-content button,
    .leaflet-popup-content small,
    .leaflet-popup-content p
  ) {
  /* !important: same reason as the first font-family rule at the top of this file. */
  font-family: var(--desktop-font) !important;
}

/* Readable silver/blue controls retain the site's existing palette. */
html[data-theme] #world #desktop-reset {
  /*
   * !important colours: readability fixes that theme tokens and component rules must not change. The same
   * applies to the placeholder, byline, service status and icon caption colours below.
   */
  color: #25313e !important;
  text-shadow: none;
}

html[data-theme] #world :is(#area-search, #route-from)::placeholder {
  color: #566675 !important;
  opacity: 1;
}

html[data-theme] #world #places .memory-mode-switch button[aria-pressed='true'],
html[data-theme] #credits-dialog .site-info-tabs button[aria-selected='true'],
html[data-theme] #world .photo-inline-presets button[aria-pressed='true'] {
  background: linear-gradient(#496a8c, #304e6e);
  color: #fff;
}

html[data-theme] #world #places .map-notes-count {
  color: #324a60;
  opacity: 1;
}

html[data-theme] #credits-dialog .site-info-close {
  color: #481c1c;
}

html[data-theme] #world .manad-byline {
  background: #2b2430e8;
  border-radius: 3px;
  padding: 3px 8px;
  color: #fff !important;
  text-shadow: none;
}

html[data-theme] #world .uturn-service-status {
  color: #241b2b !important;
  background: #f1e5ed;
  padding: 2px 5px;
  border-radius: 2px;
}

html[data-theme] #world #home .desktop-icons > button > b {
  /*
   * !important: icon caption ink and outline shadow stay legible on every wallpaper. They win over the
   * --wallpaper-label-* values set earlier in this file and over the theme caption tokens in hyd-theme.css.
   */
  color: #fff !important;
  text-shadow:
    -1px -1px 0 #211925,
    1px -1px 0 #211925,
    -1px 1px 0 #211925,
    1px 1px 0 #211925,
    0 2px 2px #211925 !important;
}

html[data-theme] :is(.uturn-question, .desktop-preferences) input::placeholder {
  color: #c5c1ca;
  opacity: 1;
}

/* Secondary UI copy uses the same bundled face as the primary controls. Display
   titles and postcard handwriting keep their separately approved fonts. */
html[data-theme]
  :is(
    #sound-deck .deck-title,
    #sound-deck .deck-controls label,
    #sound-deck .deck-footnote,
    #sound-deck .music-provider-note,
    #sound-deck .visualizer-status,
    #sound-deck .visualizer-label,
    #sound-deck .audio-picker,
    #hyd-map-note .map-note-preview,
    #area-map .map-note-popup .map-note-public-text,
    #world .desk-video-label small,
    #world .about-manad p
  ) {
  /* !important: same reason as the first font-family rule at the top of this file. */
  font-family: var(--desktop-font) !important;
}

/* Touch: 44px minimum targets in the sound deck. */
@media (pointer: coarse) {
  html[data-theme] #sound-deck :is(button, select, .audio-picker) {
    min-width: 44px;
    min-height: 44px;
    height: auto;
    box-sizing: border-box;
  }

  html[data-theme] #sound-deck #close-deck {
    width: 44px;
    height: 44px;
    padding: 0;
    flex: 0 0 44px;
  }

  html[data-theme] #sound-deck .deck-title {
    min-height: 54px;
    box-sizing: border-box;
  }
}

/* Touch: taller selects; the chevron is drawn with gradients because the native arrow is removed. */
@media (pointer: coarse) {
  html[data-theme] #sound-deck #music-source {
    height: 44px;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 28px;
    background:
      linear-gradient(45deg, transparent 50%, #294c6b 50%) calc(100% - 14px) 50%/5px 5px no-repeat,
      linear-gradient(135deg, #294c6b 50%, transparent 50%) calc(100% - 9px) 50%/5px 5px no-repeat,
      linear-gradient(#fff, #dae5ef);
  }

  html[data-theme] #hyd-place-notebook :is(#pn-date-precision, #pn-month) {
    min-height: 44px;
    /* auto, not 44px: the 44px floor holds and bigger text makes the field taller. */
    height: auto;
  }

  html[data-theme] #hyd-place-notebook #pn-date-precision {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 24px;
    background:
      linear-gradient(45deg, transparent 50%, #294c6b 50%) calc(100% - 14px) 50%/5px 5px no-repeat,
      linear-gradient(135deg, #294c6b 50%, transparent 50%) calc(100% - 9px) 50%/5px 5px no-repeat,
      #fcfdfe;
  }
}
