:root {
  color-scheme: light;
  --paper: #f4f1e8;
  --paper-deep: #e9e4d7;
  --surface: #fffdf7;
  --ink: #152031;
  --ink-soft: #526070;
  --line: #cfc9bb;
  --line-strong: #9c978b;
  --accent: #176b70;
  --accent-strong: #0c5055;
  --accent-pale: #dcebea;
  --cobalt: #2e4f8f;
  --success: #27744f;
  --code: #111b29;
  --code-ink: #dfe9f4;
  --danger: #a33d35;
  --shadow: 0 18px 48px rgba(21, 32, 49, 0.09);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --font-sans: "Avenir Next", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-sans);
  line-height: 1.65;
}

button,
input,
select {
  font: inherit;
}

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

button {
  color: inherit;
}

a {
  color: var(--accent-strong);
  text-underline-offset: 0.2em;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: white;
  background: var(--ink);
  border-radius: var(--radius-sm);
  transform: translateY(-150%);
  transition: transform 150ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

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

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 12px clamp(18px, 3vw, 46px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 232, 0.96);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--surface);
  background: var(--ink);
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: 0.01em;
}

.brand small {
  margin-top: 1px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-summary {
  display: grid;
  width: min(180px, 18vw);
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

.progress-track {
  display: block;
  height: 5px;
  overflow: hidden;
  background: var(--paper-deep);
  border-radius: 99px;
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--success);
  border-radius: inherit;
  transition: width 220ms ease;
}

.progress-fill[data-completed="0"] { width: 0%; }
.progress-fill[data-completed="1"] { width: 5.8824%; }
.progress-fill[data-completed="2"] { width: 11.7647%; }
.progress-fill[data-completed="3"] { width: 17.6471%; }
.progress-fill[data-completed="4"] { width: 23.5294%; }
.progress-fill[data-completed="5"] { width: 29.4118%; }
.progress-fill[data-completed="6"] { width: 35.2941%; }
.progress-fill[data-completed="7"] { width: 41.1765%; }
.progress-fill[data-completed="8"] { width: 47.0588%; }
.progress-fill[data-completed="9"] { width: 52.9412%; }
.progress-fill[data-completed="10"] { width: 58.8235%; }
.progress-fill[data-completed="11"] { width: 64.7059%; }
.progress-fill[data-completed="12"] { width: 70.5882%; }
.progress-fill[data-completed="13"] { width: 76.4706%; }
.progress-fill[data-completed="14"] { width: 82.3529%; }
.progress-fill[data-completed="15"] { width: 88.2353%; }
.progress-fill[data-completed="16"] { width: 94.1176%; }
.progress-fill[data-completed="17"] { width: 100%; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-accent {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.button-accent:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button-quiet {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.button-quiet:hover {
  border-color: var(--accent);
}

.mobile-list-toggle {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 342px) minmax(0, 1fr);
  min-height: calc(100vh - 78px);
}

.problem-index {
  position: sticky;
  top: 78px;
  align-self: start;
  height: calc(100vh - 78px);
  overflow-y: auto;
  padding: 28px 22px 36px clamp(18px, 3vw, 42px);
  border-right: 1px solid var(--line);
  background: rgba(233, 228, 215, 0.72);
  scrollbar-width: thin;
}

.index-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.eyebrow,
.problem-number {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.index-heading h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
}

.result-count {
  flex: none;
  padding: 3px 8px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  font-size: 11px;
  font-weight: 800;
}

.filters {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  flex: 1;
  gap: 5px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 14px;
  font-weight: 600;
}

.field input::placeholder {
  color: #8d938e;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 112, 0.16);
}

.field-search {
  margin-bottom: 10px;
}

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

.text-button {
  min-height: 36px;
  margin: 8px 0 -8px;
  padding: 4px 0;
  color: var(--accent-strong);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.problem-list {
  display: grid;
  gap: 8px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.problem-list-item {
  margin: 0;
}

.problem-list-button {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 64px;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  color: var(--ink);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
}

.problem-list-button:hover {
  background: rgba(255, 253, 247, 0.72);
  border-color: var(--line);
}

.problem-list-button[aria-current="true"] {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(21, 32, 49, 0.07);
}

.list-number {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
}

.list-copy {
  min-width: 0;
}

.list-title,
.list-meta {
  display: block;
}

.list-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-meta {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 10px;
}

.list-check {
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  color: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 900;
}

.problem-list-button[data-complete="true"] .list-check {
  color: white;
  background: var(--success);
  border-color: var(--success);
}

.study-pane {
  min-width: 0;
  padding: clamp(30px, 5vw, 72px) clamp(20px, 6vw, 92px) 70px;
}

.problem-view {
  width: min(980px, 100%);
  margin: 0 auto;
  scroll-margin-top: 104px;
  outline: none;
}

.problem-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 30px;
  border-bottom: 2px solid var(--ink);
}

.problem-header h1 {
  margin: 0;
  max-width: 750px;
  font-size: clamp(30px, 4.6vw, 56px);
  line-height: 1.12;
  letter-spacing: -0.045em;
}

.problem-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 18px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  min-height: 29px;
  padding: 4px 9px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
}

.completion-button {
  flex: none;
  color: var(--success);
  background: transparent;
  border-color: var(--success);
}

.completion-button[aria-pressed="true"] {
  color: white;
  background: var(--success);
}

.content-section {
  padding: 36px 0;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.section-heading-action {
  justify-content: space-between;
}

.section-heading-action > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-index {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--surface);
  background: var(--ink);
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
}

.section-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.lead {
  max-width: 830px;
  margin: 0 0 24px;
  font-size: clamp(17px, 2vw, 21px);
  font-weight: 600;
  line-height: 1.85;
}

.contract-card {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 27px;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
}

.contract-card span {
  flex: none;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.contract-card code {
  overflow-wrap: anywhere;
  color: var(--cobalt);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 30px;
}

.two-column h3,
.answer-notes h3 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.constraint-list {
  margin: 0;
  padding-left: 20px;
  color: var(--ink-soft);
  font-size: 14px;
}

.constraint-list li + li {
  margin-top: 5px;
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.sample-grid > div {
  min-width: 0;
  padding: 12px;
}

.sample-grid > div + div {
  border-left: 1px solid var(--line);
}

.sample-grid span,
.source-block > span {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-strong);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.sample-grid pre {
  max-width: 100%;
  margin: 0;
  overflow-x: auto;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.source-block {
  margin-top: 24px;
  padding: 17px 19px;
  background: var(--accent-pale);
  border: 1px solid #b7d2d0;
  border-radius: var(--radius);
}

.source-block p {
  margin: 0 0 7px;
  color: var(--ink-soft);
  font-size: 13px;
}

.source-block a {
  font-size: 13px;
  font-weight: 800;
}

.hint-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: hint;
}

.hint-item {
  position: relative;
  padding: 15px 17px 15px 52px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  counter-increment: hint;
  font-size: 14px;
}

.hint-item::before {
  position: absolute;
  top: 13px;
  left: 15px;
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  content: counter(hint);
  color: var(--accent-strong);
  background: var(--accent-pale);
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 900;
}

.hint-placeholder {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.answer-panel {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 7px 12px 7px 18px;
  color: #aebccd;
  background: #0c1521;
  border-bottom: 1px solid #27364a;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.copy-button {
  min-height: 32px;
  padding: 5px 9px;
  color: var(--code-ink);
  background: #26354a;
  border: 1px solid #43546d;
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.copy-buffer {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.solution-code {
  max-height: 560px;
  margin: 0;
  overflow: auto;
  padding: 24px;
  color: var(--code-ink);
  background: var(--code);
  font-family: var(--font-mono);
  font-size: clamp(12px, 1.35vw, 14px);
  line-height: 1.72;
  tab-size: 4;
}

.answer-notes {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(200px, 0.55fr);
  gap: 0;
}

.answer-notes > div {
  padding: 22px;
}

.answer-notes > div:nth-child(2) {
  border-left: 1px solid var(--line);
}

.answer-notes p,
.answer-notes blockquote {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.spoken-answer {
  grid-column: 1 / -1;
  background: var(--accent-pale);
  border-top: 1px solid #b7d2d0;
}

.spoken-answer blockquote {
  color: var(--ink);
  font-weight: 650;
}

.problem-footer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding-top: 28px;
}

.problem-footer span {
  color: var(--ink-soft);
  text-align: center;
  font-size: 12px;
}

.empty-state {
  width: min(560px, 100%);
  margin: 10vh auto 0;
  padding: 38px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.empty-code {
  margin: 0;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 54px;
  font-weight: 900;
  line-height: 1;
}

.empty-state h1 {
  margin: 12px 0 7px;
}

.empty-state p:not(.empty-code) {
  color: var(--ink-soft);
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid rgba(46, 79, 143, 0.48);
  outline-offset: 3px;
}

@media (max-width: 980px) {
  .progress-summary {
    display: none;
  }

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

  .problem-index {
    padding-left: 18px;
  }

  .study-pane {
    padding-inline: 30px;
  }

  .two-column {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar {
    position: relative;
    min-height: 70px;
    padding: 10px 14px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand strong {
    font-size: 14px;
  }

  .brand small {
    font-size: 9px;
  }

  .topbar-actions {
    gap: 7px;
  }

  .topbar-actions > .button-accent {
    display: none;
  }

  .mobile-list-toggle {
    display: inline-flex;
  }

  .workspace {
    display: block;
    min-height: 0;
  }

  .problem-index {
    position: static;
    height: auto;
    max-height: none;
    padding: 20px 14px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .problem-index:not([data-mobile-open="true"]) {
    display: none;
  }

  .problem-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .problem-list-button {
    grid-template-columns: 24px minmax(0, 1fr) 20px;
    padding-inline: 7px;
  }

  .study-pane {
    padding: 28px 16px 50px;
  }

  .problem-view {
    scroll-margin-top: 16px;
  }

  .problem-header {
    display: grid;
    gap: 20px;
  }

  .problem-header h1 {
    font-size: clamp(30px, 10vw, 44px);
  }

  .completion-button {
    width: 100%;
  }

  .content-section {
    padding: 29px 0;
  }

  .section-heading-action {
    align-items: stretch;
    gap: 15px;
  }

  .section-heading-action .button {
    flex: none;
  }

  .contract-card {
    display: grid;
    gap: 5px;
  }

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

  .sample-grid > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .answer-notes {
    grid-template-columns: 1fr;
  }

  .answer-notes > div:nth-child(2) {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .spoken-answer {
    grid-column: auto;
  }

  .problem-footer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .problem-footer span {
    display: none;
  }

  .problem-footer .button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .problem-list {
    grid-template-columns: 1fr;
  }

  .filter-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-heading-action {
    display: grid;
  }

  .section-heading-action .button {
    width: 100%;
  }

  .solution-code {
    padding: 18px 14px;
  }

  .answer-notes > div {
    padding: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
