:root {
  color-scheme: light dark;
  --page: var(--tg-theme-secondary-bg-color, light-dark(#efeff4, #0e1621));
  --paper: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, light-dark(#fff, #17212b)));
  --ink: var(--tg-theme-text-color, light-dark(#1c1c1e, #f5f5f5));
  --muted: var(--tg-theme-hint-color, light-dark(#707579, #8e9eaf));
  --line: var(--tg-theme-section-separator-color, light-dark(#d9d9de, #293744));
  --blue: var(--tg-theme-link-color, light-dark(#2481cc, #6ab2f2));
  --button: var(--tg-theme-button-color, light-dark(#2481cc, #6ab2f2));
  --button-text: var(--tg-theme-button-text-color, light-dark(#fff, #0e1621));
  --label: var(--tg-theme-section-header-text-color, var(--muted));
  --danger: var(--tg-theme-destructive-text-color, light-dark(#c73535, #ff7979));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --action-height: 0px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  background: var(--page);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; overflow-wrap: anywhere; }
button, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; min-height: 48px; }
button:disabled { opacity: .42; cursor: default; }
button:focus-visible, summary:focus-visible, .photo-view:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 21px; font-weight: 650; line-height: 1.3; }
h2 { font-size: 17px; font-weight: 550; line-height: 1.35; }
#app { max-width: 720px; margin: 0 auto; padding: calc(16px + var(--safe-top)) max(16px, var(--tg-content-safe-area-inset-right, 0px)) calc(24px + var(--safe-bottom) + var(--action-height)) max(16px, var(--tg-content-safe-area-inset-left, 0px)); }
.app-heading { margin: 0 0 16px; }
.heading-line, .meta-line, .section-heading, .detail-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.meta-line { margin-top: 3px; flex-wrap: wrap; gap: 0 12px; }
.meta, .muted, .field-label, .item-position { color: var(--muted); font-size: 14px; }
.text-button { color: var(--blue); padding: 8px 0; display: inline-flex; align-items: center; gap: 6px; text-align: left; }
.photo-link { font-size: 14px; white-space: nowrap; }
.section-links { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 20px; padding: 2px 0 4px; }
.section-link { min-width: 48px; max-width: 260px; flex: 0 0 auto; border-radius: 10px; background: var(--paper); padding: 10px 14px; text-align: left; color: var(--blue); font-size: 14px; }
.section { margin-bottom: 24px; scroll-margin-top: calc(12px + var(--safe-top)); }
.section-heading { align-items: baseline; padding: 0 12px 8px; }
.section-heading h2 { color: var(--label); font-size: 13px; font-weight: 450; }
.section-count { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.answer-list { background: var(--paper); border-radius: 11px; overflow: hidden; }
.answer-entry { position: relative; display: flex; align-items: center; }
.answer-entry + .answer-entry::before { content: ""; position: absolute; top: 0; left: 56px; right: 0; height: .5px; background: var(--line); }
.answer-entry.is-selected { background: color-mix(in srgb, var(--blue) 10%, var(--paper)); }
.answer-row { min-width: 0; flex: 1; width: 100%; display: grid; grid-template-columns: minmax(28px, auto) minmax(0, 1fr) 12px; align-items: center; gap: 10px; padding: 13px 14px; text-align: left; min-height: 66px; }
.row-number { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; max-width: 58px; }
.row-content { min-width: 0; }
.row-answer { font-size: 18px; white-space: pre-wrap; max-height: 5.4em; overflow: hidden; }
.answer-row .code { max-height: 5.4em; }
.row-preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 15px; }
.row-status { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
.row-status.error { color: var(--danger); }
.row-chevron { color: var(--muted); font-size: 23px; line-height: 1; }
.row-action { color: var(--blue); font-size: 14px; padding: 10px 14px 10px 0; flex: 0 0 auto; }
.list-hint { color: var(--muted); font-size: 14px; padding: 0 4px; }
.progress { margin: 12px 0 2px; }
progress { width: 100%; height: 5px; border: 0; border-radius: 5px; accent-color: var(--blue); display: block; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 5px; }
progress::-webkit-progress-value { background: var(--blue); border-radius: 5px; }
.back-link { margin-bottom: 4px; }
.detail-heading { margin: 4px 3px 13px; }
.item-position { white-space: nowrap; }
.panel { background: var(--paper); border-radius: 11px; padding: 16px; min-width: 0; margin-bottom: 12px; }
.field-label { margin-bottom: 10px; }
.answer-panel .field-label { color: var(--blue); }
.rich-text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.answer-text { font-size: 20px; }
.math { display: inline-block; vertical-align: middle; max-width: 100%; overflow-x: auto; overflow-y: hidden; white-space: nowrap; padding: 4px 0; line-height: normal; }
.math[data-display="true"] { display: block; padding: 6px 0; }
.math .katex { font-size: 1.08em; }
.math .katex-display { margin: 0; text-align: left; }
.math .katex-display > .katex { text-align: left; }
.code { font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; overflow: auto; max-width: 100%; margin: 0; tab-size: 4; overflow-wrap: normal; padding: 3px 0; }
.solution-toggle { min-height: 54px; display: flex; align-items: center; justify-content: space-between; color: var(--blue); cursor: pointer; list-style: none; }
.solution-toggle::-webkit-details-marker { display: none; }
.solution-toggle::after { content: "+"; font-size: 23px; font-weight: 300; }
details[open] > .solution-toggle::after { content: "−"; }
.full-solution { margin: 0 2px 12px; }
.steps { list-style: none; padding: 0; margin: 0; border-top: .5px solid var(--line); }
.step { display: grid; grid-template-columns: 25px minmax(0, 1fr); gap: 8px; padding: 11px 0; }
.step-number { color: var(--muted); font-size: 13px; padding-top: 2px; }
.prev-next { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 17px 0 24px; }
.prev-next button { background: var(--paper); border-radius: 11px; color: var(--blue); padding: 11px 8px; font-size: 15px; }
.jump-section { margin: 0 0 18px; }
.jump-section h3 { font-size: 13px; color: var(--label); font-weight: 450; margin-bottom: 9px; }
.number-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 7px; }
.number-button { background: var(--paper); border-radius: 9px; font-size: 15px; font-variant-numeric: tabular-nums; position: relative; padding: 7px 3px; }
.number-button.is-current { background: var(--button); color: var(--button-text); }
.number-button.is-ready:not(.is-current)::after { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--blue); position: absolute; bottom: 4px; left: calc(50% - 2px); }
.bottom-actions { position: fixed; z-index: 5; bottom: 0; left: 0; right: 0; padding: 10px max(16px, var(--tg-content-safe-area-inset-right, 0px)) calc(10px + var(--safe-bottom)) max(16px, var(--tg-content-safe-area-inset-left, 0px)); background: var(--page); border-top: .5px solid var(--line); }
.action-inner { max-width: 688px; margin: 0 auto; display: flex; flex-direction: column; gap: 7px; }
.primary { border-radius: 11px; min-height: 50px; padding: 12px 16px; background: var(--button); color: var(--button-text); font-weight: 550; width: 100%; }
.secondary { border-radius: 11px; background: var(--paper); color: var(--blue); padding: 11px 16px; width: 100%; }
.action-note { color: var(--muted); text-align: center; font-size: 12px; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; text-align: center; gap: 14px; padding: 24px 8px; }
.empty-state p { color: var(--muted); max-width: 330px; }
.empty-state button { width: min(100%, 330px); }
.spinner { width: 23px; height: 23px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-style: dotted; } }
.connection { position: fixed; z-index: 10; top: var(--safe-top); left: 12px; right: 12px; max-width: 680px; margin: 0 auto; background: var(--paper); border: .5px solid var(--line); border-radius: 10px; box-shadow: 0 3px 14px #0001; padding: 9px 12px; color: var(--muted); font-size: 13px; text-align: center; }
dialog { width: min(720px, calc(100% - 20px)); max-width: calc(100% - 20px); max-height: calc(var(--viewport-stable-height, 100dvh) - 30px - var(--safe-top) - var(--safe-bottom)); padding: 0; border: .5px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); }
dialog::backdrop { background: #05090ca6; }
.photo-toolbar { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 16px; }
.photo-toolbar h2 { flex: 1; min-width: 0; }
.photo-toolbar .text-button { font-size: 14px; }
.photo-pagination { display: flex; align-items: center; justify-content: center; gap: 16px; border-top: .5px solid var(--line); }
.photo-pagination button { min-width: 48px; min-height: 48px; color: var(--blue); font-size: 23px; }
.photo-pagination span { min-width: 64px; text-align: center; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.photo-pagination:not([hidden]) ~ .photo-view { max-height: calc(var(--viewport-stable-height, 100dvh) - 180px - var(--safe-top) - var(--safe-bottom)); }
.icon-button { width: 48px; height: 48px; flex-shrink: 0; font-size: 28px; color: var(--blue); }
.photo-view { overflow: auto; max-height: calc(var(--viewport-stable-height, 100dvh) - 130px - var(--safe-top) - var(--safe-bottom)); overscroll-behavior: contain; }
.photo-view img { width: 100%; height: auto; display: block; }
.photo-view.is-zoomed img { width: 200%; max-width: none; }
.photo-status { padding: 0 16px 12px; font-size: 14px; color: var(--muted); }
.photo-status:empty { display: none; }
@media (max-width: 360px) { #app { padding-left: 12px; padding-right: 12px; } .answer-row { gap: 7px; padding-left: 12px; padding-right: 10px; } .row-action { padding-right: 10px; font-size: 13px; } .prev-next button { font-size: 14px; } }

/* Number-first navigation: the worksheet is a small set of clear tap targets. */
#app { max-width: 520px; padding-top: calc(18px + var(--safe-top)); padding-bottom: calc(12px + var(--safe-bottom)); }
.app-heading { margin-bottom: 24px; }
.heading-line { gap: 10px; }
.app-heading h1 { font-size: 24px; font-weight: 650; letter-spacing: -.5px; }
.intro { color: var(--muted); font-size: 16px; margin-top: 4px; }
.photo-link { min-width: 60px; min-height: 48px; padding: 8px 12px; border-radius: 10px; background: var(--paper); justify-content: center; font-size: 16px; flex-shrink: 0; }
.section { margin-bottom: 24px; }
.section-heading { padding: 0 0 11px; }
.section-heading h2 { font-size: 18px; color: var(--ink); font-weight: 600; }
.number-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; }
.number-button { display: grid; place-items: center; min-width: 48px; min-height: 60px; border-radius: 12px; padding: 8px; background: var(--paper); color: var(--ink); }
.number-button:active { background: color-mix(in srgb, var(--blue) 10%, var(--paper)); }
.tile-number { font-size: 24px; font-weight: 550; }
.tile-source { display: block; max-width: 100%; color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.long-number .tile-number { font-size: 18px; overflow-wrap: anywhere; text-align: center; }
.number-button.is-ready:not(.is-current)::after { content: none; }
.tile-check { position: absolute; right: 7px; top: 4px; color: var(--blue); font-size: 13px; font-weight: 650; }
.tile-spinner { position: absolute; right: 6px; top: 6px; width: 12px; height: 12px; border-width: 1.5px; }
.work-status { margin-top: 14px; }
.work-status-line { display: flex; justify-content: space-between; align-items: center; min-height: 48px; gap: 10px; }
.work-status-text { display: inline-flex; gap: 8px; align-items: center; font-size: 15px; color: var(--muted); }
.small-spinner { width: 15px; height: 15px; border-width: 1.5px; }
.stop-button { min-width: 54px; justify-content: center; font-size: 16px; }
.work-status progress { height: 3px; }
.worksheet-actions { max-width: 520px; margin: 0 auto; padding: 0 max(16px, var(--tg-content-safe-area-inset-right, 0px)) calc(24px + var(--safe-bottom)) max(16px, var(--tg-content-safe-area-inset-left, 0px)); }
.action-inner { max-width: none; }
.worksheet-actions .primary { min-height: 54px; font-size: 17px; }
.action-error { padding: 14px 16px 4px; background: var(--paper); border-radius: 11px; font-size: 16px; }
.retry-action { min-height: 48px; margin-top: 3px; }
.connection { position: static; max-width: 488px; margin: 12px auto 0; width: calc(100% - 32px); box-shadow: none; text-align: left; font-size: 14px; }
.back-link { min-height: 48px; font-size: 16px; margin-bottom: 5px; }
.detail-heading { margin-bottom: 15px; }
.detail-heading h1 { font-size: 22px; }
.detail-heading + .work-status { margin-top: 0; margin-bottom: 16px; }
.condition-panel { padding: 14px 16px; font-size: 16px; }
.condition-panel .field-label { font-size: 13px; margin-bottom: 8px; }
.condition-preview.is-collapsed { max-height: var(--condition-preview-height, 116px); overflow: hidden; }
.condition-toggle { display: flex; width: 100%; min-height: 48px; margin-top: 4px; padding: 8px 0 0; font-size: 16px; }
.answer-text { font-size: 23px; line-height: 1.5; }
.answer-panel .code { font-size: 15px; }
.drawing-card { margin: 0 0 12px; padding: 14px 12px; background: var(--paper); border-radius: 11px; min-width: 0; }
.drawing-title { margin: 0 4px 10px; font-size: 16px; font-weight: 550; line-height: 1.35; overflow-wrap: anywhere; }
.drawing-canvas { display: block; width: 100%; height: auto; min-height: 260px; aspect-ratio: 3 / 2; max-width: 100%; color: var(--ink); }
.drawing-caption, .drawing-error { margin: 10px 4px 0; font-size: 14px; line-height: 1.45; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-spinner { width: 18px; height: 18px; float: right; margin-top: 3px; }
.get-answer { margin-top: 15px; }
.prev-next { margin-bottom: 12px; }
.prev-next button { min-height: 52px; }
dialog { width: min(520px, calc(100% - 20px)); }
@media (max-width: 360px) {
  .number-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .worksheet-actions { padding-left: 12px; padding-right: 12px; }
  .app-heading h1 { font-size: 22px; }
}
@media (min-width: 480px) { .number-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
