:root {
  --paper: #f5efe2;
  --paper-deep: #ece1c8;
  --ink: #1f221d;
  --muted: #615b4f;
  --line: rgba(59, 49, 29, 0.14);
  --accent: #8d3a2d;
  --accent-soft: rgba(141, 58, 45, 0.12);
  --jade: #2b5d50;
  --jade-soft: rgba(43, 93, 80, 0.12);
  --gold: #a27a28;
  --shadow: 0 18px 48px rgba(51, 36, 14, 0.12);
  --radius: 22px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(162, 122, 40, 0.16), transparent 32%),
    radial-gradient(circle at top right, rgba(43, 93, 80, 0.14), transparent 34%),
    linear-gradient(180deg, #f9f4ea 0%, #efe6d2 46%, #f7f1e5 100%);
  font-family: "Iowan Old Style", "Baskerville", "Songti SC", "STSong", "Noto Serif SC", serif;
  line-height: 1.65;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(90, 74, 40, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(90, 74, 40, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 95%);
}

button,
select,
summary {
  font: inherit;
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
  isolation: isolate;
}

.hero,
.context-shell,
.panel,
.results-shell,
.meta-card,
.plate-board,
.empty-state,
.atlas-card {
  position: relative;
  overflow: hidden;
  background: rgba(255, 252, 245, 0.82);
  border: 1px solid rgba(99, 78, 36, 0.16);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.hero::after,
.context-shell::after,
.panel::after,
.results-shell::after {
  content: "";
  position: absolute;
  inset: auto auto 0 0;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(141, 58, 45, 0.08), transparent 70%);
  transform: translate(-20%, 35%);
  pointer-events: none;
}

.hero {
  padding: 28px 28px 24px;
  margin-bottom: 20px;
  animation: rise 520ms ease-out both;
}

.hero-top,
.panel-head,
.results-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow,
.panel-kicker {
  margin: 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.74rem;
  color: var(--accent);
}

.hero h1,
.panel h2,
.results-head h2,
.context-head h2 {
  margin: 8px 0 0;
  font-weight: 600;
  line-height: 1.1;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.6rem);
}

.results-meta,
.empty-state p,
.atlas-meta p {
  margin: 0;
  color: var(--muted);
}

.context-shell,
.results-shell,
.panel {
  padding: 22px;
}

.context-shell {
  margin-bottom: 18px;
  animation: rise 560ms ease-out both;
}

.context-grid,
.select-grid {
  display: grid;
  gap: 16px;
}

.context-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.workspace-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
}

.panel {
  animation: rise 620ms ease-out both;
}

.builder {
  margin-top: 18px;
}

.builder-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(220px, 0.85fr);
  gap: 16px;
  align-items: stretch;
}

.builder-controls,
.builder-preview {
  min-width: 0;
}

.select-grid {
  grid-template-columns: 1fr;
  gap: 12px;
}

.select-field label {
  display: none;
}

.select-field {
  display: grid;
  gap: 8px;
}

.select-field select,
.icon-button,
.atlas-actions button,
.pill,
.line-chip,
.empty-state button,
.summary-badge {
  border-radius: 999px;
}

.select-field select,
.icon-button,
.atlas-actions button,
.results-actions button,
.empty-state button {
  border: 1px solid rgba(97, 72, 29, 0.16);
  background: rgba(255, 251, 244, 0.92);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.select-field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(91, 72, 31, 0.16);
  background: rgba(255, 253, 249, 0.96);
  color: var(--ink);
  outline: none;
}

.select-field select:focus {
  border-color: rgba(141, 58, 45, 0.42);
  box-shadow: 0 0 0 4px rgba(141, 58, 45, 0.08);
}

.icon-button,
.atlas-actions button,
.results-actions button,
.empty-state button {
  padding: 9px 14px;
}

.icon-button:hover,
.atlas-actions button:hover,
.results-actions button:hover,
.empty-state button:hover,
.select-field select:hover {
  transform: translateY(-1px);
  border-color: rgba(141, 58, 45, 0.38);
  background: #fffdf7;
}

.icon-button {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-button::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(97, 72, 29, 0.14);
  background: rgba(255, 252, 245, 0.98);
  box-shadow: 0 10px 24px rgba(51, 36, 14, 0.12);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.icon-button:hover::after,
.icon-button:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.swap-bridge {
  width: 54px;
  height: 54px;
  align-self: center;
  justify-self: center;
  box-shadow: 0 12px 28px rgba(51, 36, 14, 0.1);
}

.swap-bridge svg {
  width: 22px;
  height: 22px;
}

.swap-bridge::after {
  left: 50%;
  right: auto;
  transform: translate(-50%, -4px);
}

.swap-bridge:hover::after,
.swap-bridge:focus-visible::after {
  transform: translate(-50%, 0);
}

.builder-preview {
  min-width: 0;
}

.hex-card {
  display: grid;
  place-items: center;
  gap: 14px;
  min-height: 100%;
  height: 100%;
  min-height: 188px;
  padding: 20px 18px;
  border-radius: calc(var(--radius) - 6px);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.96), rgba(246, 239, 225, 0.88));
}

.hex-card.empty {
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.54), rgba(246, 239, 225, 0.4));
}

.hex-lines {
  display: grid;
  gap: 8px;
  align-content: center;
  min-width: 94px;
}

.hex-lines.placeholder {
  opacity: 0.16;
}

.yao {
  position: relative;
  width: 92px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #342517, #624124);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.yao.broken {
  background: none;
}

.yao.broken::before,
.yao.broken::after {
  content: "";
  position: absolute;
  top: 0;
  width: 36px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #342517, #624124);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.yao.broken::before {
  left: 0;
}

.yao.broken::after {
  right: 0;
}

.yao.faint {
  opacity: 0.16;
}

.hex-meta h3,
.summary-body h3,
.atlas-meta h3,
.empty-state h3 {
  margin: 0;
  font-size: 2rem;
}

.hex-meta p,
.summary-body p,
.empty-state p,
.atlas-meta p {
  margin-top: 4px;
}

.results-shell {
  z-index: 1;
  margin-top: 18px;
  animation: rise 680ms ease-out both;
  padding: 22px;
}

.results-actions {
  display: flex;
  align-items: flex-start;
}

.results-meta:empty {
  display: none;
}

.results-actions button[hidden] {
  display: none;
}

.results-actions button.is-copied {
  color: var(--jade);
  border-color: rgba(43, 93, 80, 0.22);
  background: rgba(43, 93, 80, 0.08);
}

.results {
  margin-top: 18px;
}

.empty-state {
  padding: 26px;
}

.empty-state h3 {
  margin-bottom: 8px;
}

.atlas-grid,
.results.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.atlas-card {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 251, 245, 0.92);
  animation: rise 380ms ease-out both;
}

.atlas-top {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
}

.atlas-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.plate-shell {
  display: grid;
  gap: 18px;
}

.plate-board {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 251, 245, 0.92);
  animation: rise 380ms ease-out both;
}

.plate-header {
  display: grid;
  grid-template-columns: 108px 120px minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.94rem;
  color: var(--muted);
}

.plate-table {
  display: grid;
}

.plate-row {
  display: grid;
  grid-template-columns: 108px 120px minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(59, 49, 29, 0.08);
}

.plate-row:last-child {
  border-bottom: 0;
}

.plate-cell {
  min-width: 0;
}

.aux-cell {
  display: grid;
  gap: 4px;
}

.aux-cell .line-order {
  font-size: 0.86rem;
  color: var(--muted);
}

.aux-cell strong {
  font-size: 1rem;
}

.hidden-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(162, 122, 40, 0.18);
  background: rgba(162, 122, 40, 0.08);
  color: var(--muted);
  font-size: 0.92rem;
}

.hidden-pill.empty,
.line-panel.empty {
  border-style: dashed;
  color: rgba(97, 91, 79, 0.72);
  background: rgba(255, 251, 244, 0.46);
}

.line-panel {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(97, 72, 29, 0.12);
  background: rgba(255, 251, 244, 0.82);
}

.line-panel.moving {
  border-color: rgba(141, 58, 45, 0.22);
  background: rgba(141, 58, 45, 0.06);
}

.line-panel-head,
.line-panel-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.line-panel-head {
  align-items: flex-start;
}

.line-role {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(43, 93, 80, 0.12);
  color: var(--jade);
  font-size: 0.88rem;
}

.line-role.empty {
  background: transparent;
  color: transparent;
}

.line-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid rgba(97, 72, 29, 0.14);
  background: rgba(255, 249, 238, 0.9);
  color: var(--muted);
  font-size: 0.9rem;
}

.line-chip.accent {
  color: var(--accent);
  border-color: rgba(141, 58, 45, 0.18);
}

.line-chip.gold {
  color: #7b5d1c;
  border-color: rgba(162, 122, 40, 0.18);
}

.line-visual {
  display: flex;
  align-items: center;
  gap: 10px;
}

.line-glyph {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.line-glyph .yao {
  width: 84px;
  height: 10px;
}

.move-marker {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  min-height: 24px;
  border-radius: 999px;
  background: rgba(141, 58, 45, 0.12);
  color: var(--accent);
  font-size: 0.92rem;
}

.plate-placeholder {
  display: grid;
  place-items: center;
  min-height: 82px;
  color: rgba(97, 91, 79, 0.72);
  border: 1px dashed rgba(97, 72, 29, 0.16);
  border-radius: 18px;
  background: rgba(255, 251, 244, 0.42);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1024px) {
  .workspace-shell,
  .results.grid,
  .atlas-grid {
    grid-template-columns: 1fr;
  }

  .swap-bridge {
    margin: -2px auto;
  }

  .panel-head,
  .results-head {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-top {
    align-items: stretch;
  }

  .plate-header,
  .plate-row {
    grid-template-columns: 92px 104px minmax(0, 1fr) minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .page {
    width: min(100vw - 20px, 100%);
    padding-top: 16px;
  }

  .hero,
  .context-shell,
  .panel,
  .results-shell {
    border-radius: 18px;
    padding: 18px;
  }

  .context-grid,
  .select-grid,
  .hex-card,
  .atlas-top {
    grid-template-columns: 1fr;
  }

  .builder-shell {
    grid-template-columns: 1fr;
  }

  .atlas-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .atlas-actions button {
    width: 100%;
  }

  .hex-lines {
    min-width: auto;
  }

  .plate-header {
    display: none;
  }

  .plate-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px 0 18px;
  }

  .aux-cell {
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: space-between;
  }

  .hidden-pill {
    width: 100%;
    justify-content: center;
  }
}
