:root {
  color-scheme: light;
  --ink: #10221b;
  --muted: #66746e;
  --paper: #f4f1e8;
  --panel: #fffdf7;
  --line: #d8d7cd;
  --line-dark: #b9bdb4;
  --accent: #f0563a;
  --accent-dark: #c33c26;
  --green: #1f704f;
  --green-soft: #dceade;
  --shadow: 0 28px 80px rgba(25, 39, 32, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 9% 15%, rgba(240, 86, 58, 0.09), transparent 23rem),
    linear-gradient(rgba(16, 34, 27, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 34, 27, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 32px 32px, 32px 32px, auto;
}

button,
input {
  font: inherit;
}

button,
a,
summary {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(31, 112, 79, 0.28);
  outline-offset: 3px;
}

.page-shell {
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
}

.hero {
  display: grid;
  grid-template-columns: 0.75fr 1.6fr 0.75fr;
  gap: 32px;
  align-items: end;
  padding: 44px 0 52px;
  border-bottom: 1px solid var(--line-dark);
}

.brand {
  align-self: start;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  color: var(--ink);
  text-decoration: none;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.brand b {
  color: var(--accent);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 5px);
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--ink);
}

.brand-mark i {
  width: 5px;
  height: 5px;
  background: var(--ink);
}

.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(9) {
  background: transparent;
}

.brand-mark i:nth-child(5) {
  background: var(--accent);
  border-radius: 50%;
}

.eyebrow,
.section-index {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: clamp(3.1rem, 6vw, 6.7rem);
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.hero h1 span {
  color: var(--accent);
}

.hero-intro {
  max-width: 610px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.8;
}

.hero-notes {
  display: grid;
  gap: 0;
  align-self: end;
  border-top: 1px solid var(--line-dark);
}

.hero-notes span {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  color: var(--muted);
  font-size: 0.78rem;
  border-bottom: 1px solid var(--line);
}

.hero-notes b {
  color: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 22px;
  padding: 22px 0 30px;
}

.control-column {
  display: grid;
  gap: 22px;
  align-content: start;
}

.panel,
.viewer {
  background: rgba(255, 253, 247, 0.92);
  border: 1px solid var(--line-dark);
  box-shadow: 0 12px 32px rgba(25, 39, 32, 0.06);
}

.panel {
  padding: 24px;
}

.panel-heading,
.viewer-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.panel-heading h2,
.viewer-toolbar h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: 1.65rem;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.text-button {
  padding: 4px 0;
  color: var(--green);
  background: transparent;
  border: 0;
  border-bottom: 1px solid currentColor;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}

.source-status {
  min-height: 18px;
  margin: 18px 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.source-status.is-error {
  color: var(--accent-dark);
}

.challenge-list {
  display: grid;
  gap: 5px;
  max-height: 252px;
  margin: 0;
  padding: 0 5px 0 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--line-dark) transparent;
}

.challenge-button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  width: 100%;
  padding: 11px 12px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.challenge-button:hover {
  border-color: var(--line);
  transform: translateX(2px);
}

.challenge-button[aria-current="true"] {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.challenge-date {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.challenge-size {
  color: var(--muted);
  font-size: 0.73rem;
}

.challenge-button[aria-current="true"] .challenge-size {
  color: rgba(255, 255, 255, 0.72);
}

.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 16px;
  padding-top: 15px;
  padding-right: 0;
  padding-bottom: 0;
  padding-left: 0;
  border-top: 1px solid var(--line);
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
}

.difficulty-picker legend {
  float: left;
  width: 100%;
  margin-bottom: 10px;
  padding: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.difficulty-picker label {
  position: relative;
  cursor: pointer;
}

.difficulty-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.difficulty-picker span {
  display: block;
  padding: 10px 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line-dark);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 760;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}

.difficulty-picker input:checked + span {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.difficulty-picker input:focus-visible + span {
  outline: 3px solid rgba(31, 112, 79, 0.28);
  outline-offset: 3px;
}

.difficulty-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.5;
}

.board-form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.three-columns {
  grid-template-columns: repeat(3, 1fr);
}

.two-columns {
  grid-template-columns: repeat(2, 1fr);
}

.field {
  display: grid;
  gap: 7px;
}

.field > span {
  display: flex;
  justify-content: space-between;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
}

.field em {
  color: var(--muted);
  font-size: 0.65rem;
  font-style: normal;
  font-weight: 500;
}

.field input {
  width: 100%;
  min-width: 0;
  padding: 12px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

.field input:focus {
  border-color: var(--green);
}

.form-error {
  margin: -3px 0 0;
  color: var(--accent-dark);
  font-size: 0.76rem;
  line-height: 1.5;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 16px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  cursor: pointer;
  font-weight: 760;
  transition: background 160ms ease, transform 160ms ease;
}

.primary-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.viewer {
  min-width: 0;
  padding: 28px;
  box-shadow: var(--shadow);
}

.viewer-toolbar {
  align-items: center;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.viewer-toolbar h2 {
  font-size: clamp(1.7rem, 3vw, 2.65rem);
}

.board-summary {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.download-actions {
  display: flex;
  gap: 8px;
}

.download-link {
  padding: 10px 14px;
  color: var(--ink);
  border: 1px solid var(--line-dark);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 760;
  transition: background 160ms ease, color 160ms ease;
}

.download-link:hover {
  background: var(--green-soft);
}

.download-primary {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.download-primary:hover {
  color: #fff;
  background: var(--green);
}

.board-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 620px;
  max-height: 78vh;
  margin-top: 24px;
  overflow: auto;
  background:
    linear-gradient(45deg, rgba(16, 34, 27, 0.025) 25%, transparent 25%, transparent 75%, rgba(16, 34, 27, 0.025) 75%),
    linear-gradient(45deg, rgba(16, 34, 27, 0.025) 25%, transparent 25%, transparent 75%, rgba(16, 34, 27, 0.025) 75%),
    #f8f7f1;
  background-position: 0 0, 12px 12px;
  background-size: 24px 24px;
  border: 1px solid var(--line);
  scrollbar-color: var(--line-dark) transparent;
}

.board-stage img {
  display: block;
  max-width: none;
  margin: auto;
  padding: 28px;
}

.board-stage.is-loading img,
.board-stage.has-error img {
  visibility: hidden;
}

.board-loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
  background: rgba(248, 247, 241, 0.9);
  font-size: 0.82rem;
}

.board-stage.is-loading .board-loading,
.board-stage.has-error .board-loading {
  display: grid;
}

.board-stage.has-error .loader-grid {
  display: none;
}

.loader-grid {
  display: grid;
  grid-template-columns: repeat(2, 11px);
  gap: 3px;
}

.loader-grid i {
  width: 11px;
  height: 11px;
  background: var(--green);
  animation: pulse 1s infinite alternate;
}

.loader-grid i:nth-child(2) { animation-delay: 0.2s; }
.loader-grid i:nth-child(3) { animation-delay: 0.4s; }
.loader-grid i:nth-child(4) { animation-delay: 0.6s; background: var(--accent); }

@keyframes pulse {
  to { opacity: 0.2; transform: scale(0.78); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.viewer-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 17px;
  color: var(--muted);
  font-size: 0.72rem;
}

.viewer-footer p {
  margin: 0;
  text-align: right;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  font-style: normal;
}

.legend-start {
  background: #c6efce;
  border: 2px solid #00a000;
}

.legend-mine {
  background: #111;
  border-radius: 50%;
  transform: scale(0.7);
}

.legend-number {
  color: #d00000;
  font-size: 0.76rem;
  font-weight: 800;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 25px 0 38px;
  color: var(--muted);
  border-top: 1px solid var(--line-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@media (max-width: 1060px) {
  .hero {
    grid-template-columns: 1fr 2fr;
  }

  .hero-notes {
    display: none;
  }

  .workspace {
    grid-template-columns: 310px minmax(0, 1fr);
  }

  .panel,
  .viewer {
    padding: 20px;
  }

  .board-stage {
    min-height: 520px;
  }

  .viewer-footer {
    display: grid;
  }

  .viewer-footer p {
    text-align: left;
  }
}

@media (max-width: 780px) {
  .page-shell {
    width: min(100% - 28px, 680px);
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 36px;
    padding: 26px 0 34px;
  }

  .hero h1 {
    font-size: clamp(3.2rem, 15vw, 5.7rem);
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .control-column {
    display: contents;
  }

  .challenge-panel { order: 1; }
  .viewer { order: 2; }
  .parameter-panel { order: 3; }

  .board-stage {
    min-height: 470px;
    max-height: 68vh;
  }
}

@media (max-width: 520px) {
  .page-shell {
    width: calc(100% - 20px);
  }

  .hero h1 {
    letter-spacing: -0.075em;
  }

  .hero-intro {
    font-size: 0.94rem;
  }

  .panel,
  .viewer {
    padding: 17px;
  }

  .viewer-toolbar {
    display: grid;
  }

  .download-actions,
  .download-link {
    flex: 1;
  }

  .download-link {
    text-align: center;
  }

  .board-stage {
    min-height: 400px;
  }

  .board-stage img {
    padding: 18px;
  }

  .site-footer {
    display: grid;
  }
}
