/* Mobile-first exam app — typography & layout on Pico CSS */

:root {
  --app-base: 15px;
  --app-text: #1a2332;
  --app-text-secondary: #8b95a5;
  --app-text-tertiary: #a8b0bc;
  --app-touch: 2.75rem;
  --app-header-height: 2.75rem;
  --app-icon-size: 1rem;

  /* Type scale (15px root, iOS-like) */
  --type-caption2: 0.667rem;   /* 10px */
  --type-caption: 0.733rem;      /* 11px */
  --type-footnote: 0.8rem;       /* 12px */
  --type-subhead: 0.867rem;      /* 13px */
  --type-callout: 0.933rem;      /* 14px */
  --type-body: 1rem;             /* 15px */
  --type-headline: 1.067rem;     /* 16px */

  /* Semantic titles — shared across pages */
  --type-nav-title: var(--type-footnote);   /* 12px site header */
  --type-page-lead: var(--type-callout);    /* 14px home / paper subject */
  --type-page-title: var(--type-subhead);   /* 13px question no, year row */
  --type-page-meta: var(--type-caption);    /* 11px year, count, hints */

  --pico-background-color: #fff;
  --pico-card-background-color: #fff;
  --pico-font-size: 100%;
  --pico-spacing: 1rem;
  --pico-block-spacing-vertical: 0.75rem;
  --pico-typography-spacing-vertical: 0;
  --pico-font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ── Reset Pico typography noise ── */

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  --pico-font-size: inherit;
  --pico-typography-spacing-top: 0;
  --pico-typography-spacing-vertical: 0;
}

p {
  margin: 0;
}

label {
  margin-bottom: 0.3rem;
  font-size: var(--type-footnote);
  font-weight: 500;
  color: var(--app-text-secondary);
}

button,
[role="button"],
input:not([type="checkbox"], [type="radio"]),
select {
  font-size: var(--type-subhead);
}

/* ── Shell ── */

html.app-viewport {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html {
  font-size: var(--app-base);
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: #fff;
  font-family: var(--pico-font-family);
  font-size: var(--type-body);
  line-height: 1.45;
  color: var(--app-text);
}

.container {
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

body > header.container {
  height: var(--app-header-height);
  padding-block: 0;
  display: flex;
  align-items: center;
}

body > main.container {
  height: calc(100dvh - var(--app-header-height));
  padding-block: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

body > main.question-page,
body > main.adjust-page {
  overflow-y: auto;
  touch-action: pan-y pan-x pinch-zoom;
}

/* ── Nav bar ── */

.site-header {
  background: #fff;
  border-bottom: 1px solid #e8ecf1;
}

.site-header nav ul {
  margin: 0;
}

.site-header nav li {
  margin: 0;
  padding: 0;
}

.site-title {
  display: block;
  font-size: var(--type-nav-title);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--app-text);
  text-decoration: none;
}

.site-header nav a.site-title:is(:hover, :focus) {
  color: var(--pico-primary);
  text-decoration: none;
}

/* ── Shared components ── */

.back-link {
  margin-bottom: 0.5rem;
  font-size: var(--type-subhead);
  line-height: 1.35;
}

.back-link a {
  color: var(--pico-primary);
  text-decoration: none;
}

.back-link a:active {
  opacity: 0.7;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.page-header .page-title {
  text-align: left;
  margin-bottom: 0;
}

.page-header h1 {
  font-size: var(--type-page-title);
  font-weight: 600;
  line-height: 1.35;
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: var(--type-caption);
  font-weight: 600;
  line-height: 1.3;
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
  white-space: nowrap;
}

.badge-muted {
  background: #eef1f5;
  color: var(--app-text-secondary);
  font-weight: 500;
}

.empty-state {
  text-align: center;
  padding: 1.5rem 0;
  font-size: var(--type-subhead);
  color: var(--app-text-secondary);
}

/* ── Home page ── */

body > main.home-page {
  padding-top: 0.85rem;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
  max-width: 22.5rem;
}

.home-header {
  margin-bottom: 1rem;
}

.home-kicker {
  font-size: var(--type-page-lead);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.02em;
  color: var(--app-text);
}

.home-sub {
  margin-top: 0.2rem;
  font-size: var(--type-page-meta);
  font-weight: 500;
  line-height: 1.4;
  color: var(--app-text-tertiary);
}

.paper-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 0 0 1px rgba(16, 24, 40, 0.05);
}

.paper-table {
  width: 100%;
  min-width: 16.5rem;
  border-collapse: collapse;
}

.paper-table th,
.paper-table td {
  padding: 0.55rem 0.4rem;
  text-align: center;
  vertical-align: middle;
  border-bottom: 1px solid #e8ecf1;
}

.paper-table thead th:not(.paper-table-year) {
  font-size: var(--type-caption);
  padding-inline: 0.3rem;
}

.paper-table thead th:last-child,
.paper-table tbody td:last-child {
  padding-right: 0.55rem;
}

.paper-table tbody td .paper-cell-link {
  min-width: 2rem;
  min-height: 2rem;
  padding: 0.3rem;
}

.paper-table thead th {
  font-size: var(--type-caption);
  font-weight: 600;
  line-height: 1.35;
  color: var(--app-text-secondary);
  background: #f8fafc;
  border-bottom: 1px solid #dce3ec;
}

.paper-table-year {
  width: 3.25rem;
  font-size: var(--type-page-title);
  font-weight: 700;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  color: var(--app-text);
  background: #fafbfc;
}

.paper-table tbody tr.is-latest .paper-table-year {
  font-size: var(--type-page-lead);
  box-shadow: inset 3px 0 0 #3b6fd9;
}

.paper-table tbody tr:last-child th,
.paper-table tbody tr:last-child td {
  border-bottom: none;
}

.cell-icon {
  width: var(--app-icon-size);
  height: var(--app-icon-size);
  flex-shrink: 0;
  stroke-width: 1.5;
}

.paper-cell-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.15rem;
  min-height: 2.15rem;
  padding: 0.35rem;
  border-radius: 0.45rem;
  color: var(--app-text-secondary);
  text-decoration: none;
  background: #f6f8fb;
  transition: background-color 0.12s ease, transform 0.12s ease, color 0.12s ease;
}

.paper-cell-link:active {
  background: #e8eef5;
  color: var(--app-text);
  transform: scale(0.98);
}

.paper-cell-link.col-math { box-shadow: inset 2px 0 0 color-mix(in srgb, #3b6fd9 55%, transparent); }
.paper-cell-link.col-physics { box-shadow: inset 2px 0 0 color-mix(in srgb, #7c5cbf 55%, transparent); }
.paper-cell-link.col-chemistry { box-shadow: inset 2px 0 0 color-mix(in srgb, #2d9a6a 55%, transparent); }

.paper-cell-empty {
  font-size: var(--type-subhead);
  color: var(--app-text-tertiary);
  opacity: 0.45;
}

a.paper-cell-link {
  --pico-color: var(--app-text);
  --pico-text-decoration: none;
  --pico-underline: transparent;
}

/* ── Paper page (question list) ── */

body > main.paper-page {
  padding-top: 0.75rem;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
  max-width: 22.5rem;
}

.paper-sheet {
  padding: 1rem 1.15rem 0.95rem 1.15rem;
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 0 0 1px rgba(16, 24, 40, 0.05);
}

.paper-sheet.col-math,
.paper-sheet.col-physics,
.paper-sheet.col-chemistry {
  padding: 1rem 1.15rem 0.95rem 1.3rem;
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.06), 0 0 0 1px rgba(16, 24, 40, 0.06);
}

.paper-sheet.col-math {
  border-left: 3px solid #3b6fd9;
}

.paper-sheet.col-physics {
  border-left: 3px solid #7c5cbf;
}

.paper-sheet.col-chemistry {
  border-left: 3px solid #2d9a6a;
}

.paper-sheet-head {
  margin-bottom: 0.85rem;
  padding: 0 0.4rem 0 0.35rem;
}

.paper-year {
  font-size: var(--type-page-meta);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--app-text-tertiary);
}

.paper-subject {
  margin-top: 0.15rem;
  font-size: var(--type-footnote);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.02em;
}

.paper-count {
  margin-top: 0.25rem;
  font-size: var(--type-page-meta);
  font-weight: 500;
  line-height: 1.4;
  color: var(--app-text-tertiary);
}

.question-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 0.65rem;
}

.question-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.35rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  color: var(--app-text-secondary);
  background: #f6f8fb;
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.question-chip:active {
  background: #e8eef5;
  color: var(--app-text);
  transform: scale(0.98);
}

.q-prefix,
.q-suffix {
  font-size: var(--type-subhead);
  font-weight: 500;
  line-height: 1.3;
  color: var(--app-text-tertiary);
}

.q-no {
  font-size: var(--type-callout);
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  color: var(--app-text);
}

a.question-chip {
  --pico-color: var(--app-text);
  --pico-text-decoration: none;
  --pico-underline: transparent;
}

a.question-chip:active .q-no {
  color: #2c5282;
}

/* ── Question page ── */

.question-page {
  padding-bottom: 0.75rem;
}

.page-title {
  text-align: center;
  margin-bottom: 0.5rem;
}

.page-title-meta {
  font-size: var(--type-page-meta);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.04em;
  color: var(--app-text-tertiary);
}

.page-title-main {
  margin-top: 0.12rem;
  font-size: var(--type-page-title);
  font-weight: 600;
  line-height: 1.35;
}

.center-title {
  text-align: center;
  margin-bottom: 0.5rem;
}

.adjust-link {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
}

.question-toolbar {
  display: flex;
  align-items: center;
  min-height: 2.15rem;
}

.question-toolbar--above {
  justify-content: flex-end;
  margin-bottom: 0.35rem;
}

.question-toolbar--below {
  margin-top: 0.65rem;
}

.question-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
}

.question-nav-start,
.question-nav-end {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.15rem;
}

.question-nav-start {
  justify-self: start;
}

.question-nav-end {
  justify-self: end;
}

.question-nav-hint {
  margin: 0;
  padding: 0 0.25rem;
  text-align: center;
  justify-self: center;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.15rem;
  min-height: 2.15rem;
  padding: 0.35rem;
  border-radius: 0.45rem;
  color: var(--app-text-secondary);
  background: #f6f8fb;
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.icon-btn:active {
  background: #e8eef5;
  color: var(--pico-primary);
  transform: scale(0.98);
}

.swipe-hint {
  font-size: var(--type-page-meta);
  line-height: 1.35;
  color: var(--app-text-tertiary);
}

.question-image-wrap {
  position: relative;
  width: 100%;
  touch-action: pan-y pinch-zoom;
  border: 1px solid #dce3ec;
  border-radius: 0.5rem;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 60%);
}

.question-image {
  display: block;
  width: 100%;
  height: auto;
}

.swipe-stage {
  position: relative;
  overflow: hidden;
  touch-action: pan-y pan-x pinch-zoom;
  border-radius: 0.5rem;
  isolation: isolate;
}

.swipe-underlay {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  z-index: 0;
  background: var(--pico-background-color);
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}

.swipe-underlay--next {
  left: 100%;
  right: auto;
}

.swipe-underlay--prev {
  left: 0;
  right: auto;
}

.swipe-underlay.is-visible {
  opacity: 1;
}

.swipe-card {
  position: relative;
  z-index: 1;
  background: var(--pico-background-color);
  will-change: transform;
  backface-visibility: hidden;
}

.swipe-stage.is-dragging {
  user-select: none;
}

.swipe-stage.is-dragging .swipe-card {
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
}

/* ── Adjust page (admin tool) ── */

.adjust-page .page-header h1 {
  font-size: var(--type-page-title);
  font-weight: 600;
}

.adjust-layout {
  display: grid;
  gap: 0.75rem;
}

.adjust-sidebar label {
  margin-top: 0.5rem;
}

.adjust-sidebar input,
.adjust-sidebar select {
  margin-bottom: 0.5rem;
  font-size: var(--type-subhead);
}

.adjust-sidebar .grid label {
  font-size: var(--type-caption);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  color: var(--app-text-tertiary);
}

.adjust-sidebar .toolbar a,
.adjust-sidebar .toolbar button,
.nudge-grid button {
  min-height: var(--app-touch);
  margin: 0;
  font-size: var(--type-subhead);
  font-weight: 500;
}

.adjust-sidebar .toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.nudge-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}

.nudge-grid button {
  width: 100%;
  padding: 0.45rem 0.35rem;
}

.hint {
  margin-top: 0.5rem;
  font-size: var(--type-caption);
  line-height: 1.45;
  color: var(--app-text-tertiary);
}

.adjust-preview {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  border: 1px solid var(--pico-muted-border-color);
  background: var(--pico-card-background-color);
}

.bbox-box {
  position: absolute;
  border: 2px solid var(--pico-del-color);
  background: color-mix(in srgb, var(--pico-del-color) 15%, transparent);
  pointer-events: none;
}

/* ── Responsive ── */

@media (min-width: 768px) {
  body > main.home-page,
  body > main.paper-page {
    max-width: 22.5rem;
  }

}

@media (min-width: 1200px) {
  .adjust-layout {
    grid-template-columns: 2fr 1fr;
    align-items: start;
  }

  .adjust-sidebar {
    position: sticky;
    top: 1rem;
  }
}

@media (max-width: 767px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
