:root {
  color-scheme: dark;
  --bg: #1b2026;
  --panel: #222a31;
  --line: #3a4852;
  --text: #e1e6e7;
  --muted: #a9b5bd;
  --accent: #c6b48f;
  --wood: #60c5a0;
  --fire: #df707c;
  --earth: #d1b584;
  --metal: #ebbf56;
  --water: #6fb9e2;
  --prior: #5dbdca;
  font-family:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button,
input,
textarea {
  font: inherit;
}
button,
a,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 16px;
  touch-action: manipulation;
}
button:hover {
  background: #303a43;
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  cursor: default;
  opacity: 0.5;
  transform: none;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #20252a;
  font-weight: 650;
}
button.primary:hover {
  background: #d4c4a5;
}
button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
a {
  color: var(--text);
}
:focus-visible {
  outline: 2px solid var(--water);
  outline-offset: 4px;
}
input,
textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  color: var(--text);
  background: #1c242b;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 12px;
  min-height: 50px;
  font-size: 16px;
}
input::-webkit-date-and-time-value {
  text-align: left;
}
textarea {
  resize: vertical;
  line-height: 1.8;
  min-height: 135px;
}
label {
  display: block;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1 {
  font-weight: 500;
  letter-spacing: 0.06em;
  font-size: 30px;
}
h2 {
  font-size: 20px;
  font-weight: 550;
}
h3 {
  font-size: 16px;
  font-weight: 550;
}
.muted {
  color: var(--muted);
}
.wood {
  color: var(--wood);
  fill: var(--wood);
}
.fire {
  color: var(--fire);
  fill: var(--fire);
}
.earth {
  color: var(--earth);
  fill: var(--earth);
}
.metal {
  color: var(--metal);
  fill: var(--metal);
}
.water {
  color: var(--water);
  fill: var(--water);
}
.prior {
  color: var(--prior);
  fill: var(--prior);
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.spread {
  justify-content: space-between;
}
.serif {
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
}
.small {
  font-size: 12px;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.shell {
  max-width: 1040px;
  margin: auto;
  padding: 0 24px;
}
.header {
  min-height: 86px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  letter-spacing: 0.16em;
  font-size: 20px;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: block;
  color: var(--accent);
}
.header button {
  background: transparent;
}
.header .back {
  padding: 10px 8px;
  margin-left: -8px;
  border-color: transparent;
}
.header-title {
  font-size: 17px;
}
.intro {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 42px 0 32px;
}
.intro p {
  font-size: 14px;
  color: var(--muted);
}
.start-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.7fr);
  gap: 64px;
  align-items: start;
  padding-bottom: 40px;
}
.mode-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #192128;
  margin-bottom: 30px;
}
.mode-picker button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  padding: 10px 6px;
  white-space: nowrap;
}
.mode-picker button[aria-pressed="true"] {
  background: #35414b;
  color: var(--text);
  box-shadow: 0 1px 3px #0002;
}
.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.fields {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 12px;
}
.form-block {
  margin-top: 22px;
}
.form-block:first-child {
  margin-top: 0;
}
.form-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.form-heading .field-label {
  margin: 0;
}
.form-heading button {
  font-size: 13px;
  min-height: 44px;
  padding: 8px 0;
}
.time-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}
.submit {
  width: 100%;
  margin-top: 30px;
  min-height: 52px;
  font-size: 16px;
  letter-spacing: 0.08em;
}
.error {
  margin-top: 16px;
  color: #f0a1a6;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.recent {
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.recent h2 {
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
  margin-bottom: 14px;
}
.record-link {
  display: flex;
  flex-direction: column;
  text-align: left;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: 16px 0;
  gap: 6px;
}
.record-link:hover {
  background: #222a3166;
}
.record-link .record-title {
  font-size: 16px;
  word-break: break-word;
}
.record-link .meta {
  font-size: 12px;
  color: var(--muted);
}
.record-link .preview {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.empty {
  padding: 28px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
}
.footer {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 18px 0 24px;
}
.footer button {
  font-size: 12px;
  padding: 0;
  min-height: 32px;
}
.chart-shell {
  max-width: 520px;
  margin: auto;
}
.chart-shell .header {
  min-height: 64px;
  margin-bottom: 18px;
}
.chart-main {
  padding-bottom: 110px;
}
.chart-mode {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.chart-mode .mode-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.pillars {
  padding: 0 4px 15px;
  border-bottom: 1px solid var(--line);
}
.pillar-labels,
.pillar-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  text-align: center;
  gap: 4px;
}
.pillar-labels {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.pillar-cell {
  padding: 4px 0;
  position: relative;
  min-width: 0;
}
.pillar-row + .pillar-row {
  border-top: 1px solid #ffffff0d;
  padding-top: 5px;
  margin-top: 5px;
}
.pillar-cell .stem,
.pillar-cell .zhi {
  font-size: 25px;
  line-height: 1.48;
  font-weight: 500;
  display: block;
}
.pillar-cell .relation {
  position: absolute;
  font-size: 9px;
  top: 45px;
  left: calc(50% + 15px);
  white-space: nowrap;
}
.pillar-cell .zhi.related {
  text-shadow: 0 0 6px currentColor;
}
.chain {
  font-size: 11px;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 5px 12px;
  min-height: 18px;
  color: var(--muted);
  margin-top: 8px;
}
.chart-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  padding: 3px 0;
}
.chart-status button {
  font-size: 12px;
  padding: 10px 5px;
}
.board-area {
  position: relative;
  margin: 0 -5px;
}
.disc {
  width: 100%;
  position: relative;
  aspect-ratio: 1;
  user-select: none;
  -webkit-user-select: none;
}
.board-svg,
.ring-input {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  overflow: visible;
}
.board-svg {
  pointer-events: none;
}
.ring-input {
  pointer-events: none;
}
.ring-input [data-ring] {
  pointer-events: stroke;
  touch-action: none;
  cursor: grab;
}
.ring-input [data-ring]:active {
  cursor: grabbing;
}
.ring-input [data-ring]:focus-visible {
  outline: none;
  stroke: #6fb9e24d;
}
.board-svg .ink {
  fill: var(--text);
}
.board-svg .muted {
  fill: var(--muted);
}
.board-svg .trigram {
  fill: #aab9c4;
}
.board-svg .palace {
  fill: #bac6ce;
  font-weight: 500;
}
.board-svg .yun {
  fill: var(--text);
  font-weight: 700;
}
.glow {
  filter: drop-shadow(0 0 3px currentColor);
}
.branch {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  width: 44px;
  height: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: transparent !important;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
}
.branch:active {
  transform: translate(-50%, -50%);
}
.branch.selected > span {
  text-shadow:
    0 0 3px currentColor,
    0 0 8px currentColor;
}
.branch small {
  font-size: 9px;
  color: var(--water);
  position: absolute;
  left: calc(50% + 11px);
}
.branch.ming:before {
  content: "";
  position: absolute;
  width: 33px;
  height: 26px;
  border: 1px solid #6fb9e2aa;
  background: #6fb9e21e;
  border-radius: 5px;
  left: calc(50% - 14px);
}
.branch em {
  font-size: 9px;
  color: #fff;
  position: absolute;
  top: 37px;
  left: 50%;
  transform: translateX(-50%);
  font-style: normal;
  white-space: nowrap;
  text-shadow: 0 0 5px #fff9;
}
.branch span {
  position: relative;
}
.ring-tools {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 8px 0 14px;
}
.ring-tools button {
  font-size: 13px;
  padding: 8px 12px;
  background: transparent;
}
.ring-tools .step {
  width: 44px;
  padding: 8px;
  font-size: 18px;
}
.ring-tools .hint {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.calendar {
  font-size: 11px;
  line-height: 1.9;
  color: var(--muted);
  padding: 0 4px 18px;
  overflow-wrap: anywhere;
}
.details {
  border-top: 1px solid var(--line);
  padding: 15px 4px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
}
.details strong {
  font-size: 20px;
  font-weight: 500;
}
.editor {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.editor input,
.editor textarea {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 4px 0;
  min-height: 40px;
}
.editor textarea {
  min-height: 105px;
}
.editor label + label {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 12px;
}
.editor .field-label {
  font-size: 11px;
  margin-bottom: 5px;
}
.save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: #1b2026f2;
  border-top: 1px solid var(--line);
  z-index: 5;
  backdrop-filter: blur(12px);
}
.save-bar > div {
  max-width: 472px;
  margin: auto;
}
.save-bar button {
  width: 100%;
  min-height: 48px;
}
.library-main {
  max-width: 680px;
  margin: 32px auto 60px;
}
.library-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 24px;
}
.library-tools button {
  font-size: 13px;
}
.search {
  margin: 24px 0 8px;
}
.library-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 16px;
  line-height: 1.8;
}
.privacy-note {
  font-size: 12px;
  color: var(--muted);
  padding: 10px 0 0;
}
.page-tag {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
#toast {
  position: fixed;
  bottom: calc(94px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #e1e6e7;
  color: #1b2026;
  border-radius: 9px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 4px 25px #0003;
  z-index: 20;
  max-width: calc(100vw - 32px);
  width: max-content;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
#toast.show {
  opacity: 1;
}
dialog {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 360px;
  width: calc(100vw - 40px);
  padding: 25px;
}
dialog::backdrop {
  background: #0009;
}
dialog p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
  margin: 12px 0 22px;
}
.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.skip {
  position: fixed;
  top: -100px;
  z-index: 30;
}
.skip:focus {
  top: 8px;
  left: 8px;
  background: var(--panel);
  padding: 10px;
}
#main {
  scroll-margin-top: 20px;
}
.update {
  font-size: 12px;
  color: var(--muted);
  padding: 10px 0;
}
.update button {
  font-size: 12px;
  margin-left: 10px;
}
.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;
}
@media (min-width: 700px) {
  .start-layout {
    min-height: 480px;
  }
  .chart-shell {
    padding: 0;
  }
  .chart-shell .header {
    margin-top: 12px;
  }
  .chart-main {
    padding-left: 16px;
    padding-right: 16px;
  }
  .brand {
    font-size: 22px;
  }
  .intro h1 {
    font-size: 36px;
  }
  .recent {
    margin-top: 0;
  }
}
@media (max-width: 699px) {
  .shell {
    padding: 0 20px;
  }
  .header {
    min-height: 76px;
  }
  .start-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 34px;
  }
  .intro {
    margin: 32px 0 26px;
  }
  .mode-picker {
    margin-bottom: 22px;
  }
  .recent {
    margin-top: 0;
  }
  .chart-shell {
    padding: 0 16px;
  }
  .chart-shell .header {
    margin-bottom: 12px;
  }
  .chart-main {
    padding-bottom: 100px;
  }
  .footer {
    flex-wrap: wrap;
  }
  .footer button {
    min-height: 44px;
  }
  .chart-status {
    font-size: 10px;
  }
  .chart-status span {
    max-width: 78%;
    line-height: 1.7;
  }
  .board-area {
    margin: 0 -6px;
  }
  .ring-tools {
    gap: 6px;
  }
  .ring-tools button {
    padding: 8px;
    font-size: 12px;
  }
  .ring-tools .hint {
    font-size: 10px;
  }
  .pillars {
    padding-bottom: 10px;
  }
  .pillar-cell .stem,
  .pillar-cell .zhi {
    font-size: 23px;
  }
  .editor {
    padding: 15px;
  }
  .intro .page-tag {
    margin-bottom: 4px;
  }
}
@media (max-width: 350px) {
  .shell {
    padding: 0 16px;
  }
  .chart-shell {
    padding: 0 10px;
  }
  .brand {
    font-size: 18px;
    gap: 9px;
  }
  .brand-mark {
    width: 28px;
  }
  .branch {
    font-size: 19px;
  }
  .branch em {
    font-size: 8px;
    top: 34px;
  }
  .chart-status {
    font-size: 9px;
  }
  .ring-tools {
    gap: 2px;
  }
  .ring-tools .hint {
    font-size: 9px;
  }
  .ring-tools button {
    padding: 8px 5px;
  }
  .pillar-cell .relation {
    font-size: 8px;
    left: calc(50% + 12px);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *:before,
  *:after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
/* Chromium determines touch gestures on the SVG viewport, not its circle. */
.ring-input {
  touch-action: none;
}
[hidden] {
  display: none !important;
}
