:root {
  color-scheme: light;
  --brand: #a5b55a;
  --brand-ink: #17200d;
  --canvas: #f1f0e8;
  --panel: rgba(251, 252, 248, 0.96);
  --panel-solid: #fbfcf8;
  --text: #293322;
  --muted: #65705e;
  --line: #dce2d2;
  --soft: #edf1e4;
  --rail-width: 300px;
  --region-top: max(58px, calc(env(safe-area-inset-top) + 52px));
  --viewer-top: calc(var(--region-top) + 62px);
  --toolbar-bottom: max(44px, calc(env(safe-area-inset-bottom) + 32px));
  --toolbar-height: 196px;
  --controls-gap: 4px;
  --region-bottom: calc(var(--toolbar-bottom) + var(--toolbar-height) + var(--controls-gap));
}

* { box-sizing: border-box; }
html, body, #app, #viewer { width: 100%; height: 100%; margin: 0; }
html, body { overflow: hidden; background: var(--canvas); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
#app { position: relative; overflow: hidden; background: var(--panel-solid); }
#viewer { width: calc(100% - 20px); left: 10px; height: calc(100% - var(--toolbar-bottom) - var(--toolbar-height) - 8px - var(--viewer-top)); top: var(--viewer-top); position: relative; z-index: 0; isolation: isolate; background: var(--canvas); touch-action: none; border-radius: 18px; overflow: hidden; }

.status {
  position: absolute; left: 50%; top: 50%; z-index: 60; max-width: min(88vw, 560px);
  padding: 12px 16px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px;
  background: var(--panel); color: var(--text); font-size: 14px; line-height: 1.5; text-align: center;
  pointer-events: none; transform: translate(-50%, -50%); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.error { background: #862f2a; color: #fff; }
.hint {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 12px; z-index: 31;
  padding: 8px 12px; border: 1px solid rgba(255,255,255,.12); border-radius: 999px;
  background: var(--panel); color: var(--text); font-size: 12px; white-space: nowrap;
  pointer-events: none; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.toast {
  position: absolute; left: 50%; bottom: calc(var(--region-bottom) + 64px); z-index: 70; max-width: calc(100vw - 32px);
  padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--panel-solid);
  font-size: 13px; white-space: nowrap; pointer-events: none; transform: translateX(-50%);
}
#detail-status { top: var(--viewer-top); max-width: calc(100% - 24px); white-space: normal; }
#retry-details { pointer-events: auto; min-height: 44px; border: 0; border-radius: 8px; background: var(--brand); color: var(--brand-ink); padding: 0 10px; }
.view-tools { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); display: flex; gap: 6px; z-index: 38; }
.view-tools-spacer { flex: 1; }
.view-tools button { min-width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-solid); color: var(--text); font-size: 18px; padding: 0 12px; }
.view-tools #home, .view-tools #viewer-help { font-size: 13px; }
#help-dialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel-solid); color: var(--text); }
#help-dialog::backdrop { background: rgba(0,0,0,.65); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-header h2 { margin: 0; font-size: 20px; }
#help-dialog button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); color: var(--text); font-size: 14px; }
.help-steps { margin: 20px 0; }
.help-steps div + div { margin-top: 16px; }
.help-steps dt, .help-section h3 { margin: 0 0 6px; font-size: 14px; font-weight: 650; }
.help-steps dd, .help-section p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.help-section { padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line); }
.help-section p { margin: 8px 0 12px; }
.help-actions { display: flex; gap: 10px; }
#size-calibration { width: min(400px, calc(100vw - 32px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 22px; border: 1px solid var(--line);
  border-radius: 16px; background: var(--panel-solid); color: var(--text); }
#size-calibration::backdrop { background: rgba(0,0,0,.65); }
#size-calibration h2 { margin: 0; font-size: 20px; }
#size-calibration p { font-size: 14px; line-height: 1.6; }
.ruler-track { display: flex; justify-content: center; align-items: center; height: 50px; }
#ruler-line { flex-shrink: 0; height: 20px; position: relative; border-left: 1px solid var(--text); border-right: 1px solid var(--text); }
#ruler-line::after { content: ''; position: absolute; top: 9px; left: 0; right: 0; border-top: 1px solid var(--text); }
#ruler-size { display: block; width: 100%; min-height: 44px; margin: 0; accent-color: var(--brand); }
.calibration-actions { display: flex; justify-content: flex-end; gap: 12px; }
.calibration-actions button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 10px; }
#save-calibration { background: var(--brand); color: var(--brand-ink); }

.region-shell {
  position: absolute; left: 0; right: 0; top: var(--region-top); z-index: 36; display: flex;
  align-items: center; gap: 6px; padding: 4px 12px;
  background: var(--panel-solid); pointer-events: none;
}
.region-nav {
  display: flex; flex: 1 1 auto; min-width: 0; gap: 4px; overflow-x: auto; overflow-y: hidden;
  padding: 2px 0; scrollbar-width: thin; scrollbar-color: #a9b395 transparent; -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity; scroll-padding-inline: 8px; pointer-events: auto;
}
.region-nav::-webkit-scrollbar { height: 3px; width: 3px; }
.region-nav::-webkit-scrollbar-thumb { background: #a9b395; border-radius: 3px; }
.region-button {
  flex: 0 0 auto; min-height: 44px; padding: 0 8px; border: 1px solid transparent;
  border-radius: 10px; background: var(--panel-solid); color: var(--text); font-size: 12px; font-weight: 500;
  white-space: nowrap; scroll-snap-align: center; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.region-button:first-child { background: var(--panel-solid); position: sticky; left: 0; z-index: 2; box-shadow: 6px 0 8px var(--panel-solid); }
.region-button.active { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); }
.region-button:active { opacity: .86; transform: scale(.98); }
.region-dot {
  display: inline-block; width: 8px; height: 8px; margin-right: 7px; border: 1px solid rgba(255,255,255,.42);
  border-radius: 3px; vertical-align: 1px;
}

.toolbar {
  position: absolute; left: 50%; bottom: var(--toolbar-bottom); z-index: 38;
  display: grid; grid-template-rows: 34px 44px 44px 44px; gap: 4px; padding: 8px;
  height: var(--toolbar-height); width: min(520px, calc(100% - 24px));
  border: 0; border-radius: 18px; background: var(--panel-solid);
  color: var(--text); transform: translateX(-50%);
}
.follow-heading { padding: 0 4px; overflow: hidden; }
#follow-status { display: block; font-size: 14px; line-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mode-hint { color: var(--muted); font-size: 12px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playback-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.auto-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.follow-options { display: grid; grid-template-columns: repeat(3, 1fr); align-items: center; gap: 4px; }
.toolbar button { min-width: 0; min-height: 44px; padding: 0 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-solid); color: var(--text); font-size: 14px; font-weight: 500; white-space: nowrap; }
.toolbar button:active { opacity: .85; }
.toolbar #auto-restore { background: var(--brand); color: var(--brand-ink); border-color: transparent; font-size: 15px; }
.toolbar #auto-restore[aria-pressed="true"] { background: #dce8aa; }
.follow-options button { background: transparent; border-color: transparent; color: var(--muted); font-size: 13px; font-weight: 500; }
#restore-speed { font-variant-numeric: tabular-nums; min-width: 94px; }
#feedback-dialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel-solid); color: var(--text); }
#feedback-dialog::backdrop { background: rgba(0,0,0,.55); }
#feedback-dialog button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); color: var(--text); }
#feedback-form { display: grid; gap: 10px; margin-top: 20px; }
#feedback-form label { font-size: 14px; }
#feedback-form textarea, #feedback-form input { display: block; width: 100%; min-width: 0; min-height: 44px; padding: 10px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #fff; }
#feedback-form textarea { resize: vertical; min-height: 100px; }
#feedback-form p { margin: 0; font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
#feedback-context { color: var(--muted); }
#feedback-result[data-error="true"] { color: #a12f27; }
#feedback-form #feedback-submit { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.region-button:focus-visible { outline-offset: -3px; }
@media (max-width: 600px) {
  .toolbar { width: calc(100% - 16px); }
}

.region-overlay { position: relative; transform-origin: 0 0; }
/* OSD writes display:block every frame; hidden SVG text must not keep scaling/layout. */
.region-overlay[hidden] { display: none !important; }
.region-overlay svg { display: block; width: 100%; height: 100%; overflow: visible; }
.region-group { cursor: pointer; }
.region-shape {
  stroke-width: 3; stroke-opacity: .95; vector-effect: non-scaling-stroke;
  transition: fill-opacity .12s ease, stroke-width .12s ease, stroke-opacity .12s ease;
}
.region-group:active .region-shape { fill-opacity: .34; stroke-width: 5; }
.region-label {
  fill: #f5f7ef; font-weight: 750; text-anchor: middle; dominant-baseline: middle; paint-order: stroke;
  stroke: rgba(14,18,10,.78); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; user-select: none;
}

@media (hover: hover) and (pointer: fine) {
  .region-group:hover .region-shape { fill-opacity: .3; stroke-width: 4; }
  .region-button:hover, .toolbar button:hover { border-color: rgba(150,166,68,.72); }
}

@media (min-width: 900px) and (orientation: landscape) {
  :root { --viewer-top: max(58px, calc(env(safe-area-inset-top) + 50px)); }
  #viewer { width: calc(100% - var(--rail-width) - 20px); height: calc(100% - var(--viewer-top) - 12px); }
  .view-tools { right: calc(var(--rail-width) + 12px); }
  .toast, .status { left: calc((100% - var(--rail-width)) / 2); }
  .toolbar { left: auto; right: 12px; width: 276px; transform: none; }
  .region-shell {
    top: 16px; right: 12px; bottom: calc(var(--toolbar-bottom) + var(--toolbar-height) + 12px); left: auto; width: 276px; padding: 0;
    flex-direction: column; align-items: stretch; gap: 10px; background: transparent;
  }
  .region-nav {
    order: 2; flex-direction: column; overflow-x: hidden; overflow-y: auto; padding: 8px;
    border: 1px solid var(--line); border-radius: 16px; background: var(--panel-solid);
    scroll-snap-type: y proximity; scroll-padding: 60px 0 0;
  }
  .region-button {
    width: 100%; min-height: 46px; padding: 0 12px; overflow: hidden; border-radius: 12px;
    text-align: left; text-overflow: ellipsis; scroll-snap-align: center; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .region-button:first-child { top: 0; left: auto; box-shadow: 0 8px 14px var(--panel-solid); }
  .toast { bottom: calc(var(--toolbar-bottom) + var(--toolbar-height) + 16px); }
}

/* Keep the artwork usable when a phone is turned sideways. */
@media (min-width: 600px) and (max-height: 500px) and (orientation: landscape) {
  :root { --rail-width: 300px; --viewer-top: max(58px, calc(env(safe-area-inset-top) + 50px)); }
  #viewer { width: calc(100% - var(--rail-width) - 20px); height: calc(100% - var(--viewer-top) - 12px); }
  .view-tools { right: calc(var(--rail-width) + 12px); }
  .status, .toast { left: calc((100% - var(--rail-width)) / 2); }
  .region-shell { top: 8px; bottom: calc(var(--toolbar-bottom) + var(--toolbar-height) + 8px); right: 8px; left: auto; width: 284px; padding: 0; flex-direction: column; align-items: stretch; gap: 4px; }
  .region-nav { order: 2; flex-direction: column; overflow-x: hidden; overflow-y: auto; scroll-snap-type: y proximity; scroll-padding: 50px 0 0; }
  .region-button { text-align: left; }
  .region-button:first-child { top: 0; left: auto; }
  .toolbar { left: auto; right: 8px; width: 284px; transform: none; }
  .toast { bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .status, .hint, .region-button, .toolbar {
    background: var(--panel-solid); backdrop-filter: none; -webkit-backdrop-filter: none;
  }
}

/* Explicit centering is consistent across browser and WeChat WebView fonts. */
.view-tools button, .toolbar button, .calibration-actions button, #help-dialog button, #feedback-dialog button {
  display: inline-flex; align-items: center; justify-content: center; text-align: center; line-height: 1.25;
}
.follow-heading { text-align: center; }

button[hidden] { display: none !important; }
.icp-footer {
  position: absolute; left: 50%; bottom: max(2px, env(safe-area-inset-bottom)); z-index: 41;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  max-width: calc(100% - 24px); color: var(--muted); font-size: 10px; line-height: 12px;
  text-align: center; white-space: nowrap; transform: translateX(-50%);
}
.icp-footer a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
/* r22: image-first controls with the same light, rounded language as the gallery. */
:root { --brand: #96a644; --canvas: #f2f4ea; }
.work-title { align-self:center; min-width:0; max-width:34vw; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; font-size:15px; font-weight:600; color:var(--text); }
.view-tools { align-items:center; gap:8px; }
.view-tools button { border:0; border-radius:50%; background:var(--soft); padding:0; width:44px; flex-shrink:0; }
.view-tools #home { width:52px; border-radius:22px; }
.view-tools #viewer-help { font-size:19px; font-weight:600; }
.region-button { display:inline-flex; align-items:center; justify-content:center; gap:3px; border-radius:14px; background:var(--soft); line-height:1.3; }
.region-number { display:inline-flex; align-items:center; justify-content:center; flex-shrink:0; min-width:0; height:auto; padding:0; color:var(--muted); font-size:10px; font-variant-numeric:tabular-nums; }
.region-button.active { background:var(--brand); }
.toolbar { border-radius:20px; }
.follow-heading { text-align:left; padding:0 8px; }
.toolbar button { border:0; border-radius:22px; background:var(--soft); }
.toolbar #auto-restore { font-weight:600; }
.follow-options button { background:transparent; }
#viewer { border-radius:22px; }
@media (min-width: 900px) and (orientation: landscape) {
 .region-button { justify-content:flex-start; border-radius:16px; }
 .region-nav { border:0; background:transparent; }
}
@media (min-width:600px) and (max-height:500px) and (orientation:landscape) {
 .region-button { justify-content:flex-start; }
 .work-title { max-width:18vw; }
}

.region-button.active .region-number { color:var(--brand-ink); }
