/* Sharpest: an answer sheet, a pencil and a highlighter. */

:root {
  --sheet: #d3ecdf;
  --paper: #fbfefc;
  --form: #14594a;
  --form-soft: #8dbfac;
  --graphite: #23282b;
  --lead: #566069;
  --eraser: #f59ab0;
  --highlighter: #f4f25a;
  --wood: #f1d9ae;
  --danger: #a3213f;

  --display: 'Anybody', 'Segoe UI', Tahoma, sans-serif;
  --text: 'Atkinson Hyperlegible', 'Segoe UI', Tahoma, sans-serif;
  --gutter: clamp(16px, 4vw, 48px);
  --round: 8px;
  color-scheme: light;
}

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

body {
  margin: 0;
  background: var(--sheet);
  color: var(--graphite);
  font: 400 1.0625rem/1.5 var(--text);
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
p,
ul,
ol,
fieldset {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

h1,
h2 {
  font-family: var(--display);
  font-weight: 800;
  line-height: 1.12;
  text-wrap: balance;
}

h1 {
  font-size: clamp(1.75rem, 5vw, 2.75rem);
}

h2 {
  font-size: 1.25rem;
}

a {
  color: var(--form);
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--form);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.muted {
  color: #43504f;
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---- Top bar ---- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px var(--gutter);
}

.wordmark {
  color: var(--graphite);
  font: 900 1.375rem/1 var(--display);
  font-stretch: 130%;
  text-decoration: none;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-code strong {
  font-family: var(--display);
  letter-spacing: 0.08em;
}

.offline {
  padding: 8px var(--gutter);
  background: var(--graphite);
  color: var(--paper);
}

/* ---- Buttons and fields ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 18px;
  border: 2px solid var(--form);
  border-radius: var(--round);
  background: var(--form);
  color: #fff;
  font: 700 1rem/1.2 var(--text);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: #0d4236;
}

.btn:active {
  translate: 0 1px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-big {
  min-height: 56px;
  padding-inline: 28px;
  font-size: 1.1875rem;
}

.btn-plain {
  background: var(--paper);
  color: var(--form);
}

.btn-plain:hover {
  background: #e9f6ef;
}

.btn-quiet {
  padding-inline: 8px;
  border-color: transparent;
  background: none;
  color: var(--form);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-quiet:hover {
  background: rgb(20 89 74 / 0.1);
}

label,
legend {
  font-weight: 700;
}

input:not([type='checkbox']),
textarea,
select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 2px solid var(--form);
  border-radius: var(--round);
  background: var(--paper);
  color: inherit;
  font: inherit;
}

textarea {
  display: block;
  resize: vertical;
}

::placeholder {
  color: #66756f;
}

.form-error {
  color: var(--danger);
  font-weight: 700;
}

.form-error:empty,
.question-hint:empty {
  display: none;
}

.tag {
  justify-self: center;
  padding: 4px 12px;
  border-radius: 4px;
  background: var(--graphite);
  color: var(--paper);
  font-weight: 700;
}

.highlight {
  padding: 0.05em 0.25em;
  background: linear-gradient(var(--highlighter), var(--highlighter)) 0 60% / 100% 82% no-repeat;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.notice,
.loading {
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 16px;
  width: min(100%, 36rem);
  margin: auto;
  padding: 32px var(--gutter);
}

/* ---- The pencil ---- */

.lacquer-0 { --lacquer: #ffc629; }
.lacquer-1 { --lacquer: #ff8f6b; }
.lacquer-2 { --lacquer: #79c6ee; }
.lacquer-3 { --lacquer: #a5d765; }
.lacquer-4 { --lacquer: #f7acd0; }
.lacquer-5 { --lacquer: #f3f0e4; }

.pencil {
  --size: 44px;
  display: flex;
  width: 100%;
  min-width: 0;
  height: var(--size);
}

.pencil-eraser {
  flex: none;
  width: calc(var(--size) * 0.4);
  border-radius: 6px 0 0 6px;
  background: var(--eraser);
}

.pencil-ferrule {
  flex: none;
  width: calc(var(--size) * 0.36);
  background: repeating-linear-gradient(90deg, #a9bbb3 0 3px, #dce7e2 3px 6px);
}

/* Three flat faces, like the sides of a hexagonal pencil. */
.pencil-body,
.podium-body {
  background-color: var(--lacquer);
}

.pencil-body {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  padding: 0 10px;
  background-image: linear-gradient(rgb(255 255 255 / 0.35) 0 24%, transparent 24% 76%, rgb(35 40 43 / 0.14) 76%);
}

.pencil-label {
  overflow: hidden;
  font: 700 1.0625rem/1.4 var(--display);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pencil-wood {
  position: relative;
  flex: none;
  width: calc(var(--size) * 0.85);
  background: var(--wood);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.pencil-lead {
  position: absolute;
  inset: 0 0 0 66%;
  background: var(--graphite);
}

.pencil-hero {
  --size: 64px;
  max-width: 30rem;
}

.pencil-hero .pencil-label {
  font-size: 1.375rem;
}

/* ---- Timer ---- */

.timer {
  display: flex;
  align-items: center;
  gap: 16px;
}

.timer-track {
  flex: 1;
  min-width: 0;
}

.timer-pencil {
  --size: 30px;
  --stub: calc(var(--size) * 1.61);
  width: calc(var(--stub) + (100% - var(--stub)) * var(--left, 1));
}

.timer-pencil .pencil-body {
  padding: 0;
}

.timer-number {
  min-width: 2.2ch;
  font: 900 2rem/1 var(--display);
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.timer.is-ending .timer-number {
  color: var(--danger);
}

/* ---- Question progress, printed like an answer sheet's edge marks ---- */

.marks {
  display: flex;
  gap: 5px;
}

.mark {
  flex: 1;
  max-width: 28px;
  height: 9px;
  border: 2px solid var(--graphite);
}

.mark.is-done {
  background: var(--graphite);
}

.mark.is-now {
  background: #ffc629;
}

/* ---- Answers ---- */

.bubble {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--form);
  border-radius: 50%;
  background: var(--paper);
  color: var(--form);
  font: 800 1.125rem/1 var(--display);
}

.bubble.is-filled {
  border-color: var(--graphite);
  background: var(--graphite);
  color: var(--paper);
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 12px 16px;
  border: 2px solid var(--form-soft);
  border-radius: var(--round);
  background: var(--paper);
  color: inherit;
  font: inherit;
  font-size: 1.1875rem;
  line-height: 1.3;
  text-align: start;
}

button.option {
  cursor: pointer;
  touch-action: manipulation;
}

button.option:hover:not([aria-disabled]) {
  border-color: var(--form);
}

button.option[aria-disabled] {
  cursor: default;
}

button.option[aria-disabled]:not(.is-picked) {
  background: transparent;
}

.option.is-picked {
  border-color: var(--graphite);
  box-shadow: inset 0 0 0 1px var(--graphite);
}

.option.is-right {
  border-color: var(--form);
}

.option.is-faded {
  background: transparent;
}

.option-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.option.is-right .option-text {
  font-weight: 700;
}

.option-note {
  flex: none;
  font-size: 1rem;
}

.option.has-tally {
  padding-bottom: 24px;
}

.tally {
  position: absolute;
  inset-inline: 16px;
  bottom: 9px;
  height: 6px;
  background: var(--graphite);
  transform: scaleX(var(--share));
  transform-origin: left;
}

.question-text {
  font-size: clamp(1.5rem, 4.6vw, 3rem);
  overflow-wrap: anywhere;
}

.note {
  max-width: 70ch;
  padding-inline-start: 14px;
  border-inline-start: 5px solid var(--highlighter);
}

/* ---- Home ---- */

.home {
  display: grid;
  gap: 24px;
  width: min(100%, 68rem);
  margin: auto;
  padding: 16px var(--gutter) 56px;
}

.home-title {
  font-size: clamp(2.75rem, 9.5vw, 7rem);
  font-weight: 900;
  font-stretch: 120%;
  line-height: 0.98;
}

.home-pencils {
  display: grid;
  gap: 10px;
  margin-inline-start: calc(var(--gutter) * -1);
}

.home-pencils .pencil {
  --size: clamp(30px, 5vw, 52px);
}

.lede {
  max-width: 46ch;
  font-size: 1.1875rem;
}

.join-form {
  display: grid;
  gap: 8px;
}

.join-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.join-row .code-input {
  width: 13rem;
  min-height: 56px;
  font: 800 1.625rem/1 var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---- Player ---- */

.play {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
  width: min(100%, 44rem);
  margin-inline: auto;
  padding: 4px var(--gutter) 32px;
}

.play-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-weight: 700;
}

.play-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-score {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.name-form,
.play-center {
  display: grid;
  gap: 14px;
  margin-block: auto;
}

.play-center .tag {
  justify-self: start;
}

.play-question,
.play-reveal,
.play-final {
  display: grid;
  gap: 18px;
}

.play-status {
  min-height: 1.5em;
}

.verdict {
  display: grid;
  gap: 4px;
  padding: 18px 20px;
  border-radius: var(--round);
}

.verdict.is-right {
  background: var(--form);
  color: #fff;
}

.verdict.is-wrong {
  background: var(--eraser);
}

.reveal-question,
.review-question {
  font-weight: 700;
}

.review {
  display: grid;
  gap: 18px;
}

.review li {
  display: grid;
  gap: 4px;
  padding-top: 14px;
  border-top: 2px solid var(--form-soft);
}

/* ---- Host ---- */

.host {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: clamp(16px, 3vh, 28px);
  width: min(100%, 84rem);
  margin-inline: auto;
  padding: 4px var(--gutter) 32px;
}

.host-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.answered {
  margin-inline-end: auto;
  font: 700 1.25rem/1.3 var(--display);
}

.lobby {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  flex: 1;
  gap: clamp(24px, 5vw, 72px);
  align-items: start;
}

.lobby-join,
.lobby-players {
  display: grid;
  justify-items: start;
  gap: 16px;
}

.lobby-title {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  overflow-wrap: anywhere;
}

.lobby-code {
  font: 900 clamp(3rem, 8vw, 6.5rem) / 1 var(--display);
  letter-spacing: 0.04em;
}

.lobby-qr {
  width: min(100%, 220px);
  height: auto;
  border-radius: var(--round);
}

.roster {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
  gap: 10px 20px;
  width: 100%;
}

.roster li {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.roster .pencil {
  flex: 1;
}

.is-away .pencil {
  opacity: 0.45;
}

.host-ready {
  display: grid;
  gap: 24px;
  margin-block: auto;
  text-align: center;
}

.host-ready .question-text {
  font-size: clamp(2rem, 6vw, 5rem);
}

.host-question,
.host-standings,
.host-final {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: clamp(16px, 3vh, 28px);
}

.options-host {
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: auto;
}

.options-host .option {
  min-height: clamp(80px, 14vh, 130px);
  padding-inline: 20px;
  font-size: clamp(1.1875rem, 2.1vw, 1.875rem);
}

.options-host .bubble {
  width: 3.25rem;
  height: 3.25rem;
  font-size: 1.5rem;
}

.host .note {
  font-size: 1.1875rem;
}

.scores {
  display: grid;
  gap: 10px;
}

.scores li {
  display: grid;
  grid-template-columns: 2.5ch minmax(0, 1fr) 6.5ch 8.5ch;
  align-items: center;
  gap: 14px;
}

.score-rank,
.score-total {
  font: 800 1.25rem/1 var(--display);
  font-variant-numeric: tabular-nums;
}

.score-total {
  text-align: end;
}

.pencil-score {
  min-width: 9rem;
  max-width: 100%;
  transition: width 0.9s cubic-bezier(0.3, 0.9, 0.3, 1);
}

.host-standings .host-actions {
  margin-top: auto;
}

.podium {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 12rem));
  justify-content: center;
  align-items: end;
  gap: clamp(10px, 4vw, 56px);
  height: clamp(340px, 58vh, 560px);
  border-bottom: 4px solid var(--graphite);
  overflow: hidden;
}

.podium-place {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  justify-items: center;
  height: calc(100% * var(--height));
  min-height: 200px;
  text-align: center;
  animation: rise 0.8s cubic-bezier(0.2, 0.9, 0.3, 1) var(--wait) backwards;
}

.is-settled .podium-place {
  animation: none;
}

.podium-name {
  max-width: 100%;
  font: 800 clamp(1.0625rem, 2.2vw, 1.625rem) / 1.2 var(--display);
  overflow-wrap: anywhere;
}

.podium-score {
  margin-bottom: 8px;
}

.podium-pencil {
  --width: clamp(60px, 11vw, 110px);
  display: flex;
  flex-direction: column;
  width: var(--width);
  min-height: 0;
  height: 100%;
}

.podium-wood {
  position: relative;
  flex: none;
  height: calc(var(--width) * 0.8);
  background: var(--wood);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.podium-lead {
  position: absolute;
  inset: 0 0 66%;
  background: var(--graphite);
}

.podium-body {
  flex: 1;
  background-image: linear-gradient(90deg, rgb(255 255 255 / 0.35) 0 24%, transparent 24% 76%, rgb(35 40 43 / 0.14) 76%);
}

@keyframes rise {
  from {
    transform: translateY(110%);
  }
}

.final-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
  gap: 40px;
  padding-top: 16px;
}

.final-details section {
  display: grid;
  align-content: start;
  gap: 16px;
}

/* ---- Quiz library and editor ---- */

.library,
.editor {
  display: grid;
  gap: 18px;
  width: min(100%, 56rem);
  margin-inline: auto;
  padding: 16px var(--gutter) 64px;
}

.library-head,
.quiz-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.quiz-row {
  padding-block: 18px;
  border-top: 2px solid var(--form-soft);
}

.quiz-info {
  flex: 1 1 14rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.editor .title-input {
  font: 800 1.5rem/1.2 var(--display);
}

.question-list {
  display: grid;
  gap: 20px;
}

.question-card {
  display: grid;
  gap: 10px;
  padding: clamp(16px, 3vw, 24px);
  border-radius: var(--round);
  background: var(--paper);
}

.question-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
}

.question-tools h2 {
  margin-inline-end: auto;
}

.answer-fields {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 0;
}

.answer-fields legend {
  margin-bottom: 8px;
  padding: 0;
}

.answer-field {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bubble-check {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

.bubble-check input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.bubble-check input:checked + .bubble {
  border-color: var(--graphite);
  background: var(--graphite);
  color: var(--paper);
}

.bubble-check input:focus-visible + .bubble {
  outline: 3px solid var(--form);
  outline-offset: 2px;
}

.question-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.question-hint {
  color: var(--danger);
}

.editor-add {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.editor-host {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.paste-dialog {
  width: min(100% - 32px, 40rem);
  padding: clamp(16px, 4vw, 28px);
  border: 0;
  border-radius: var(--round);
  background: var(--paper);
  color: inherit;
}

.paste-dialog[open] {
  display: grid;
  gap: 12px;
}

.paste-dialog::backdrop {
  background: rgb(13 45 37 / 0.6);
}

/* ---- Small screens ---- */

@media (max-width: 720px) {
  .lobby,
  .options-host {
    grid-template-columns: minmax(0, 1fr);
  }

  .options-host .option {
    min-height: 68px;
  }

  .scores li {
    grid-template-columns: 2ch minmax(0, 1fr) 6.5ch;
    gap: 8px;
  }

  .score-extra {
    display: none;
  }

  .topbar-end {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .podium-place {
    animation: none;
  }

  .pencil-score {
    transition: none;
  }
}
