@font-face {
  font-family: "Instrument Serif";
  font-style: italic;
  font-display: swap;
  src: url("fonts/InstrumentSerif-Italic.woff2") format("woff2");
}

@font-face {
  font-family: "Instrument Serif";
  font-style: normal;
  font-display: swap;
  src: url("fonts/InstrumentSerif-Regular.woff2") format("woff2");
}

:root {
  --ink: #eef1f8;
  --dim: rgb(238 241 248 / 56%);
  --faint: rgb(238 241 248 / 14%);
  --night: #05060a;
  --panel: rgb(13 15 23 / 82%);
  --gold: #ffcf5a;
  --pay: #5cff9e;
  --freedom: #54a8ff;
  --purpose: #ff5686;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 58%, #10131f 0%, #080a12 46%, var(--night) 100%);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity 450ms;
}

/* A new era: the market dims and waits while the centre says what changed. */
.announcing canvas {
  opacity: 0.16;
}

.announcing .era,
.announcing .profile {
  opacity: 0;
}

#stage {
  touch-action: none;
}

p,
h1,
h2 {
  margin: 0;
}

.kicker {
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Header: the era on the left, the score on the right. Clicks pass through to the canvas. */
.hud {
  position: fixed;
  inset: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(18px, 3.4vw, 40px);
  pointer-events: none;
}

.era {
  max-width: min(30rem, 40vw);
  transition: opacity 300ms;
}

.era h1 {
  margin: 10px 0 6px;
  font-family: var(--serif);
  font-size: clamp(34px, 4.6vw, 62px);
  font-style: italic;
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: -0.01em;
}

.era.swap h1,
.era.swap .info,
.era.swap #kicker {
  animation: arrive 900ms cubic-bezier(0.2, 0.7, 0.1, 1) both;
}

.era.swap .info {
  animation-delay: 90ms;
}

/* Info panel: the algorithm, its use, its limits and the bars that change era. */
/* The text and the spacing grow with the screen. A 1280 x 720 screen gets the smallest size, so the panel clears the lower ring. */
.info {
  --text: clamp(12.5px, 0.45vw + 0.45vh + 3.5px, 17px);
  width: min(clamp(20rem, 24vw, 30rem), 100%);
  margin-top: clamp(12px, 3.4vh - 12px, 30px);
  padding: clamp(11px, 1.6vh, 18px) clamp(14px, 1.1vw, 22px) 2px;
  border: 1px solid var(--faint);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.info summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: calc(var(--text) * 0.86);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  list-style: none;
  cursor: pointer;
  pointer-events: auto;
}

.info summary::-webkit-details-marker {
  display: none;
}

.info summary::after {
  width: 6px;
  height: 6px;
  margin: 0 3px 3px;
  border: solid var(--dim);
  border-width: 0 1.5px 1.5px 0;
  content: "";
  transform: rotate(45deg);
  transition: transform 200ms;
}

.info details[open] summary::after {
  transform: translateY(3px) rotate(-135deg);
}

.info dl {
  display: grid;
  gap: clamp(9px, 2.2vh - 7px, 18px);
  margin: clamp(11px, 2vh - 4px, 18px) 0 clamp(4px, 1vh - 3px, 10px);
}

.info dt {
  color: var(--dim);
  font-size: calc(var(--text) * 0.78);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.info dd {
  margin: clamp(2px, 0.5vh - 1px, 5px) 0 0;
  color: rgb(238 241 248 / 86%);
  font-size: var(--text);
  line-height: 1.4;
}

@keyframes arrive {
  from {
    opacity: 0;
    filter: blur(10px);
    transform: translateY(10px);
  }
}

.announce {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 24px;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  cursor: pointer;
  transition: opacity 450ms, visibility 0s 450ms;
}

/* The whole screen is the button: a click anywhere continues. */
.announcing .announce {
  opacity: 1;
  visibility: visible;
  transition: opacity 450ms;
}

.continue {
  margin-top: 44px;
  padding: 6px 10px;
  border: 0;
  color: var(--dim);
  font: 600 11px var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: none;
  cursor: pointer;
}

.announce h2 {
  margin: 14px 0 26px;
  font-family: var(--serif);
  font-size: clamp(46px, 8.4vw, 118px);
  font-style: italic;
  font-weight: 400;
  line-height: 0.96;
  letter-spacing: -0.015em;
  text-shadow: 0 0 60px rgb(238 241 248 / 28%);
}

.announce .algorithm {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.announce .detail {
  max-width: 34rem;
  margin-top: 10px;
  color: rgb(238 241 248 / 78%);
  font-size: clamp(16px, 1.7vw, 22px);
  line-height: 1.4;
  text-wrap: balance;
}

.announcing .announce > * {
  @media (prefers-reduced-motion: no-preference) {
    animation: rise 800ms cubic-bezier(0.2, 0.7, 0.1, 1) both;
  }
}

.announcing .announce > :nth-child(2) {
  animation-delay: 80ms;
}

.announcing .announce > :nth-child(3) {
  animation-delay: 220ms;
}

.announcing .announce > :nth-child(4) {
  animation-delay: 300ms;
}

.announcing .announce > .continue {
  @media (prefers-reduced-motion: no-preference) {
    animation: rise 800ms 700ms cubic-bezier(0.2, 0.7, 0.1, 1) both, blink 2.4s 1.5s ease-in-out infinite;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.pips {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  pointer-events: auto;
}

.pips button {
  position: relative;
  flex: 1;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.pips button::before,
.pips button i {
  position: absolute;
  height: 2px;
  border-radius: 2px;
  content: "";
}

.pips button::before {
  inset: 10px 0 auto;
  background: var(--faint);
  transition: background 200ms;
}

.pips button:hover::before {
  background: rgb(238 241 248 / 34%);
}

.pips button i {
  top: 10px;
  left: 0;
  width: 0;
  background: var(--ink);
}

.score {
  width: min(15rem, 40vw);
  text-align: right;
}

.number {
  margin-top: 2px;
  font-family: var(--serif);
  font-size: clamp(52px, 6vw, 84px);
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}

.number small {
  margin-left: 2px;
  color: var(--dim);
  font-size: 0.42em;
}

.bar {
  position: relative;
  height: 2px;
  margin-top: 12px;
  border-radius: 2px;
  background: var(--faint);
}

.bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 2px;
  background: var(--ink);
  box-shadow: 0 0 12px rgb(238 241 248 / 70%);
}

.bar .best {
  position: absolute;
  top: -4px;
  width: 1px;
  height: 10px;
  background: var(--dim);
}

.bar .best span {
  position: absolute;
  top: 14px;
  right: -1px;
  color: var(--dim);
  font-size: 11px;
  white-space: nowrap;
}

.bar .best b {
  color: var(--ink);
  font-weight: 500;
}

.vip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
  gap: 8px;
  margin-top: 40px;
  color: var(--dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.vip i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px 2px rgb(255 207 90 / 70%);
  animation: blink 1.6s ease-in-out infinite;
}

.vip.here {
  color: var(--gold);
}

@keyframes blink {
  50% {
    opacity: 0.35;
  }
}

/* Hints: soft speech bubbles outside the triangle. main.mjs sets --x and --y. */
.tip {
  position: fixed;
  top: var(--y);
  left: var(--x);
  max-width: 17.5em;
  padding: 0.8em 1em;
  border: 1px solid var(--faint);
  border-radius: 12px;
  color: rgb(238 241 248 / 74%);
  font-size: clamp(12.5px, 0.45vw + 0.45vh + 3.5px, 16px);
  line-height: 1.4;
  background: rgb(13 15 23 / 92%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 800ms;
}

.tip.on {
  opacity: 1;
}

.tip::before {
  position: absolute;
  width: 9px;
  height: 9px;
  border: solid var(--faint);
  background: rgb(13 15 23);
  content: "";
  rotate: 45deg;
}

.tip.side {
  translate: 0 -50%;
}

.tip.side::before {
  top: calc(50% - 5px);
  left: -6px;
  border-width: 0 0 1px 1px;
}

.tip.below {
  translate: -50% 0;
}

.tip.below::before {
  top: -6px;
  left: calc(50% - 5px);
  border-width: 1px 0 0 1px;
}

/* Floating panels: the job offer and the profile. */
.panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 232px;
  padding: 16px;
  border: 1px solid var(--faint);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgb(0 0 0 / 60%);
  backdrop-filter: blur(14px);
  will-change: transform;
  transition: opacity 450ms;
}

.panel[hidden] {
  display: none;
}

.row {
  display: grid;
  grid-template-columns: 62px 1fr 28px;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  color: var(--dim);
  font-size: 12px;
}

.row output,
.row b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  text-align: right;
}

.pay {
  --trait: var(--pay);
}

.freedom {
  --trait: var(--freedom);
}

.purpose {
  --trait: var(--purpose);
}

.profile.gold .row {
  --trait: var(--gold);
}

.row .meter {
  height: 4px;
  border-radius: 4px;
  background: var(--faint);
}

.row .meter i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--trait);
  box-shadow: 0 0 10px var(--trait);
}

input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  background: none;
  cursor: pointer;
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--trait) var(--at), var(--faint) var(--at));
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--trait) var(--at), var(--faint) var(--at));
}

input[type="range"]:focus-visible,
button:focus-visible {
  border-radius: 6px;
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

input[type="range"]::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 12px var(--trait);
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 12px var(--trait);
}

.offer button {
  width: 100%;
  margin-top: 16px;
  padding: 8px;
  border: 1px solid var(--faint);
  border-radius: 9px;
  color: var(--ink);
  font: 600 12px var(--sans);
  letter-spacing: 0.14em;
  background: rgb(238 241 248 / 6%);
  cursor: pointer;
  transition: background 150ms;
}

.offer button:hover {
  background: rgb(238 241 248 / 14%);
}

.profile {
  pointer-events: none;
}

.who {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.who h2 {
  font-family: var(--serif);
  font-size: 25px;
  font-style: italic;
  font-weight: 400;
  line-height: 1;
}

.status {
  margin-top: 4px;
  color: var(--dim);
  font-size: 11px;
}

.rating {
  text-align: right;
}

#rating {
  font-family: var(--serif);
  font-size: 27px;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}

/* The last jobs: each one drawn like its ring, with the mood it left. */
.jobs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 8px;
  margin-top: 16px;
}

.jobs:empty {
  display: none;
}

.jobs .kicker {
  grid-column: 1 / -1;
  font-size: 10px;
}

.jobs figure {
  position: relative;
  display: grid;
  justify-items: center;
  margin: 0;
}

.jobs svg {
  width: 46px;
  height: 46px;
  rotate: -90deg;
}

.jobs circle {
  fill: none;
  stroke: var(--trait);
  stroke-width: 3.2;
  filter: drop-shadow(0 0 2px var(--trait));
}

.jobs span {
  position: absolute;
  top: 23px;
  font-size: 15px;
  line-height: 0;
}

.jobs figcaption {
  color: var(--dim);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.profile.gold {
  border-color: rgb(255 207 90 / 55%);
  box-shadow: 0 0 60px rgb(255 207 90 / 22%), 0 18px 60px rgb(0 0 0 / 60%);
}

.profile.gold #rating {
  color: var(--gold);
  font-size: 44px;
  line-height: 0.6;
  text-shadow: 0 0 22px rgb(255 207 90 / 80%);
}

.profile.gold #ratingNote {
  white-space: nowrap;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

@media (max-width: 640px) {
  .hud {
    gap: 12px;
  }

  .era {
    max-width: 58vw;
  }

  /* An open panel takes the full width and covers the VIP line. A closed one stays under the title. */
  .info:has(details[open]) {
    position: relative;
    z-index: 1;
    width: min(20.5rem, 100vw - 36px);
  }

  /* No room beside the triangle: every hint sits at the bottom, with no tail. */
  .tip.side,
  .tip.below {
    top: auto;
    bottom: clamp(14px, 3vh, 30px);
    left: 50%;
    width: max-content;
    max-width: calc(100vw - 48px);
    text-align: center;
    translate: -50% 0;
  }

  .tip::before {
    display: none;
  }

  .vip {
    margin-top: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .era.swap h1,
  .era.swap .info,
  .era.swap #kicker,
  .vip i {
    animation: none;
  }
}
