:root {
  --bg: #f7f7f5;
  --text: #1f1d1a;
  --muted: #5f5a52;
  --card: #ffffff;
  --line: #cfd3dc;
  --accent: #2f46c8;
  --on-accent: #ffffff;
  --star-on: #b45309;
  --star-off: #c9ced8;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --text: #e9ecf2;
    --muted: #9aa3b5;
    --card: #171b24;
    --line: #333b4d;
    --accent: #8fa2ff;
    --on-accent: #0f1218;
    --star-on: #fbbf24;
    --star-off: #3b4356;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.page {
  max-width: 460px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

/* Read-only average: the filled part of the gradient is clipped to the star shapes. */
.average {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.stars-static {
  font-size: 1.4rem;
  letter-spacing: 0.1em;
  line-height: 1;
  background: linear-gradient(
    90deg,
    var(--star-on) calc(var(--value) / 5 * 100%),
    var(--star-off) 0
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.form {
  padding: 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.legend {
  padding: 0;
  margin-bottom: 0.4rem;
  font-weight: 600;
}

/* The stars are written 1 to 5 in the HTML, in the same order as on screen, so the
   Left and Right arrow keys move the way people expect. */
.stars {
  display: inline-flex;
}

.star-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  opacity: 0;
}

.star-label {
  padding: 0.1rem 0.15rem;
  color: var(--star-off);
  font-size: 2.2rem;
  line-height: 1;
  cursor: pointer;
}

/* The checked star, and every star before it */
.star-input:checked + .star-label,
.star-label:has(~ .star-input:checked) {
  color: var(--star-on);
}

/* Hover preview: reset, then fill the star under the pointer and every star before it.
   Only for devices that really hover, so a tap on a phone does not leave stars "stuck". */
@media (hover: hover) {
  .stars:hover .star-label {
    color: var(--star-off);
  }

  .stars:hover .star-label:hover,
  .stars:hover .star-label:has(~ .star-label:hover) {
    color: var(--star-on);
  }
}

.star-input:focus-visible + .star-label {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.status {
  min-height: 1.4rem;
  margin: 0.5rem 0 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.submit {
  min-height: 2.75rem;
  padding: 0 1.4rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.submit:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
