:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #e8f1ef;
  --text: #172127;
  --muted: #5f6c70;
  --line: #cedbd7;
  --accent: #0b6b5d;
  --accent-strong: #074b42;
  --warn: #d39a2e;
  --rose: #b93e50;
  --blue: #315d8c;
  --code-bg: #16232a;
  --code-text: #edf5f3;
  --shadow: 0 18px 50px rgba(22, 31, 36, 0.10);
  --topbar: 64px;
  --mobile-actions: 58px;
  font-family: "Yu Gothic UI", "Meiryo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: max-content minmax(240px, 520px) max-content;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar);
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 246, 0.95);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}

.brand-text {
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}

.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.menu-button span,
.search-icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
}

.menu-button span::before,
.menu-button span::after,
.menu-button span {
  border-top: 2px solid currentColor;
}

.menu-button span::before,
.menu-button span::after {
  position: absolute;
  left: 0;
  width: 18px;
  content: "";
}

.menu-button span::before {
  top: 5px;
}

.menu-button span::after {
  top: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 12px;
}

.search-icon::before {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  content: "";
}

.search-icon::after {
  position: absolute;
  left: 13px;
  top: 13px;
  width: 7px;
  border-top: 2px solid var(--muted);
  transform: rotate(45deg);
  transform-origin: left center;
  content: "";
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.read-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
}

.read-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

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

.sidebar {
  position: sticky;
  top: var(--topbar);
  height: calc(100vh - var(--topbar));
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
  padding: 16px 12px 24px;
}

.nav-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0 4px 14px;
  border-bottom: 1px solid var(--line);
}

.nav-tab {
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.nav-tab:hover,
.nav-tab:focus-visible {
  color: var(--accent-strong);
  outline: 0;
}

.nav-tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent-strong);
}

.progress-panel {
  padding: 6px 6px 14px;
}

.progress-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #e5eceb;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.doc-list {
  display: grid;
  gap: 4px;
}

.nav-group-label {
  margin: 16px 10px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}

.nav-group-label:first-child {
  margin-top: 4px;
}

.doc-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.doc-link:hover,
.doc-link:focus-visible {
  background: var(--surface-soft);
  outline: 0;
}

.doc-link.active {
  background: #e3f2ef;
  color: #073f40;
  font-weight: 800;
}

.doc-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-badge {
  min-width: 22px;
  color: var(--accent-strong);
  font-size: 14px;
  text-align: center;
}

.doc-link:not(.done) .doc-badge {
  color: #aeb8b6;
}

.reader {
  min-width: 0;
  padding: 32px clamp(18px, 5vw, 72px) 80px;
}

.article {
  max-width: 920px;
  margin: 0 auto;
}

.article:focus {
  outline: 0;
}

.article.loading {
  color: var(--muted);
}

.article h1,
.article h2,
.article h3,
.article h4 {
  line-height: 1.35;
  letter-spacing: 0;
}

.article h1 {
  margin: 0 0 28px;
  padding-bottom: 18px;
  border-bottom: 3px solid var(--accent);
  font-size: 34px;
}

.article h2 {
  margin: 46px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 24px;
}

.article h3 {
  margin: 30px 0 10px;
  color: var(--accent-strong);
  font-size: 19px;
}

.article h4 {
  margin: 24px 0 8px;
  font-size: 17px;
}

.article p {
  margin: 12px 0;
}

.article ul,
.article ol {
  padding-left: 1.45rem;
}

.article li + li {
  margin-top: 4px;
}

.article a {
  color: var(--accent-strong);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.article code {
  border-radius: 5px;
  background: #eaf0ef;
  color: #12383a;
  padding: 0.12em 0.34em;
  font-family: "Cascadia Code", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.article pre {
  overflow: auto;
  margin: 18px 0;
  border-radius: 8px;
  background: var(--code-bg);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}

.article pre code {
  display: block;
  min-width: max-content;
  background: transparent;
  color: var(--code-text);
  padding: 16px;
  font-size: 14px;
  line-height: 1.65;
}

.article blockquote {
  margin: 18px 0;
  border-left: 4px solid var(--warn);
  padding: 6px 0 6px 16px;
  color: #4d5b5e;
  background: #fff8e7;
  padding: 10px 14px;
}

.article table {
  display: block;
  width: 100%;
  overflow: auto;
  border-collapse: collapse;
  margin: 18px 0;
}

.article th,
.article td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.article th {
  background: var(--surface-soft);
}

.article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 28px 0;
}

.mobile-actions {
  display: none;
}

.scrim {
  display: none;
}

mark.search-hit {
  border-radius: 4px;
  background: #ffe4a8;
  color: inherit;
  padding: 0 2px;
}

.task-item {
  list-style: none;
  margin-left: -1.45rem;
}

.task-item label {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  cursor: pointer;
}

.task-checkbox {
  width: 18px;
  height: 18px;
  margin-top: 5px;
  accent-color: var(--accent);
}

.task-item.completed span {
  color: var(--muted);
  text-decoration: line-through;
}

.question-options {
  display: grid;
  gap: 8px;
  margin: 18px 0 24px;
}

.option-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.option-button:hover,
.option-button:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 139, 141, 0.16);
}

.option-button.selected {
  border-color: var(--accent-strong);
  background: #e3f2ef;
}

.option-letter {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  font-weight: 800;
}

.option-button.correct-answer {
  border-color: #23824d;
}

.question-options.is-wrong .option-button.selected {
  border-color: var(--rose);
  background: #fbe9ef;
}

.grade-button,
.mock-controls button,
.form-submit,
.data-actions button,
.import-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.grade-button {
  justify-self: start;
  padding: 0 18px;
}

.primary {
  border-color: var(--accent-strong) !important;
  background: var(--accent-strong) !important;
  color: #fff !important;
}

.question-feedback {
  min-height: 1.7em;
  margin: 0 !important;
  color: var(--muted);
  font-weight: 800;
}

.question-options.is-correct .question-feedback {
  color: #187442;
}

.question-options.is-wrong .question-feedback {
  color: var(--rose);
}

.answer-reveal,
.mock-answer-key {
  margin: 18px 0 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.answer-reveal summary,
.mock-answer-key > summary {
  padding: 12px 14px;
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 800;
}

.answer-body,
.mock-answer-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--line);
}

.answer-body h3:first-child,
.mock-answer-body h2:first-child {
  margin-top: 20px;
}

.mock-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px 18px;
  margin: 20px 0 30px;
  padding: 14px;
  border-top: 2px solid var(--accent);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.mock-timer {
  min-width: 126px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.written-answer {
  display: grid;
  gap: 7px;
  margin: 18px 0 34px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 6px;
  background: #f5f8fb;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.written-answer textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid #bdccd7;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.7;
}

.written-answer textarea:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(49, 93, 140, 0.14);
}

.mock-timer.time-up {
  color: var(--rose);
}

.mock-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.mock-controls button {
  padding: 0 14px;
}

.mock-result {
  grid-column: 1 / -1;
  min-height: 1.7em;
  margin: 0 !important;
  font-weight: 800;
}

.code-block {
  position: relative;
  margin: 18px 0;
}

.code-block pre {
  margin: 0;
}

.code-block pre code {
  padding-top: 46px;
}

.copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  min-height: 30px;
  padding: 2px 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  background: #26343c;
  color: #fff;
  font-size: 13px;
}

.mistake-manager {
  margin-top: 18px;
}

.checklist-summary {
  margin-bottom: 14px;
  color: var(--accent-strong);
  font-weight: 800;
}

.mistake-form {
  display: grid;
  gap: 12px;
  padding: 16px 0 20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.mistake-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mistake-form input,
.mistake-form select,
.mistake-form textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

.form-submit {
  justify-self: start;
  padding: 0 18px;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.data-actions button,
.import-button {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  cursor: pointer;
}

.import-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.mistake-list {
  display: grid;
}

.mistake-entry {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.mistake-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.mistake-heading button {
  border: 0;
  background: transparent;
  color: var(--rose);
}

.mistake-entry p {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
  margin: 6px 0;
}

.mistake-entry p span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.empty-state {
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 20px);
  border-radius: 8px;
  background: #152126;
  color: #fff;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 820px) {
  :root {
    --topbar: 106px;
  }

  body {
    padding-bottom: var(--mobile-actions);
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px 10px;
  }

  .icon-button {
    display: grid;
    place-items: center;
  }

  .brand-text {
    max-width: 44vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .search-box {
    grid-column: 1 / -1;
    order: 5;
    height: 40px;
  }

  .read-toggle {
    height: 40px;
    padding: 0 10px;
  }

  .layout {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: var(--topbar) auto var(--mobile-actions) 0;
    z-index: 40;
    width: min(86vw, 340px);
    height: auto;
    transform: translateX(-105%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  body.menu-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  body.menu-open .scrim {
    display: block;
    position: fixed;
    inset: var(--topbar) 0 var(--mobile-actions);
    z-index: 35;
    background: rgba(13, 24, 26, 0.35);
  }

  .reader {
    padding: 22px 16px 34px;
  }

  .article h1 {
    margin-bottom: 22px;
    font-size: 28px;
  }

  .article h2 {
    margin-top: 34px;
    font-size: 22px;
  }

  .article h3 {
    font-size: 18px;
  }

  .article pre {
    margin-left: -16px;
    margin-right: -16px;
    border-radius: 0;
  }

  .article .code-block {
    margin-left: -16px;
    margin-right: -16px;
  }

  .article .code-block pre {
    margin: 0;
    border-radius: 0;
  }

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

  .mock-toolbar {
    grid-template-columns: 1fr;
  }

  .mock-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mock-controls button {
    min-width: 0;
    padding: 0 8px;
  }

  .mock-result {
    grid-column: auto;
  }

  .toast {
    bottom: calc(var(--mobile-actions) + 16px);
  }

  .article pre code {
    padding: 14px 16px;
    font-size: 13px;
  }

  .mobile-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    min-height: var(--mobile-actions);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .mobile-actions button {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-weight: 800;
  }
}

@media (max-width: 460px) {
  .brand-text {
    max-width: 36vw;
    font-size: 15px;
  }

  .read-toggle span {
    display: none;
  }

  .article {
    font-size: 15.5px;
  }

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

  .answer-body,
  .mock-answer-body {
    padding-left: 12px;
    padding-right: 12px;
  }
}
