:root {
  --bg: #e8eef3;
  --sheet: #ffffff;
  --ink: #152033;
  --muted: #5a6a7a;
  --line: #c3d0db;
  --accent: #0b6e6e;
  --accent-ink: #ffffff;
  --danger: #9b2c2c;
  --ok: #1f6b4a;
  --pending: #8a5a12;
  --chip: #f3f7f8;
  --veil: color-mix(in srgb, var(--ink) 88%, #000000);
  --wash-danger: color-mix(in srgb, var(--danger) 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);
}

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

.screen[hidden] {
  display: none;
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.15;
  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;
}

input[type="text"],
input[type="password"],
input[type="number"],
input:not([type]),
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

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

.hint {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
}

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

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

.check {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  font-weight: 500;
  font-size: 16px;
}

.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

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

.chip {
  flex: 1;
  min-height: 40px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

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

.btn-row.sticky {
  position: sticky;
  bottom: 0;
  padding: 12px 0 4px;
  background: linear-gradient(
    to top,
    var(--sheet) 70%,
    color-mix(in srgb, var(--sheet) 0%, transparent)
  );
}

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

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

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

.btn.text {
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  margin-top: 18px;
  min-height: 40px;
  padding: 0;
}

.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;
}

.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;
}

.progress {
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  margin-bottom: 16px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
}

.question img.stem {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--chip);
  cursor: zoom-in;
}

.stem-text {
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.answer {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.opt {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.opt[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--wash-accent);
}

.opt-letter {
  flex: 0 0 28px;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
}

.opt-img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}

.opt.image-opt {
  flex-direction: column;
  align-items: stretch;
}

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

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

.upload-status {
  margin: 0;
  font-size: 14px;
  color: var(--ok);
}

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

.results {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.results li {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.res-head {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
  margin-bottom: 6px;
}

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

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

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

.res-feedback {
  margin: 0;
  color: var(--ink);
}

.zoom {
  position: fixed;
  inset: 0;
  background: var(--veil);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.zoom[hidden] {
  display: none;
}

.zoom img {
  flex: 1;
  width: 100%;
  object-fit: contain;
  padding: 12px;
}

.zoom-close {
  align-self: flex-end;
  margin: 12px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

@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;
  }
}
