:root {
  --paper: #fafafa;
  --surface: #ffffff;
  --ink: #111111;
  --muted: #555555;
  --line: #bdbdbd;
}

* {
  box-sizing: border-box;
}

/* hidden 属性を author CSS の display 指定より常に優先させる（img/div の display:block に負けないため） */
[hidden] {
  display: none !important;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  color: var(--ink);
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.site-header,
.page-shell,
.site-footer {
  width: min(1180px, calc(100% - 40px));
  margin-right: auto;
  margin-left: auto;
}

.site-header {
  padding: 64px 0 30px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.35rem;
  line-height: 1.2;
}

h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.lede,
.muted {
  color: var(--muted);
}

.lede {
  max-width: 50rem;
  margin-bottom: 0;
}

.page-shell {
  padding: 24px 0 48px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 48px;
  padding: 10px 24px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--surface);
  font-weight: 700;
}

.tab:hover,
.tab.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.tab-panel[hidden] {
  display: none;
}

.search-panel,
.info-card,
.viewer-card,
.compare-pane {
  border: 1px solid var(--line);
  background: var(--surface);
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(280px, 1.4fr);
  gap: 20px 32px;
  align-items: start;
  padding: 24px;
}

.search-panel .status {
  grid-column: 1 / -1;
}

.search-panel h2,
.compare-heading h2 {
  margin-bottom: 5px;
}

.search-panel .muted,
.compare-heading .muted {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.search-form label,
.compare-search label,
.viewer-toolbar > label:first-child {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 700;
}

.search-row {
  display: flex;
  gap: 8px;
}

input[type="search"],
select {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  padding: 8px 12px;
}

input[type="search"] {
  width: 100%;
}

input[type="search"]:focus,
select:focus {
  border-color: var(--ink);
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 44px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  padding: 8px 14px;
  font-weight: 700;
}

.primary-button:hover,
.secondary-button:hover,
.text-button:hover {
  background: var(--ink);
  color: var(--surface);
}

.primary-button {
  min-width: 76px;
  background: var(--ink);
  color: var(--surface);
}

.primary-button:hover {
  background: var(--surface);
  color: var(--ink);
}

.text-button {
  min-height: 34px;
  padding: 4px 8px;
  border-color: transparent;
  font-weight: 600;
}

.input-detection,
.status {
  min-height: 1.35em;
}

.input-detection {
  overflow: hidden;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.status-link {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 検索失敗時に入力欄を 2 回だけ赤く光らせる（入力すると消える） */
@keyframes error-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0); border-color: var(--line); }
  50% { box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.35); border-color: #c0392b; }
}

.search-row.is-error input[type="search"] {
  animation: error-glow 0.7s ease-in-out 2;
  border-color: #c0392b;
}

.candidate-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.candidate-list[hidden] {
  display: none;
}

.candidate-list p {
  width: 100%;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.single-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 20px;
  margin-top: 20px;
}

.info-card,
.viewer-card {
  min-width: 0;
  padding: 24px;
}

.card-heading,
.compare-heading {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
}

.card-heading h2,
.card-heading h3 {
  overflow-wrap: anywhere;
}

.cid-label,
.viewer-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.compound-facts,
.compact-facts {
  margin: 24px 0;
}

.compound-facts > div,
.compact-facts > div {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.compound-facts > div:last-child,
.compact-facts > div:last-child {
  border-bottom: 1px solid var(--line);
}

dt {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.structure-2d h3,
.viewer-label {
  margin-top: 0;
  margin-bottom: 8px;
}

.structure-frame {
  display: grid;
  min-height: 260px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
}

.structure-frame img {
  display: block;
  width: min(100%, 360px);
  height: auto;
}

/* 2D 構造式の回転台。3D の見え方に合わせて transform: rotate()（裏面なら scaleX(-1)）を JS が付ける */
.structure-rotor {
  display: grid;
  width: 100%;
  place-items: center;
  transform-origin: center;
  will-change: transform;
  transition: opacity 0.2s;
}

/* 3D が傾いていて 2D と対応しないときは薄くして知らせる */
.structure-rotor.is-tilted {
  opacity: 0.35;
}

.structure-note {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  font-size: 0.7rem;
  pointer-events: none;
}

.single-grid .structure-frame,
.compact-structure {
  position: relative;
}

.structure-svg {
  display: grid;
  width: 100%;
  min-height: 240px;
  place-items: center;
}

.structure-svg svg {
  display: block;
  width: min(100%, 360px);
  height: auto;
}

.viewer-frame {
  position: relative;
  min-height: 470px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
}

.single-grid .structure-frame,
.single-grid .viewer-frame {
  height: 470px;
  min-height: 0;
}

.viewer {
  width: 100%;
  height: 100%;
  min-height: 470px;
}

/* 画面固定の軸ガイド。ビューア中央に置き、分子とは独立に常に X 右・Y 上・Z 手前を示す */
.axis-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 210px;
  height: 210px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.9;
}

.viewer-help {
  position: absolute;
  right: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  overflow: hidden;
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 0.7rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: center;
  margin-top: 12px;
}

.viewer-toolbar > label:first-child {
  margin: 0;
}

.viewer-toolbar select {
  min-height: 44px;
}

.check-label {
  display: inline-flex;
  min-height: 44px;
  gap: 7px;
  align-items: center;
  padding: 4px 2px;
  font-size: 0.86rem;
}

.check-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
}

.orbital-info {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.orientation-controls {
  display: flex;
  gap: 6px;
  align-items: stretch;
  justify-content: space-between;
  margin-top: 10px;
}

.orientation-controls .angle-label {
  align-self: center;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.orientation-controls .angle-select {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 4px 6px;
  font-size: 0.82rem;
}

.orientation-controls .secondary-button {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 5px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.viewer-guide {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.viewer-guide summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
}

.viewer-guide summary:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.guide-list {
  margin: 8px 0 0;
}

.guide-list > div {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.guide-list dt {
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 0.84rem;
  letter-spacing: 0;
  text-transform: none;
}

.guide-list dd {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.guide-list b {
  color: var(--ink);
}

.compare-heading {
  margin-bottom: 20px;
  padding: 4px 0;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.compare-pane {
  min-width: 0;
  padding: 20px;
}

.compare-search {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.compact-heading {
  margin-top: 18px;
}

.compact-heading h3 {
  margin-bottom: 0;
}

.compact-facts {
  margin: 12px 0 18px;
}

.compact-structure {
  min-height: 210px;
}

.compact-structure .structure-rotor {
  width: min(86%, 300px);
}

.compact-structure .structure-svg {
  min-height: 190px;
}

.compact-structure .structure-svg svg,
.compact-structure img {
  width: 100%;
  max-width: 300px;
}

.compare-viewer-frame,
.compare-viewer-frame .viewer {
  min-height: 360px;
}

.compact-toolbar {
  margin-top: 10px;
}

.reference-panel a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reference-panel a:hover,
.reference-panel a:focus-visible {
  text-decoration-thickness: 2px;
}

.reference-current {
  margin: 0 0 20px;
  padding: 12px 16px;
  border: 1px solid var(--ink);
  font-size: 0.92rem;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.reference-section {
  min-width: 0;
  padding: 20px 24px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.reference-section h3 {
  margin-bottom: 4px;
  font-size: 1.05rem;
}

.reference-facts {
  margin: 12px 0 0;
}

.reference-facts > div {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.reference-facts dt {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 0.9rem;
  letter-spacing: 0;
  text-transform: none;
}

.reference-facts dd {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.reference-facts dd:last-child {
  margin-bottom: 0;
}

.reference-facts code {
  padding: 0 3px;
  border: 1px solid var(--line);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.85em;
}

.site-footer {
  padding: 0 0 40px;
  color: var(--muted);
  font-size: 0.74rem;
}

@media (max-width: 900px) {
  .single-grid {
    grid-template-columns: 1fr;
  }

  .viewer-frame,
  .viewer {
    min-height: 420px;
  }

  .single-grid .structure-frame,
  .single-grid .viewer-frame {
    height: 420px;
  }
}

@media (max-width: 768px) {
  .site-header,
  .page-shell,
  .site-footer {
    width: min(100% - 24px, 680px);
  }

  .site-header {
    padding-top: 36px;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }

  .search-panel .status {
    grid-column: auto;
  }

  .compare-grid,
  .reference-grid {
    grid-template-columns: 1fr;
  }

  .orientation-controls {
    flex-wrap: wrap;
    gap: 3px;
  }

  .orientation-controls .angle-select {
    min-width: 64px;
  }

  .orientation-controls .secondary-button {
    padding-right: 2px;
    padding-left: 2px;
    font-size: 0.7rem;
  }
}

@media (max-width: 520px) {
  .info-card,
  .viewer-card,
  .compare-pane,
  .search-panel {
    padding: 16px;
  }

  .search-row {
    align-items: stretch;
  }

  .search-row .primary-button {
    min-width: 64px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .tab {
    flex: 1 1 0;
    padding-right: 10px;
    padding-left: 10px;
  }

  .viewer-frame,
  .viewer {
    min-height: 340px;
  }

  .single-grid .structure-frame,
  .single-grid .viewer-frame {
    height: 340px;
  }

  .compare-viewer-frame,
  .compare-viewer-frame .viewer {
    min-height: 300px;
  }
}
