:root {
  color-scheme: light;
  --accent: #05a8a4;
  --accent-dark: #037e7b;
  --accent-soft: #e7f7f6;
  --ink: #263b3b;
  --muted: #657373;
  --line: #c9dfde;
  --surface: #ffffff;
  --canvas-bg: #dbe8e7;
  font-family: "Meiryo", "Yu Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--canvas-bg); color: var(--ink); }

body { overscroll-behavior-y: none; }

button, input { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

.toolbar {
  position: sticky;
  z-index: 20;
  top: 0;
  padding: calc(8px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, white 96%, var(--accent));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 3px 14px rgb(15 65 64 / 12%);
}

.brand-row, .search-row, .control-row, .page-controls, .zoom-controls, .result-controls {
  display: flex;
  align-items: center;
}

.brand-row { min-height: 34px; gap: 10px; }

.brand-mark {
  color: var(--accent-dark);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: .16em;
}

.document-name { flex: 1; font-size: .82rem; font-weight: 700; color: var(--muted); }

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: .8rem;
  font-weight: 700;
  text-decoration: none;
}

.search-row { gap: 8px; margin-top: 7px; }

.search-row input {
  min-width: 0;
  min-height: 48px;
  flex: 1;
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 0 14px;
  background: white;
  color: var(--ink);
  font-size: 1rem;
  outline: none;
}

.search-row input:focus { box-shadow: 0 0 0 3px rgb(5 168 164 / 20%); }

.primary-button {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.control-row { justify-content: space-between; gap: 8px; margin-top: 8px; }

.control-row button {
  min-width: 36px;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: var(--accent-dark);
  font-weight: 800;
}

.control-row button:disabled { opacity: .35; }

.result-controls { min-width: 0; gap: 5px; }

#searchStatus {
  max-width: 138px;
  overflow: hidden;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-controls { gap: 4px; }

#pageNumber {
  width: 44px;
  min-height: 36px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
}

#pageTotal { color: var(--muted); font-size: .78rem; }

.zoom-controls { gap: 4px; }

#zoomReset { min-width: 60px; font-size: .7rem; }

.viewer {
  min-height: calc(100vh - 154px);
  padding: 14px 8px calc(24px + env(safe-area-inset-bottom));
  overflow-x: auto;
}

.pages {
  display: flex;
  width: 100%;
  min-width: 100%;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.page-shell {
  position: relative;
  flex: none;
  scroll-margin-top: 190px;
}

.page-stage {
  position: relative;
  background: white;
  box-shadow: 0 10px 30px rgb(27 62 61 / 20%);
}

.page-canvas { display: block; max-width: none; }

.page-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: linear-gradient(135deg, #fff 0%, #f1f8f7 100%);
  font-size: .82rem;
  font-weight: 700;
}

.page-placeholder[hidden] { display: none; }

.page-label {
  position: absolute;
  z-index: 3;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgb(38 59 59 / 72%);
  color: white;
  font-size: .7rem;
  font-weight: 700;
  pointer-events: none;
}

.annotation-layer { position: absolute; inset: 0; pointer-events: none; }

.annotation-layer a {
  position: absolute;
  border-radius: 2px;
  pointer-events: auto;
}

.annotation-layer a:focus-visible { outline: 3px solid #ffbf47; background: rgb(255 191 71 / 18%); }

.loading-card, .error-panel {
  margin: 14vh auto 0;
  padding: 24px;
  border-radius: 16px;
  background: white;
  text-align: center;
  box-shadow: 0 8px 30px rgb(27 62 61 / 14%);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.error-panel { max-width: 340px; }
.error-panel span { display: block; margin: 8px 0 16px; color: var(--muted); }
.error-panel button { min-height: 44px; border: 0; border-radius: 10px; padding: 0 18px; background: var(--accent); color: white; font-weight: 800; }

.back-to-menu {
  position: fixed;
  z-index: 50;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: inline-flex;
  min-height: 50px;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  border: 2px solid white;
  border-radius: 999px;
  background: #4c4948;
  color: white;
  box-shadow: 0 6px 22px rgb(0 0 0 / 28%);
  font-size: 1rem;
  font-weight: 800;
}

.back-to-menu[hidden] { display: none; }
.back-to-menu:focus-visible { outline: 3px solid #ffbf47; outline-offset: 3px; }
.back-to-menu:active { transform: translateY(1px); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  .toolbar { padding-inline: 8px; }
  .control-row { flex-wrap: wrap; }
  .result-controls { order: 1; flex: 1 1 145px; }
  .page-controls { order: 2; }
  .zoom-controls { order: 3; margin-left: auto; }
  .viewer { min-height: calc(100vh - 196px); }
  .page-shell { scroll-margin-top: 220px; }
}

@media (min-width: 760px) {
  .toolbar { padding-inline: max(18px, calc((100vw - 900px) / 2)); }
  .brand-row { min-height: 38px; }
  .search-row { max-width: 900px; margin-inline: auto; }
  .control-row { max-width: 900px; margin-inline: auto; margin-top: 8px; }
}
