:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

body {
  margin: 0;
  background: #f6f6f6;
  color: #111;
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand small,
.muted,
.small {
  color: #666;
}

.brand-badge {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-weight: 700;
}

.app-shell,
.list,
.phase-list {
  display: grid;
  gap: 12px;
}

.card {
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 14px;
}

.card.compact {
  padding: 12px;
}

.phase-card {
  display: grid;
  gap: 12px;
}

.phase-rows {
  display: grid;
  gap: 10px;
}

.subject-row-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.study-subject-card h3 {
  margin: 0 0 6px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1:last-child,
h2:last-child,
p:last-child {
  margin-bottom: 0;
}

a {
  color: #0b57d0;
}

.row {
  display: flex;
}

.wrap {
  flex-wrap: wrap;
}

.gap {
  gap: 8px;
}

.space-between {
  justify-content: space-between;
}

.center-y {
  align-items: center;
}

.button {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  background: #fafafa;
}

.button.disabled {
  color: #999;
  background: #f1f1f1;
  border-color: #e2e2e2;
}

.button.active {
  background: #1a73e8;
  color: white;
  border-color: #1a73e8;
}

.breadcrumb {
  margin-bottom: 8px;
  font-size: 14px;
}

.page-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.page-link {
  display: inline-block;
  min-width: 32px;
  padding: 5px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  background: #fff;
}

.page-link.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.viewer-card {
  overflow: auto;
}

.utility-card {
  display: grid;
  gap: 12px;
}

.utility-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(220px, 0.7fr);
  gap: 14px;
}

.utility-grid-tight {
  grid-template-columns: 1fr;
}

.utility-title {
  margin-bottom: 8px;
}

.section-jump-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.section-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  background: #fafafa;
  cursor: pointer;
  text-align: left;
}

.section-chip-code {
  font-size: 12px;
  font-weight: 700;
  color: #1a73e8;
}

.section-chip-title {
  font-size: 13px;
  font-weight: 600;
  color: #222;
}

.section-chip-meta {
  font-size: 12px;
  color: #666;
}

.page-jump-form {
  display: flex;
  gap: 8px;
}

.page-jump-input {
  width: 100%;
  max-width: 120px;
  padding: 7px 9px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font: inherit;
}

.all-pages-list {
  display: grid;
  gap: 12px;
}

.page-card {
  display: grid;
  gap: 12px;
  scroll-margin-top: 16px;
}

.page-card-top {
  margin-bottom: 4px;
}

.page-image-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #f3f5f8;
  min-height: 240px;
}

.page-image {
  display: block;
  width: 100%;
  height: auto;
  position: relative;
  z-index: 1;
  transition: opacity 0.2s ease;
}

.page-image-frame.loading .page-image {
  opacity: 0;
}

.page-image-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #eef1f4 25%, #f7f8fa 37%, #eef1f4 63%);
  background-size: 400% 100%;
  animation: page-skeleton 1.2s ease-in-out infinite;
}

.page-image-frame:not(.loading) .page-image-skeleton {
  display: none;
}

.page-image-error {
  display: none;
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
}

.page-image-frame.error .page-image {
  opacity: 0.2;
}

.page-image-frame.error .page-image-error {
  display: block;
}

.hidden {
  display: none;
}

pre,
code {
  white-space: pre-wrap;
  word-break: break-word;
}

@keyframes page-skeleton {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

@media (max-width: 700px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .page-jump-form {
    flex-wrap: wrap;
  }

  .page-jump-input {
    max-width: none;
  }
}

.page-text {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1.5rem;
  font-size: 1rem;
  line-height: 1.7;
  color: #222;
}

.viewer-card .page-text,
.card .page-text {
  padding: 0;
}

.page-text h1,
.page-text h2,
.page-text h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

.page-text p {
  margin-bottom: 1em;
}

.page-text ul,
.page-text ol {
  margin-bottom: 1em;
  padding-left: 1.5em;
}

.page-text table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1em;
}

.page-text th,
.page-text td {
  border: 1px solid #ddd;
  padding: 0.4em 0.8em;
  text-align: left;
}

.page-text th {
  background: #f5f5f5;
  font-weight: 600;
}

.page-text code {
  background: #f5f5f5;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.9em;
}

.page-text pre {
  background: #f5f5f5;
  padding: 1em;
  border-radius: 6px;
  overflow-x: auto;
}

.view-switch {
  margin-bottom: 12px;
}

.mode-label {
  margin-bottom: 0;
}

.top-actions {
  margin-top: 8px;
}

.file-row-actions {
  margin: 10px 0;
}

.page-text blockquote {
  border-left: 3px solid #ddd;
  margin: 0 0 1em;
  padding: 0.5em 1em;
  color: #555;
}
