.ref-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.ref-panel,
.ref-card,
.ref-item {
  min-width: 0;
}
.ref-card {
  padding: 22px;
  background: var(--surface, #111b2a);
  border: 1px solid var(--line, #293448);
  border-radius: 12px;
}
.ref-card h2 {
  font-size: 18px;
  margin-top: 0;
}
.ref-card textarea {
  resize: vertical;
  min-height: 90px;
}
.ref-actions,
.ref-result-head,
.ref-pagination,
.ref-item-head {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.ref-result-head {
  justify-content: space-between;
}
.ref-actions button {
  min-height: 44px;
}
.ref-note {
  font-size: 13px;
  line-height: 1.8;
  color: var(--muted, #a0adbe);
  overflow-wrap: anywhere;
}
.ref-result-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 14px;
}
.ref-item {
  padding: 18px;
  background: var(--bg, #0b111b);
  border: 1px solid var(--line, #293448);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.ref-item h3 {
  font-size: 16px;
  margin: 0;
  min-width: 0;
}
.ref-data {
  display: grid;
  grid-template-columns: minmax(70px, auto) minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
  line-height: 1.6;
}
.ref-data dt {
  color: var(--muted, #a0adbe);
}
.ref-data dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}
.ref-flag {
  width: 64px;
  height: 48px;
  object-fit: contain;
  border: 1px solid #344053;
  background: #fff;
}
.ref-swatch {
  display: block;
  flex: none;
  width: 48px;
  height: 48px;
  border: 1px solid #8892a0;
  border-radius: 6px;
}
.ref-pagination {
  margin-top: 20px;
  justify-content: center;
}
.ref-lines-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}
.ref-lines-controls button {
  min-height: 44px;
}
.ref-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.ref-check input {
  width: auto;
  min-height: 24px;
}
.ref-hexagram {
  width: 110px;
  display: grid;
  gap: 7px;
  margin: 16px 0;
}
.ref-hexagram > div {
  height: 9px;
  display: flex;
  gap: 14px;
}
.ref-hexagram span {
  flex: 1;
  background: var(--accent, #f5b526);
}
.ref-tarot-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 56px;
  border: 1px solid var(--accent, #f5b526);
  color: var(--accent, #f5b526);
  border-radius: 5px;
}
.ref-lines-input summary {
  cursor: pointer;
  min-height: 44px;
  padding: 12px 0;
}
.ref-card input[type='file'] {
  max-width: 100%;
  font-size: 13px;
}
.ref-pagination span {
  font-size: 13px;
}
.ref-item button {
  width: 100%;
  min-height: 44px;
}
.ref-item-head h3 {
  flex: 1;
}
@media (min-width: 1400px) {
  .ref-layout {
    grid-template-columns: 350px minmax(0, 1fr);
  }
}
@media (max-width: 900px) {
  .ref-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .ref-card {
    padding: 16px;
  }
  .ref-result-head {
    align-items: flex-start;
  }
  .ref-result-head .ref-actions {
    width: 100%;
  }
  .ref-data {
    grid-template-columns: minmax(65px, 100px) minmax(0, 1fr);
  }
  .ref-actions {
    gap: 8px;
  }
  .ref-actions button {
    flex: 1;
  }
  .ref-item {
    padding: 14px;
  }
}
/* Native visual browsing: compact desktop detail column, stacked touch layout. */
.ref-browser {
  margin-bottom: 22px;
}
.ref-visual-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}
.ref-visual-head h2 {
  margin: 0;
}
.ref-visual-head button {
  min-height: 44px;
}
.ref-visual-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: 24px;
  align-items: start;
}
.ref-visual-body[hidden] {
  display: none;
}
.ref-visual-stage,
.ref-visual-detail {
  min-width: 0;
}
.ref-visual-stage h3,
.ref-visual-detail h3 {
  font-size: 16px;
  margin: 0 0 12px;
}
.ref-visual-stage > select {
  width: 100%;
  margin-bottom: 12px;
}
.ref-visual-detail {
  padding: 18px;
  background: var(--bg, #0b111b);
  border: 1px solid var(--line, #293448);
  border-radius: 8px;
  overflow-wrap: anywhere;
  position: sticky;
  top: 88px;
}
.ref-visual-detail > button {
  width: 100%;
  margin-top: 12px;
  min-height: 44px;
}
.ref-visual-detail > .ref-flag,
.ref-visual-detail > .ref-swatch {
  margin-bottom: 14px;
}
.ref-visual-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.ref-visual-toolbar > button {
  min-height: 44px;
  flex-shrink: 0;
}
.ref-visual-toolbar > select,
.ref-visual-toolbar > input:not([type='color']) {
  flex: 1 1 180px;
  width: 0;
  min-width: min(180px, 100%);
  max-width: 100%;
}
.ref-visual-toolbar > span {
  font-size: 13px;
  color: var(--muted, #a0adbe);
}
.ref-visual-directory {
  margin-top: 18px;
}
.ref-visual-directory > summary {
  cursor: pointer;
  min-height: 44px;
  padding: 12px 0;
  font-size: 14px;
}
.ref-map-host {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line, #293448);
  border-radius: 9px;
  background: #0b1824;
}
.ref-map-host > .ref-visual-toolbar {
  padding: 0 10px;
}
.ref-world {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2/1;
  user-select: none;
}
.ref-country {
  fill: #233e50;
  stroke: #7091a7;
  stroke-width: 0.6;
  cursor: pointer;
  outline: none;
}
.ref-country:hover,
.ref-country:focus {
  fill: #49676d;
  stroke: var(--accent, #f5b526);
  stroke-width: 1.8;
}
.ref-country.is-selected {
  fill: #bc8926;
  stroke: #ffd47b;
  stroke-width: 1.6;
}
.ref-map-unlisted {
  fill: #25303d;
  cursor: default;
}
.ref-graticule path {
  stroke: #8097a322;
  stroke-width: 0.8;
  fill: none;
}
.ref-map-label {
  margin: 8px 12px 12px !important;
  min-height: 24px;
}
.ref-map-point {
  cursor: pointer;
  outline: none;
}
.ref-map-point circle:not(.ref-point-hit) {
  fill: #ffcd67;
  stroke: #102033;
  stroke-width: 1.5;
}
.ref-map-point:hover circle:not(.ref-point-hit),
.ref-map-point:focus circle:not(.ref-point-hit) {
  fill: #50dfec;
  stroke: #fff;
}
.ref-point-hit {
  fill: transparent;
  stroke: none;
}
.ref-result-focus {
  border-color: var(--accent, #f5b526);
  box-shadow: 0 0 0 2px #f5b52644;
}
.ref-flag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.ref-flag-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  min-height: 120px;
  border: 1px solid var(--line, #293448);
  border-radius: 7px;
  background: var(--bg, #0b111b);
  font-size: 13px;
  text-align: center;
  overflow-wrap: anywhere;
}
.ref-flag-choice img,
.ref-no-flag {
  width: 56px;
  height: 42px;
  object-fit: contain;
}
.ref-flag-choice small {
  color: var(--muted, #a0adbe);
}
.ref-bagua {
  display: block;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  overflow: visible;
}
.ref-bagua-sector {
  cursor: pointer;
  outline: none;
}
.ref-bagua-sector > path:first-child {
  fill: #142333;
  stroke: #477080;
  stroke-width: 1.2;
}
.ref-bagua-sector:hover > path:first-child,
.ref-bagua-sector:focus > path:first-child,
.ref-bagua-sector[aria-pressed='true'] > path:first-child {
  fill: #3c351f;
  stroke: #ffd47b;
  stroke-width: 3;
}
.ref-bagua-line {
  stroke: var(--accent, #f5b526);
  stroke-width: 5;
  fill: none;
  pointer-events: none;
}
.ref-bagua-sector text {
  fill: var(--text, #e4e8ef);
  font-size: 19px;
  font-family: var(--font-sans);
  pointer-events: none;
}
.ref-bagua-direction {
  fill: var(--muted, #a0adbe);
  font-size: 14px;
  pointer-events: none;
}
.ref-taiji-base {
  fill: #e7ae36;
  stroke: #e7ae36;
  stroke-width: 2;
}
.ref-taiji-half,
.ref-taiji-dot-dark {
  fill: #101e2d;
}
.ref-taiji-dot-light {
  fill: #e7ae36;
}
.ref-mini-lines {
  display: grid;
  width: 54px;
  gap: 4px;
  margin: 10px 0;
}
.ref-mini-lines > span {
  height: 5px;
  display: flex;
  gap: 7px;
}
.ref-mini-lines i {
  background: var(--accent, #f5b526);
  flex: 1;
}
.ref-hexagram-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
.ref-hexagram-choice {
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 13px;
  background: var(--bg, #0b111b);
  border: 1px solid var(--line, #293448);
  border-radius: 6px;
  min-height: 100px;
}
.ref-character-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}
.ref-character-choice {
  padding: 6px 2px;
  display: flex;
  align-items: center;
  flex-direction: column;
  background: var(--bg, #0b111b);
  border: 1px solid var(--line, #293448);
  border-radius: 5px;
  min-height: 60px;
}
.ref-character-choice > span {
  font-family: system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.4;
}
.ref-character-choice small {
  font-size: 10px;
  letter-spacing: 0;
  color: var(--muted, #a0adbe);
}
.ref-geologic-bands {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  gap: 12px;
}
.ref-geologic-band {
  border: 1px solid var(--era-color);
  border-top: 10px solid var(--era-color);
  background: var(--bg, #0b111b);
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  padding: 16px;
  min-height: 135px;
  overflow-wrap: anywhere;
}
.ref-geologic-band span,
.ref-geologic-band small {
  font-size: 12px;
  color: var(--muted, #a0adbe);
}
.ref-browser .is-selected,
.ref-browser button[aria-pressed='true'] {
  border-color: var(--accent, #f5b526);
  box-shadow: inset 0 0 0 1px var(--accent, #f5b526);
}
.ref-browser button:focus-visible {
  outline: 2px solid #76d9e8;
  outline-offset: 3px;
}
.ref-browser button:hover {
  border-color: #d5b55b;
}
@media (max-width: 1100px) {
  .ref-visual-body {
    grid-template-columns: minmax(0, 1fr) minmax(200px, 260px);
  }
}
@media (max-width: 800px) {
  .ref-visual-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }
  .ref-visual-detail {
    position: static;
    padding: 14px;
  }
  .ref-visual-head {
    align-items: flex-start;
  }
  .ref-visual-head button {
    font-size: 12px;
    padding: 8px 10px;
  }
  .ref-visual-toolbar > select,
  .ref-visual-toolbar > input:not([type='color']) {
    width: 100%;
    flex-basis: 100%;
  }
  .ref-world {
    aspect-ratio: 2/1;
  }
  .ref-character-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .ref-flag-grid {
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  }
  .ref-flag-choice {
    padding: 10px 6px;
  }
  .ref-geologic-band {
    padding: 12px;
  }
  .ref-map-host > .ref-visual-toolbar {
    gap: 6px;
  }
  .ref-map-host > .ref-visual-toolbar > button {
    padding: 8px 12px;
  }
}
@media (max-width: 360px) {
  .ref-character-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .ref-visual-toolbar {
    gap: 6px;
  }
}

.ref-bagua-sector text {
  font-size: 24px;
}
.ref-bagua-direction {
  font-size: 16px;
}
.ref-visual-collapsed > .ref-visual-directory {
  display: none;
}
.ref-visual-detail,
.ref-results {
  scroll-margin-top: 88px;
}
.ref-browser {
  scroll-margin-top: 88px;
}

/* A continuous local HSV wheel and a small, illustrated deck instead of grids. */
.ref-visual-stage {
  container-type: inline-size;
  container-name: reference-stage;
}
.ref-color-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}
.ref-color-wheel {
  position: relative;
  aspect-ratio: 1;
  width: min(100%, 360px);
  margin: auto;
  touch-action: none;
  border-radius: 50%;
  cursor: crosshair;
  user-select: none;
}
.ref-color-wheel canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
}
.ref-color-wheel:focus-visible {
  outline: 3px solid #76d9e8;
  outline-offset: 6px;
}
.ref-color-marker {
  position: absolute;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #101826;
  pointer-events: none;
}
.ref-color-controls {
  min-width: 0;
}
.ref-color-preview {
  height: 64px;
  border: 1px solid #a0adbe66;
  border-radius: 8px;
}
.ref-color-values {
  font-size: 13px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
}
.ref-color-slider {
  display: block;
  margin: 10px 0;
}
.ref-color-slider-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted, #a0adbe);
}
.ref-color-slider output {
  font-family: var(--font-mono);
  color: var(--text, #e4e8ef);
}
.ref-color-slider input[type='range'] {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0;
  accent-color: var(--accent, #f5b526);
  cursor: pointer;
  touch-action: pan-y;
}
.ref-color-hex-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}
.ref-color-hex-row label {
  font-size: 13px;
  color: var(--muted, #a0adbe);
}
.ref-color-hex-row input {
  min-width: 0;
  width: 100%;
  font-family: var(--font-mono);
}
.ref-color-hex-row button {
  min-height: 44px;
}
.ref-color-controls #colors-hex-error:empty {
  display: none;
}
.ref-tarot-selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.ref-tarot-selectors label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  color: var(--muted, #a0adbe);
}
.ref-tarot-selectors select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
}
.ref-tarot-selectors .ref-tarot-version {
  grid-column: 1/-1;
}
.ref-tarot-fan {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 350px;
  border: 1px solid var(--line, #293448);
  border-radius: 12px;
  background: radial-gradient(ellipse at 50% 40%, #273a43, #0d1724 70%);
  touch-action: pan-y;
  user-select: none;
  --spread: 58px;
}
.ref-tarot-fan:focus-visible {
  outline: 2px solid #76d9e8;
  outline-offset: 3px;
}
.ref-tarot-fan .ref-tarot-card {
  position: absolute;
  top: calc(20px + var(--distance) * 16px);
  left: 50%;
  width: 180px;
  padding: 0;
  min-height: 0;
  border: 2px solid #827043;
  background: #e9dfbc;
  border-radius: 7px;
  overflow: hidden;
  transform: translateX(calc(-50% + var(--offset) * var(--spread)))
    rotate(calc(var(--offset) * 8deg)) scale(calc(1 - var(--distance) * 0.12));
  transform-origin: center 85%;
  box-shadow: 0 10px 22px #0009;
  cursor: pointer;
}
.ref-tarot-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--tarot-ratio, 3/5);
  object-fit: contain;
  pointer-events: none;
}
.ref-tarot-card img[hidden] {
  display: none;
}
.ref-tarot-card:not(.is-selected) {
  filter: brightness(0.7);
}
.ref-tarot-card:not(.is-selected):hover,
.ref-tarot-card:focus-visible {
  filter: brightness(1);
}
.ref-tarot-fan .ref-tarot-card.is-selected {
  border-color: var(--accent, #f5b526);
  box-shadow:
    0 0 0 1px #f5b526,
    0 10px 24px #0009;
}
.ref-tarot-image-error {
  display: grid;
  place-items: center;
  padding: 12px;
  aspect-ratio: var(--tarot-ratio, 3/5);
  font-size: 13px;
  background: #172536;
  color: #e4e8ef;
}
.ref-tarot-caption {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 18px 4px 10px;
  overflow-wrap: anywhere;
}
.ref-tarot-caption strong {
  font-size: 18px;
}
.ref-tarot-caption span {
  font-size: 12px;
  color: var(--muted, #a0adbe);
}
.ref-tarot-navigation {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.ref-tarot-navigation button {
  min-height: 44px;
}
.ref-tarot-navigation > span {
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--muted, #a0adbe);
}
.ref-tarot-thumbnail {
  width: 48px;
  height: 80px;
  object-fit: contain;
  border: 1px solid #827043;
  border-radius: 4px;
  flex: none;
}
@container reference-stage (max-width:460px) {
  .ref-color-picker {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }
  .ref-color-wheel {
    width: min(100%, 280px);
  }
  .ref-tarot-fan {
    --spread: 42px;
    min-height: 310px;
  }
  .ref-tarot-fan .ref-tarot-card {
    width: 156px;
  }
}
@container reference-stage (max-width:300px) {
  .ref-tarot-selectors {
    grid-template-columns: minmax(0, 1fr);
  }
  .ref-tarot-fan {
    --spread: 36px;
    min-height: 270px;
  }
  .ref-tarot-fan .ref-tarot-card {
    width: 132px;
  }
}
