:root {
  color-scheme: light;
  --ink: #172b27;
  --ink-soft: #4d5f5b;
  --jade: #17655b;
  --jade-dark: #123f39;
  --jade-pale: #e3eeea;
  --cinnabar: #bd3f32;
  --cinnabar-pale: #f8e9e5;
  --gold: #c4933c;
  --paper: #ffffff;
  --ground: #eef2ef;
  --line: #ccd6d1;
  --line-strong: #9caea7;
  --warning: #8f3028;
  --shadow: 0 18px 44px rgba(25, 52, 46, 0.1);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--ground);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0;
}

body.telegram-mini-app {
  min-height: var(--tg-viewport-stable-height, 100vh);
  padding-bottom: max(env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px));
  background: var(--tg-theme-secondary-bg-color, var(--ground));
}

.telegram-mini-app .api-link {
  display: none;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

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

button {
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke-width: 1.8;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  color: #fff;
  background: var(--jade-dark);
  border-radius: 4px;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 68px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1240px, calc(100% - 40px));
  height: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  background: var(--cinnabar);
  border: 1px solid #9c2f27;
  border-radius: 4px;
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 25px;
  line-height: 1;
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.25;
}

.brand-copy strong {
  overflow: hidden;
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 20px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 11px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-link,
.text-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 10px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}

.icon-link:hover,
.text-tool:hover {
  color: var(--jade);
  background: var(--jade-pale);
  border-color: #c6dad4;
}

.icon-link:focus-visible,
.text-tool:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(23, 101, 91, 0.22);
  outline-offset: 2px;
}

main {
  min-height: calc(100vh - 68px);
}

.workspace {
  display: grid;
  width: min(1240px, calc(100% - 40px));
  min-height: 724px;
  margin: 24px auto 36px;
  overflow: hidden;
  grid-template-columns: 430px minmax(0, 1fr);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.intake-pane {
  padding: 32px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.pane-heading,
.result-header,
.recent-heading,
.field-label-row,
.card-toolbar,
.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.pane-heading {
  align-items: flex-start;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cinnabar);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 34px;
  line-height: 1.2;
}

h2 {
  font-size: 24px;
  line-height: 1.35;
}

h3 {
  font-size: 15px;
}

.method-badge {
  padding: 5px 8px;
  color: var(--jade-dark);
  background: var(--jade-pale);
  border: 1px solid #bcd4cc;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
}

#divination-form {
  display: grid;
  gap: 24px;
  scroll-margin-top: 80px;
}

.field-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-group > label,
.field-label-row > label,
.field-label-row > span,
.field-group legend {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.field-group legend {
  margin-bottom: 10px;
}

.field-label-row {
  min-height: 36px;
  margin-bottom: 8px;
}

#question-count {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}

#question-count.near-limit {
  color: var(--warning);
}

.category-grid {
  display: grid;
  overflow: hidden;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.category-grid label {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.category-grid input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.category-grid span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 0 4px;
  color: var(--ink-soft);
  background: #fff;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}

.category-grid label:nth-child(4n) span {
  border-right: 0;
}

.category-grid label:nth-child(n + 5) span {
  border-bottom: 0;
}

.category-grid input:checked + span {
  color: #fff;
  background: var(--jade);
}

.category-grid input:focus-visible + span {
  position: relative;
  z-index: 1;
  outline: 3px solid rgba(23, 101, 91, 0.24);
  outline-offset: -3px;
}

textarea {
  display: block;
  width: 100%;
  min-height: 116px;
  resize: vertical;
  padding: 12px 14px;
  color: var(--ink);
  background: #fbfcfb;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  line-height: 1.6;
}

textarea::placeholder {
  color: #81908c;
}

textarea:focus {
  background: #fff;
  border-color: var(--jade);
}

.number-field .text-tool {
  margin-right: -10px;
}

.digit-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
}

.digit-input {
  width: 78px;
  height: 88px;
  padding: 0;
  color: var(--jade-dark);
  background: #f7faf8;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.digit-input:focus {
  background: #fff;
  border-color: var(--jade);
}

.digit-divider {
  width: 24px;
  height: 2px;
  background: var(--gold);
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  color: var(--ink-soft);
  background: #f3f7f5;
  border-left: 3px solid var(--jade);
  font-size: 12px;
  line-height: 1.55;
}

.privacy-note svg {
  width: 15px;
  height: 15px;
  margin-top: 2px;
}

.form-alert {
  padding: 10px 12px;
  color: var(--warning);
  background: var(--cinnabar-pale);
  border: 1px solid #e7bdb7;
  border-radius: 5px;
  font-size: 13px;
}

.primary-button,
.secondary-button,
.telegram-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 50px;
  padding: 0 18px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  color: #fff;
  background: var(--jade-dark);
  border: 1px solid var(--jade-dark);
}

.primary-button:hover {
  background: var(--jade);
  border-color: var(--jade);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button-arrow {
  margin-left: auto;
}

.result-pane {
  position: relative;
  min-width: 0;
  padding: 32px;
  background: #f2f5f2;
  scroll-margin-top: 80px;
}

.empty-state {
  display: grid;
  height: 100%;
  min-height: 658px;
  align-items: center;
  grid-template-columns: minmax(230px, 1fr) 286px;
  gap: 36px;
}

.empty-copy {
  align-self: center;
}

.empty-copy h2 {
  max-width: 340px;
  margin-bottom: 12px;
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 34px;
}

.empty-copy p:last-child {
  max-width: 360px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.sample-card-frame {
  width: 286px;
  margin: 0;
  padding: 9px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: 0 12px 30px rgba(25, 52, 46, 0.13);
}

.sample-card-frame img {
  width: 100%;
  height: 548px;
  object-fit: contain;
  border-radius: 3px;
}

.sample-card-frame figcaption {
  padding: 8px 4px 1px;
  color: var(--ink-soft);
  font-size: 11px;
  text-align: center;
}

.loading-state {
  display: grid;
  min-height: 658px;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.loading-seal {
  display: grid;
  width: 72px;
  height: 72px;
  margin-bottom: 20px;
  place-items: center;
  color: #fff;
  background: var(--cinnabar);
  border: 3px double #fff;
  border-radius: 50%;
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 34px;
  animation: seal-pulse 1.4s ease-in-out infinite;
}

.loading-state h2 {
  min-width: 240px;
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 28px;
}

.progress-track {
  width: 240px;
  height: 4px;
  margin-top: 24px;
  overflow: hidden;
  background: #d5dfda;
  border-radius: 2px;
}

.progress-track span {
  display: block;
  width: 40%;
  height: 100%;
  background: var(--jade);
  animation: progress-move 1.2s ease-in-out infinite;
}

@keyframes seal-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

@keyframes progress-move {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(350%);
  }
}

.result-state {
  width: min(100%, 720px);
  margin: 0 auto;
}

.result-header {
  align-items: flex-start;
  margin-bottom: 18px;
}

.result-header h2 {
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 32px;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--jade);
  border-color: var(--jade);
}

.result-question {
  margin: 0 0 22px;
  padding: 10px 12px;
  color: var(--ink-soft);
  background: #fff;
  border-left: 3px solid var(--gold);
  font-size: 14px;
}

.hexagram-flow {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.hexagram-flow > svg {
  justify-self: center;
  color: var(--gold);
}

.hexagram-block {
  min-width: 0;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 3px solid var(--jade);
  border-radius: 6px;
}

.changed-block {
  border-top-color: var(--cinnabar);
}

.hexagram-block span,
.verdict-block span {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-soft);
  font-size: 12px;
}

.hexagram-block strong {
  display: block;
  overflow: hidden;
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 28px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-facts {
  display: grid;
  margin: 0 0 20px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.result-facts div {
  min-width: 0;
  padding: 11px 14px;
  border-right: 1px solid var(--line);
}

.result-facts div:last-child {
  border-right: 0;
}

.result-facts dt {
  color: var(--ink-soft);
  font-size: 11px;
}

.result-facts dd {
  margin: 2px 0 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-tabs {
  display: grid;
  margin-bottom: 14px;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line-strong);
}

.result-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.result-tabs button[aria-selected="true"] {
  color: var(--jade-dark);
  border-bottom-color: var(--jade);
  font-weight: 700;
}

.tab-panel {
  min-height: 244px;
}

.interpretation-panel {
  display: grid;
  gap: 12px;
}

.verdict-block,
.advice-block {
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.verdict-block {
  border-left: 4px solid var(--cinnabar);
}

.verdict-block strong {
  display: block;
  color: var(--warning);
  font-family: STKaiti, KaiTi, "Kaiti SC", serif;
  font-size: 22px;
  line-height: 1.4;
}

.advice-block {
  border-left: 4px solid var(--jade);
}

.advice-block p,
.risk-notice {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.risk-notice {
  padding: 0 4px;
  font-size: 12px;
}

.card-panel {
  min-height: 420px;
}

.card-toolbar {
  margin-bottom: 12px;
}

.card-switch {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.card-switch button {
  min-height: 36px;
  padding: 0 13px;
  color: var(--ink-soft);
  background: #fff;
  border: 0;
  border-right: 1px solid var(--line);
  cursor: pointer;
  font-size: 12px;
}

.card-switch button:last-child {
  border-right: 0;
}

.card-switch button.active {
  color: #fff;
  background: var(--jade);
}

.generated-card-frame {
  display: grid;
  min-height: 390px;
  place-items: center;
  padding: 10px;
  background: #e3e9e5;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.generated-card-frame img {
  width: auto;
  max-width: 100%;
  height: 500px;
  object-fit: contain;
  background: #fff;
  border-radius: 3px;
}

.disclaimer {
  margin: 16px 0;
  padding-top: 12px;
  color: #667671;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.55;
}

.result-actions {
  align-items: stretch;
}

.secondary-button,
.telegram-button {
  flex: 1;
}

.secondary-button {
  color: var(--jade-dark);
  background: #fff;
  border: 1px solid var(--jade);
}

.secondary-button:hover {
  background: var(--jade-pale);
}

.telegram-button {
  color: #fff;
  background: #2aabee;
  border: 1px solid #169bdc;
}

.telegram-button:hover {
  background: #179bdc;
}

.telegram-button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
}

.recent-band {
  background: #fff;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.recent-inner {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 32px;
}

.recent-heading {
  margin-bottom: 16px;
}

.recent-heading h2 {
  font-size: 20px;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.history-item {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) 36px;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: #f7f9f7;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.history-item strong,
.history-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong {
  font-size: 14px;
}

.history-item span {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 11px;
}

.history-item a {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--jade);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.history-empty {
  margin: 0;
  padding: 18px 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1240px, calc(100% - 40px));
  min-height: 82px;
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: 12px;
}

.page-footer p {
  margin: 0;
}

.page-footer a {
  color: var(--jade);
  white-space: nowrap;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100% - 40px));
  padding: 11px 14px;
  color: #fff;
  background: var(--jade-dark);
  border: 1px solid #315d55;
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 390px minmax(0, 1fr);
  }

  .intake-pane,
  .result-pane {
    padding: 26px;
  }

  .empty-state {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .empty-copy {
    align-self: end;
  }

  .sample-card-frame {
    width: 250px;
    justify-self: center;
  }

  .sample-card-frame img {
    height: 410px;
  }
}

@media (max-width: 780px) {
  .workspace {
    width: min(680px, calc(100% - 24px));
    grid-template-columns: 1fr;
  }

  .intake-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .result-pane {
    min-height: 680px;
  }

  .empty-state,
  .loading-state {
    min-height: 610px;
  }

  .empty-state {
    grid-template-columns: minmax(0, 1fr) 250px;
  }

  .history-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    height: 62px;
  }

  .topbar-inner,
  .recent-inner,
  .page-footer {
    width: calc(100% - 32px);
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 22px;
  }

  .brand-copy strong {
    font-size: 18px;
  }

  .brand-copy small,
  .icon-link span {
    display: none;
  }

  .icon-link {
    width: 38px;
    padding: 0;
  }

  .workspace {
    width: 100%;
    margin: 0 0 24px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .intake-pane,
  .result-pane {
    padding: 22px 18px;
  }

  .pane-heading {
    margin-bottom: 24px;
  }

  h1 {
    font-size: 30px;
  }

  .method-badge {
    margin-top: 2px;
  }

  .category-grid span {
    min-height: 40px;
    font-size: 12px;
  }

  .digit-input {
    width: 72px;
    height: 82px;
  }

  .result-pane {
    min-height: 620px;
  }

  .empty-state,
  .loading-state {
    min-height: 570px;
  }

  .empty-state {
    grid-template-columns: 1fr;
  }

  .empty-copy h2 {
    font-size: 29px;
  }

  .sample-card-frame {
    width: 230px;
  }

  .sample-card-frame img {
    height: 360px;
  }

  .result-header h2 {
    font-size: 28px;
  }

  .hexagram-flow {
    grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr);
    gap: 6px;
  }

  .hexagram-block {
    padding: 13px 11px;
  }

  .hexagram-block strong {
    font-size: 22px;
  }

  .result-facts div {
    padding: 10px;
  }

  .result-facts dd {
    font-size: 13px;
  }

  .generated-card-frame img {
    height: 430px;
  }

  .result-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .history-list {
    grid-template-columns: 1fr;
  }

  .page-footer {
    min-height: 96px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
