/* The Weighing of the Heart: papyrus, lapis lazuli and gold.
   Cinzel (carved capitals) for the title and big numbers, Archivo for
   everyday text, Newsreader italic for the soft secondary lines. */

:root {
  color-scheme: light;
  --paper: #efe2c2;
  --card: #f7eed8;
  --ink: #2a2116;
  --muted: #6e5d44;
  --faint: #9c8a6c;
  --rule: #dbc9a3;
  --gold: #b9821f;
  --lapis: #1f3f73;
  --lapis-ink: #f7eed8;
  --bad: #a8361f;
  --shadow: 0 1px 2px rgba(42, 33, 22, 0.06), 0 10px 30px rgba(42, 33, 22, 0.1);
  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --sans: "Archivo", "Segoe UI", system-ui, sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  /* Papyrus sheet the questions sit on, so small text reads over the wall. */
  --sheet: rgba(247, 238, 216, 0.94);
  /* Dims the bricks outside the scale scene so the scene stands out. */
  --wall-dim: rgba(70, 45, 12, 0.12);
  /* Laid over the brick wall: lit from above the scale, darker at the edges
     and towards the bottom of the page. */
  --wall-shade:
    radial-gradient(130% 70% at 50% 22%, rgba(255, 248, 230, 0.4) 0%, rgba(255, 248, 230, 0) 50%),
    radial-gradient(150% 110% at 50% 30%, rgba(90, 60, 20, 0) 55%, rgba(90, 60, 20, 0.22) 100%),
    linear-gradient(rgba(90, 60, 20, 0) 40%, rgba(90, 60, 20, 0.1) 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #12161f;
    --card: #1a2030;
    --ink: #efe2c2;
    --muted: #b9a988;
    --faint: #8a7d66;
    --rule: #2e3548;
    --gold: #e0ad4a;
    --lapis: #6f95d6;
    --lapis-ink: #0f1420;
    --bad: #ee8a6c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.4);
    --sheet: rgba(26, 32, 48, 0.94);
    --wall-dim: rgba(0, 0, 0, 0.28);
    --wall-shade:
      radial-gradient(130% 70% at 50% 22%, rgba(255, 210, 140, 0.06) 0%, rgba(255, 210, 140, 0) 50%),
      radial-gradient(150% 110% at 50% 30%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.45) 100%),
      linear-gradient(rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, 0.2) 100%);
  }
}

* {
  box-sizing: border-box;
}

/* Every rem size scales from this; raise or lower it to resize all page text. */
html {
  font-size: 20px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
}

main {
  padding: 40px 0 64px;
}

/* Text sits in a centred column; the scale runs the full page width. */
.top,
.panel {
  width: min(100% - 32px, 900px);
  margin-left: auto;
  margin-right: auto;
}

button {
  font: inherit;
  cursor: pointer;
}

/* ---- Header ---- */

.top {
  text-align: center;
}

.wordmark {
  margin: 0 0 22px;
  font-family: var(--display);
  font-stretch: 125%;
  font-weight: 700;
  font-size: clamp(1.8rem, 9.5vw, 5rem);
  letter-spacing: 0.06em;
  line-height: 1;
}

.dateline {
  margin: 22px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Only shown when the puzzle won't load. */
.top .dateline[hidden] {
  display: none;
}

.top .dateline {
  display: inline-block;
  margin: 10px 0 22px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--sheet);
}

.aim {
  color: var(--faint);
  font-family: var(--serif);
  font-style: italic;
}

.icon-button {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-weight: 700;
}

/* ---- Scale ---- */

/* Edge to edge on every screen. The height is what a 900-unit-wide scene
   (both pans at full tilt) needs at this width, capped at 680px; game.js
   widens the scene to fill whatever width is left over. */
.scale-stage {
  width: 100%;
}

.scale-stage canvas {
  display: block;
  width: 100%;
  height: min(100vw * 616 / 900, 680px);
}

/* The hieroglyph banner under the scene; game.js sets its height. */
.scale-stage .frieze {
  height: 0;
}

/* ---- Panels ---- */

.panel {
  margin-top: 28px;
  padding: 22px 26px 26px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.panel[hidden] {
  display: none;
}

.status {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Question timer: a gold bar that drains, with the seconds left beside it. */
.timer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.timer[hidden] {
  display: none;
}

.timer-track {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 999px;
  background: var(--rule);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: var(--gold);
  transform-origin: left center;
  transition: transform 0.1s linear;
}

.timer-label {
  min-width: 2.6em;
  font-family: var(--display);
  font-stretch: 112%;
  font-weight: 650;
  font-size: 0.95rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.timer[data-urgent="true"] .timer-fill {
  background: var(--bad);
}

.timer[data-urgent="true"] .timer-label {
  color: var(--bad);
}

@media (prefers-reduced-motion: reduce) {
  .timer-fill {
    transition: none;
  }
}

h2 {
  margin: 18px 0 14px;
  font-family: var(--display);
  font-stretch: 112%;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

form {
  display: flex;
  gap: 10px;
}

input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
}

input[type="text"]::placeholder {
  font-family: var(--serif);
  font-style: italic;
  color: var(--faint);
}

input[type="text"]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  border-color: transparent;
}

.primary {
  min-width: 120px;
  padding: 12px 28px;
  border: 0;
  border-radius: 4px;
  background: var(--lapis);
  color: var(--lapis-ink);
  font-weight: 650;
}

.primary:hover {
  filter: brightness(1.15);
}

.primary:focus-visible,
.link-button:focus-visible,
.icon-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button:disabled,
input:disabled {
  opacity: 0.5;
  cursor: default;
}

.feedback {
  min-height: 1.5em;
  margin: 10px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
}

.feedback[data-tone="good"] {
  color: var(--gold);
}

.feedback[data-tone="bad"] {
  color: var(--bad);
}

/* "Did you mean …?" autocorrect prompt */
.suggest {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  margin-top: 10px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  background: var(--card);
}

.suggest[hidden] {
  display: none;
}

.suggest p {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
}

.suggest b {
  font-family: var(--sans);
  font-style: normal;
  font-weight: 650;
}

.suggest-weight {
  font-family: var(--sans);
  font-style: normal;
  font-weight: 650;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.suggest-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.suggest .primary {
  min-width: 0;
  padding: 8px 22px;
}

.suggest .link-button {
  margin-top: 0;
}

/* Answers so far, as small ruled chips */
.used {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.used:empty {
  display: none;
}

.used li {
  display: inline-flex;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.9rem;
}

.used li b {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* Answers the scale picked when time ran out. */
.used li.timed-out {
  border-style: dashed;
  font-style: italic;
}

.rows li.timed-out .answer {
  font-style: italic;
}

.rows .picked {
  font-family: var(--serif);
  font-size: 0.85rem;
  color: var(--faint);
}

.link-button {
  margin-top: 18px;
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- Start screen ---- */

.ready {
  text-align: center;
}

.ready h2 {
  margin-top: 4px;
}

.ready .tagline {
  margin: 0 0 20px;
}

.start-button {
  min-width: 200px;
  padding: 14px 36px;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

/* ---- Result ---- */

.result {
  text-align: center;
}

.result .dateline {
  margin-top: 0;
}

.big {
  margin: 4px 0 0;
  font-family: var(--display);
  font-stretch: 125%;
  font-size: 4.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.big small {
  font-family: var(--sans);
  font-stretch: 100%;
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
}

.result[data-outcome="bust"] #result-score,
.result[data-outcome="gave_up"] #result-score {
  color: var(--bad);
}

.result[data-perfect] #result-score {
  color: var(--gold);
}

.tagline {
  margin: 8px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--muted);
}

.small-print {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--faint);
}

/* Ruled rows: answer + question on the left, weight on the right */
.rows {
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  border-top: 1px solid var(--rule);
}

.rows li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--rule);
}

.rows .answer {
  display: block;
  font-weight: 500;
}

.rows .prompt {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
}

.rows .weight {
  font-family: var(--display);
  font-stretch: 112%;
  font-weight: 650;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.rows li.over .weight {
  color: var(--bad);
}

.scoreboard {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
  text-align: center;
}

.scoreboard h3 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-stretch: 112%;
  font-size: 1.05rem;
}

#scoreboard-place {
  margin: 0 0 16px;
}

#scoreboard-empty {
  margin: 12px 0 0;
}

.score-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0 0;
}

.score-curve {
  display: block;
  width: 100%;
  height: 132px;
  overflow: visible;
}

.score-curve-baseline {
  stroke: var(--rule);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.score-curve-fill {
  fill: color-mix(in srgb, var(--ink) 16%, transparent);
  stroke: none;
}

.score-curve-line {
  fill: none;
  stroke: color-mix(in srgb, var(--ink) 55%, transparent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.score-curve-you-line {
  stroke: var(--good);
  stroke-width: 1.5;
  stroke-dasharray: 3 4;
  opacity: 0.85;
  vector-effect: non-scaling-stroke;
}

.score-curve-you {
  fill: var(--good);
  stroke: var(--card);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.score-curve-labels {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border-top: 1px solid var(--rule);
  padding-top: 6px;
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.score-curve-labels span {
  text-align: center;
  min-height: 0.7rem;
}

.score-curve-labels .you {
  color: var(--ink);
  font-weight: 700;
}

.share-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 28px;
}

.share-row .primary {
  min-width: 170px;
}

#next {
  margin-top: 14px;
  font-size: 0.95rem;
}

/* ---- Developer tools ---- */

.dev {
  margin-top: 48px;
  border-style: dashed;
  border-color: var(--faint);
}

.dev h3 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-stretch: 112%;
  font-size: 0.95rem;
}

#dev-info {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.dev-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.dev-row button,
.dev-date input {
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
}

.dev-date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.dev details {
  margin-top: 12px;
}

.dev summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.dev-answers {
  columns: 3 160px;
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.dev-answers li.over {
  color: var(--faint);
  text-decoration: line-through;
}

/* ---- Help dialog ---- */

dialog {
  width: min(100% - 32px, 460px);
  padding: 28px;
  border: 0;
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(29, 42, 47, 0.2);
}

dialog::backdrop {
  background: rgba(29, 42, 47, 0.35);
}

dialog h2 {
  margin-top: 0;
}

dialog .lede {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--muted);
  line-height: 1.4;
}

dialog ol {
  padding-left: 20px;
  line-height: 1.55;
}

dialog ol li + li {
  margin-top: 0.45em;
}

dialog .muted {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 560px) {
  main {
    padding-top: 60px; /* Clears the fixed ? button above the title. */
  }

  .panel {
    padding: 16px 16px 20px;
  }

  html {
    font-size: 17px;
  }

  h2 {
    font-size: 1.25rem;
  }

  .big {
    font-size: 3.2rem;
  }

  form .primary {
    min-width: 0;
    padding: 12px 18px;
  }
}
