* {
  box-sizing: border-box;
}

:root {
  --paper: #f6f1e8;
  --paper-soft: rgba(255, 252, 244, 0.86);
  --ink: #252928;
  --muted: #73706b;
  --line: rgba(55, 49, 39, 0.13);
  --teal: #0d5050;
  --teal-soft: rgba(13, 80, 80, 0.1);
  --red: #9b382f;
  --gold: #b99a66;
  --shadow: 0 16px 42px rgba(61, 49, 31, 0.12);
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  padding-bottom: 82px;
  max-width: 100%;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "SimSun", serif;
  background:
    linear-gradient(rgba(246, 241, 232, 0.78), rgba(246, 241, 232, 0.92)),
    url("../bg-main.webp") center bottom / cover fixed;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 22vh;
  background:
    linear-gradient(180deg, rgba(246, 241, 232, 0.18), rgba(246, 241, 232, 0.92)),
    url("../bg-splash.webp") center center / cover no-repeat;
  transition: opacity 1.05s ease, visibility 1.05s ease;
}

.splash.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-inner {
  position: relative;
  display: grid;
  justify-items: center;
}

.splash-dust::before,
.splash-dust::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(13, 80, 80, 0.18);
  box-shadow: 0 0 18px rgba(13, 80, 80, 0.08);
}

.splash-dust::before {
  width: 3px;
  height: 3px;
  top: 20px;
  right: 18px;
  animation: dustFloat 6s ease-in-out infinite;
}

.splash-dust::after {
  width: 2px;
  height: 2px;
  left: 4px;
  bottom: 112px;
  animation: dustFloat 7s 0.8s ease-in-out infinite;
}

.splash-logo {
  width: 152px;
  height: 152px;
  border-radius: 32px;
  margin-bottom: 38px;
  box-shadow: 0 24px 70px rgba(38, 31, 22, 0.18);
  animation: splashLogoIn 1.2s ease both, splashBreath 5.5s 1.2s ease-in-out infinite;
}

.splash-tagline {
  writing-mode: vertical-rl;
  text-orientation: upright;
  color: rgba(37, 41, 40, 0.82);
  font-size: 19px;
  line-height: 1.9;
  letter-spacing: 5px;
  margin-bottom: 28px;
  animation: splashTextIn 0.9s 0.7s ease both;
}

@keyframes splashLogoIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes splashTextIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 0.82; transform: translateY(0); }
}

@keyframes splashBreath {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.004); }
}

@keyframes dustFloat {
  0%, 100% { transform: translateY(0); opacity: 0.18; }
  50% { transform: translateY(-10px); opacity: 0.34; }
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 28px 18px 40px;
}

.header {
  padding: 12px 0 24px;
}

.header-content {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.title {
  margin: 0;
  color: var(--ink);
  font-size: clamp(30px, 6vw, 46px);
  font-weight: 500;
  letter-spacing: 0;
}

.seal {
  display: inline-flex;
  align-items: center;
  margin-left: 12px;
  border: 1px solid rgba(155, 56, 47, 0.58);
  padding: 3px 9px;
  color: var(--red);
  font-size: 15px;
  line-height: 1.1;
  writing-mode: horizontal-tb;
}

.taiji-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin-left: 10px;
  border: 1px solid rgba(13, 80, 80, 0.28);
  border-radius: 50%;
  color: var(--teal);
  font-family: "Times New Roman", serif;
  font-size: 16px;
  line-height: 1;
  vertical-align: 0.18em;
  background: rgba(255, 253, 247, 0.58);
}

.taiji-inline {
  display: inline-block;
  margin: 0 7px;
  color: var(--teal);
  font-family: "Times New Roman", serif;
  font-size: 0.72em;
  vertical-align: 0.08em;
}

.back-link {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--teal);
  text-decoration: none;
  background: rgba(255, 252, 244, 0.52);
}

.subtitle {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.main-content {
  display: block;
  align-items: start;
}

.tab-page {
  display: none;
  width: min(430px, 100%);
  margin: 0 auto;
}

.tab-page.active {
  display: block;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.control-card,
.result-card {
  padding: 20px;
}

.left-panel {
  position: sticky;
  top: 18px;
}

.form-group {
  margin-bottom: 17px;
}

.label {
  display: block;
  margin-bottom: 8px;
  color: #4a4742;
  font-size: 14px;
}

.input,
.time-display {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 253, 247, 0.72);
  outline: none;
}

.input:focus {
  border-color: rgba(13, 80, 80, 0.45);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.time-display-row {
  display: flex;
  gap: 9px;
}

.time-display {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  min-width: 0;
  width: auto;
  color: var(--muted);
  font-size: 14px;
}

.btn {
  min-height: 42px;
  border: 1px solid rgba(13, 80, 80, 0.36);
  border-radius: 6px;
  padding: 9px 14px;
  color: #fff;
  background: var(--teal);
}

.btn:hover {
  filter: brightness(1.03);
}

.btn-small {
  flex: 0 0 auto;
  min-width: 74px;
}

.btn-light,
.btn-secondary {
  color: var(--teal);
  background: rgba(255, 253, 247, 0.74);
}

.btn-history {
  background: #26312f;
  border-color: rgba(38, 49, 47, 0.28);
}

.btn-primary {
  background: var(--teal);
}

.btn-danger {
  border-color: rgba(155, 56, 47, 0.36);
  color: #fff;
  background: var(--red);
}

.button-group,
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
}

.title-site {
  color: var(--muted);
  font-size: 12px;
  font-family: Arial, sans-serif;
  font-weight: 400;
  letter-spacing: 0;
  white-space: nowrap;
}

.divider,
.divider-flex {
  height: 1px;
  background: var(--line);
}

.divider-flex {
  flex: 1;
}

.result-content {
  min-height: 520px;
}

.right-panel {
  display: none;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(430px, 100%);
  margin: 0 auto;
  border-top: 1px solid var(--line);
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  background: rgba(250, 247, 239, 0.94);
  backdrop-filter: blur(12px);
}

.bottom-nav-item {
  display: grid;
  justify-items: center;
  gap: 3px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.bottom-nav-item.active {
  color: var(--teal);
}

.nav-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
}

.bottom-nav-item.active .nav-icon {
  color: #fff;
  background: var(--teal);
}

.mine-page {
  padding-bottom: 14px;
}

.mine-section {
  margin-bottom: 18px;
}

.mine-section-title {
  margin: 0 0 10px;
  color: #6f6b63;
  font-size: 13px;
}

.mine-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper-soft);
  box-shadow: var(--shadow);
}

.mine-row {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 0;
  padding: 0 16px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.mine-row + .mine-row {
  border-top: 1px solid rgba(80, 67, 49, 0.1);
}

.mine-row-note {
  color: #8b8173;
  font-size: 12px;
  white-space: nowrap;
}

.mine-about {
  padding: 16px;
  color: #5f5a51;
  font-size: 14px;
  line-height: 1.9;
}

.mine-version {
  margin: 18px 0 2px;
  color: rgba(95, 90, 81, 0.68);
  font-size: 12px;
  line-height: 1.8;
  text-align: center;
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: 10020;
  transform: translateX(-50%) translateY(8px);
  border: 1px solid rgba(13, 80, 80, 0.18);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--teal);
  background: rgba(255, 253, 247, 0.96);
  box-shadow: 0 12px 30px rgba(61, 49, 31, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.welcome {
  display: grid;
  min-height: 460px;
  place-items: center;
  text-align: center;
  background:
    radial-gradient(circle at 50% 58%, rgba(13, 80, 80, 0.08), transparent 34%),
    linear-gradient(transparent, rgba(255, 255, 255, 0.22));
}

.welcome-title {
  color: var(--teal);
  font-size: 30px;
  letter-spacing: 0;
}

.welcome-sub {
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
}

.divination-method {
  margin-bottom: 14px;
  color: var(--red);
  font-size: 16px;
  text-align: center;
}

.gua-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin: 10px 0;
}

.gua-title,
.single-gua-title {
  color: var(--teal);
  font-size: 24px;
  text-align: center;
}

.single-gua-title {
  display: block;
  grid-column: 1 / -1;
  width: 100%;
  margin: 10px 0;
}

.gua-grid,
.single-gua-grid {
  display: grid;
  gap: 7px;
  margin: 14px 0;
}

.gua-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 48px;
  gap: 8px;
  align-items: stretch;
}

.single-gua-grid .gua-row {
  grid-template-columns: minmax(0, 1fr) 48px;
  width: min(360px, 100%);
  margin: 0 auto;
}

.liushen-cell,
.yao-cell {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: rgba(255, 253, 247, 0.62);
}

.liushen-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  writing-mode: vertical-rl;
}

.yao-row-top {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  line-height: 1.55;
  white-space: nowrap;
}

.liuqin {
  color: var(--teal);
  margin-right: 2px;
}

.najia {
  color: #343736;
}

.symbol {
  color: var(--ink);
  font-weight: 700;
}

.dong-yang,
.dong-yin {
  color: var(--red);
}

.jing {
  color: #9b9282;
}

.shi-ying,
.shi,
.ying {
  flex: 0 0 auto;
  border: 1px solid rgba(13, 80, 80, 0.28);
  border-radius: 999px;
  padding: 0 5px;
  color: var(--teal);
  background: var(--teal-soft);
  font-size: 11px;
}

.ben-yao .shi-ying {
  margin-left: 5px;
}

.fushen-line {
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 13px;
}

.gua-type-row,
.chonghe-type-row {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: center;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 253, 247, 0.46);
}

.single-type,
.single-chonghe {
  grid-column: 1 / -1;
}

.gua-type,
.chonghe-type {
  padding: 10px;
  color: var(--muted);
  text-align: center;
}

.gua-type-divider,
.chonghe-type-divider {
  width: 1px;
  height: 100%;
  background: var(--line);
}

.time-info,
.gua-result {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.result-actions {
  display: flex;
  justify-content: center;
  margin: 16px 0 4px;
}

.favorite-save {
  min-width: 132px;
}

.favorite-save.saved {
  background: #9a8a73;
}

.info-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
  color: var(--muted);
}

.info-value {
  color: var(--ink);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(32, 29, 24, 0.42);
}

.modal.active {
  display: flex;
}

.modal-content,
.modal-content-fullscreen {
  display: flex;
  flex-direction: column;
  width: min(640px, 100%);
  max-height: min(760px, 92vh);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 247, 239, 0.96);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

.modal-content-fullscreen {
  width: min(920px, 100%);
}

.modal-header,
.modal-header-fullscreen {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.modal-header h3,
.modal-header-fullscreen h3 {
  margin: 0;
  color: var(--teal);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.35;
}

.modal-close,
.modal-close-btn,
.modal-close-fullscreen {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.modal-body,
.modal-body-fullscreen {
  flex: 1 1 auto;
  max-height: calc(92vh - 72px);
  overflow: auto;
  padding: 18px;
  overscroll-behavior: contain;
}

.time-selector-modal {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.time-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(55, 49, 39, 0.1);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 253, 247, 0.54);
}

.time-row span {
  color: var(--teal);
  font-size: 13px;
  white-space: nowrap;
}

.time-select,
.yao-select,
.hex-select {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 8px 2px;
  color: var(--ink);
  background: transparent;
  outline: none;
}

#timeModal .modal-content {
  width: min(520px, 100%);
  background:
    linear-gradient(rgba(250, 247, 239, 0.96), rgba(250, 247, 239, 0.96)),
    url("../bg-detail.webp") center bottom / cover;
}

#timeModal .modal-header {
  padding: 18px 20px 14px;
}

#timeModal .modal-header h3 {
  color: var(--ink);
  font-size: 22px;
}

#timeModal .modal-body {
  padding: 18px 20px 20px;
}

#timeModal #setCurrentTime {
  width: 100%;
  margin-bottom: 12px;
}

#timeModal .modal-actions {
  grid-template-columns: 1fr 1fr;
}

.divination-info,
.instruction {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.8;
}

.yao-list {
  display: grid;
  gap: 6px;
}

.yao-selector,
.manual-moving,
.palace-selector,
.yao-selection {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.yao-selection {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.yao-selector,
.palace-item,
.yao-checkbox-label {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(255, 253, 247, 0.56);
}

.yao-checkbox-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 38px;
  padding: 7px 5px;
  font-size: 14px;
  white-space: nowrap;
}

.yao-name,
.palace-label-simple {
  display: block;
  margin-bottom: 5px;
  color: var(--teal);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-empty {
  color: var(--muted);
  text-align: center;
}

.consult-entry {
  margin-top: 16px;
  width: 100%;
}

.consult-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(37, 41, 40, 0.28);
}
.consult-modal.active { display: flex; }
.consult-modal-panel {
  width: min(430px, 100%);
  border-radius: 14px 14px 0 0;
  border: 1px solid var(--line);
  background: rgba(255, 252, 244, 0.98);
  box-shadow: 0 -18px 60px rgba(61, 49, 31, 0.18);
}
.consult-modal-head {
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.consult-modal-head h3 { margin: 0; color: var(--teal); font-size: 18px; font-weight: 500; }
.consult-modal-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 253, 247, 0.74);
  color: var(--ink);
  font-size: 22px;
}
.consult-modal-body { padding: 16px; color: #5f5a51; font-size: 14px; line-height: 1.85; }
.consult-modal-body p { margin: 0 0 12px; }

.history-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px;
  background: rgba(255, 253, 247, 0.64);
}

.history-item-time {
  color: var(--muted);
  font-size: 13px;
}

.history-item-question {
  margin-top: 4px;
  color: var(--ink);
}

.detail-content {
  color: var(--ink);
  line-height: 1.9;
}

.result-error {
  border: 1px solid rgba(155, 56, 47, 0.24);
  border-radius: 6px;
  padding: 12px;
  color: var(--red);
  background: rgba(155, 56, 47, 0.07);
}

.disabled,
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 780px) {
  #app {
    padding: 18px 12px 26px;
  }

  .main-content {
    grid-template-columns: 1fr;
  }

  .left-panel {
    position: static;
  }

  .control-card,
  .result-card {
    padding: 16px;
  }

  .brand-row {
    align-items: flex-start;
  }

  .title {
    font-size: 34px;
  }

  .subtitle {
    font-size: 13px;
    line-height: 1.7;
  }

  .result-content {
    min-height: 360px;
  }

  .welcome {
    min-height: 300px;
  }

  .gua-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 38px;
    gap: 6px;
  }

  .single-gua-grid .gua-row {
    grid-template-columns: minmax(0, 1fr) 38px;
    width: min(280px, 100%);
  }

  .liushen-cell,
  .yao-cell {
    padding: 7px 6px;
    font-size: 13px;
  }

  .gua-title,
  .single-gua-title {
    font-size: 21px;
  }

  .modal {
    padding: 10px;
    align-items: stretch;
  }

  .modal-content {
    max-height: calc(100vh - 20px);
  }

  .modal-body {
    max-height: none;
  }

  #manualModal .modal-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  #manualModal .manual-moving {
    gap: 7px;
    margin-bottom: 8px;
  }

  #manualModal .manual-moving h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
  }

  #manualModal .yao-selection {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }

  #manualModal .yao-checkbox-label {
    min-height: 34px;
    padding: 5px 2px;
    font-size: 12px;
    gap: 2px;
  }

  #manualModal .yao-checkbox {
    width: 12px;
    height: 12px;
    margin: 0;
  }

  #manualModal .modal-actions {
    position: sticky;
    bottom: -18px;
    z-index: 2;
    margin: 2px -18px -18px;
    border-top: 1px solid var(--line);
    padding: 10px 18px 14px;
    background: rgba(250, 247, 239, 0.98);
  }
}

@media (max-width: 430px) {
  .back-link {
    padding: 8px 10px;
    font-size: 13px;
  }

  .button-group,
  .modal-actions,
  #timeModal .modal-actions {
    grid-template-columns: 1fr;
  }

  .time-display-row {
    display: grid;
  }

  .time-selector-modal {
    grid-template-columns: 1fr;
  }

  .gua-title-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
}
