/* Any rule that sets `display` beats the [hidden] attribute's own
   display:none, so `.photo-row { display: flex }` left the empty photo preview
   and its Remove button on screen before a photo was ever chosen. The app
   hides several panels with .hidden = true, so fix it once here rather than
   per component. */
[hidden] {
  display: none !important;
}

:root {
  --bg: #e8eef3;
  --sheet: #ffffff;
  --ink: #152033;
  --muted: #5a6a7a;
  --line: #c3d0db;
  --accent: #0b6e6e;
  --accent-ink: #ffffff;
  --danger: #9b2c2c;
  --ok: #1f6b4a;
  --pending: #8a5a12;
  --chip: #f3f7f8;
  --wash-danger: color-mix(in srgb, var(--danger) 10%, var(--sheet));
  --wash-ok: color-mix(in srgb, var(--ok) 10%, var(--sheet));
  --wash-accent: color-mix(in srgb, var(--accent) 12%, var(--sheet));
  --focus: color-mix(in srgb, var(--accent) 45%, var(--sheet));
  --shadow: 0 10px 28px color-mix(in srgb, var(--ink) 10%, transparent);
  --radius: 14px;
  --pad: 16px;
  --gap: 12px;
  --tap: 48px;
  --max: 430px;
  --font: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.shell {
  width: min(100%, var(--max));
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--sheet);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.mast {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--gap);
  padding: 10px var(--pad);
  border-bottom: 3px solid var(--accent);
  background: var(--chip);
}

.mast-kicker,
.mast-mark {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: var(--mono);
}

.mast-mark {
  text-align: right;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--ink);
  max-width: 62%;
}

main {
  flex: 1;
  padding: 20px var(--pad) 28px;
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 8px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 20px;
  color: var(--muted);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 15px;
}

textarea {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus-visible,
.chip input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

fieldset {
  margin: 0;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
}

legend {
  font-weight: 700;
  padding: 0 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
  flex: 1 1 7.5rem;
  margin: 0;
  font-weight: 600;
}

.chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.chip span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}

.chip input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.chip input:disabled + span {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* The mark button stays in reach while the student scrolls a long question.
   It must read as a bar sitting ON TOP of the page, not as text overlapping
   text: with a fading gradient the "Take a photo of your working" label showed
   through it and looked broken on a phone. Solid fill plus a rule fixes that,
   and the extra padding under the panel keeps the last control clear of the
   bar when the page is scrolled to the bottom. */
.btn-row.sticky {
  position: sticky;
  bottom: 0;
  padding: 12px 0;
  background: var(--sheet);
  border-top: 1px solid var(--line);
}

.answer {
  padding-bottom: 8px;
}

.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 12px;
  border: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  flex: 1;
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.ghost {
  flex: 1;
  background: var(--chip);
  color: var(--ink);
  border: 1.5px solid var(--line);
}

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

.error {
  margin: 0;
  padding: 10px 12px;
  background: var(--wash-danger);
  color: var(--danger);
  border-radius: 10px;
  font-size: 15px;
}

.status {
  margin: 0;
  padding: 10px 12px;
  background: var(--wash-accent);
  color: var(--ink);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
}

.status[aria-busy="true"] {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.titleblock {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 13px;
}

.tb-q,
.tb-meta {
  margin: 0;
}

.tb-meta {
  color: var(--muted);
  text-align: right;
}

.question-panel {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1.5px solid var(--line);
}

.stem-text {
  margin: 0 0 16px;
  font-size: 1.25rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.diagram {
  margin: 0 0 16px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--chip);
}

.diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

.upload {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload input[type="file"] {
  width: 100%;
  min-height: var(--tap);
  padding: 12px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: var(--chip);
  font: inherit;
  color: var(--ink);
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.photo-row img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--chip);
}

.photo-row .btn {
  flex: 1;
}

.total {
  margin: 16px 0 8px;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-family: var(--mono);
}

.total.award-ok {
  color: var(--ok);
}

.total.award-bad {
  color: var(--danger);
}

.total.award-pending {
  color: var(--pending);
}

.res-feedback {
  margin: 0 0 14px;
  white-space: pre-wrap;
}

.result {
  margin-top: 8px;
}

.result .btn {
  width: 100%;
}

.solution {
  margin-top: 14px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--chip);
}

.review-answer {
  margin: 0;
  white-space: pre-wrap;
}

@media (min-width: 720px) {
  :root {
    --max: 560px;
  }

  body {
    padding: 24px 0;
  }

  .shell {
    min-height: calc(100dvh - 48px);
    border-radius: 18px;
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
