:root {
  --ink: #241710;
  --paper: #f5ddb0;
  --paper-deep: #e4b75d;
  --tile: #171311;
  --tile-light: #342622;
  --wood: #4a2118;
  --wood-dark: #1d100d;
  --red: #8e1f1b;
  --green: #2e5a49;
  --gold: #d9a441;
  --blue: #243f54;
  --line: rgba(64, 28, 18, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  background:
    linear-gradient(rgba(22, 13, 10, 0.64), rgba(22, 13, 10, 0.78)),
    repeating-linear-gradient(90deg, #4b2119 0 2px, #351711 2px 18px);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 26px 16px;
}

.hanok-stage {
  width: min(1040px, 100%);
  position: relative;
  filter: drop-shadow(0 30px 42px rgba(0, 0, 0, 0.42));
}

.hanok-stage::before,
.hanok-stage::after {
  content: "";
  position: absolute;
  top: 126px;
  z-index: 2;
  width: 38px;
  height: 82px;
  background:
    linear-gradient(90deg, rgba(255, 238, 166, 0.25), transparent 24%, transparent 76%, rgba(255, 238, 166, 0.25)),
    #b83024;
  border: 3px solid #4b1812;
  box-shadow: 0 0 26px rgba(217, 164, 65, 0.42);
}

.hanok-stage::before {
  left: 24px;
}

.hanok-stage::after {
  right: 24px;
}

.roof {
  position: relative;
  height: 118px;
  margin: 0 auto -12px;
  width: min(940px, 96%);
}

.roof-line {
  position: absolute;
  inset: 18px 3% auto;
  height: 58px;
  border-radius: 50% 50% 18px 18px;
  background: linear-gradient(180deg, #4b332a, var(--tile) 70%);
  transform: perspective(420px) rotateX(18deg);
}

.tiles {
  position: absolute;
  inset: 28px 6% auto;
  height: 50px;
  background:
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(255, 255, 255, 0.08) 34px 38px),
    repeating-radial-gradient(ellipse at 50% 100%, rgba(255, 255, 255, 0.1) 0 3px, transparent 3px 19px);
  border-radius: 42% 42% 12px 12px;
}

.eaves {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  height: 30px;
  border-radius: 0 0 18px 18px;
  background: linear-gradient(180deg, #120d0c, #2d1915);
  border-bottom: 7px solid var(--wood-dark);
}

.wood-frame {
  border: 14px solid var(--wood-dark);
  background:
    linear-gradient(90deg, rgba(255, 213, 127, 0.1), transparent 18%, transparent 82%, rgba(255, 213, 127, 0.1)),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 16px),
    var(--wood);
  padding: 14px;
}

.topbar {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px 22px;
  color: #ffecc1;
  background:
    linear-gradient(180deg, rgba(255, 223, 143, 0.18), transparent 48%),
    repeating-linear-gradient(90deg, rgba(255, 236, 193, 0.08) 0 2px, transparent 2px 28px),
    linear-gradient(90deg, #5c1714, #8e1f1b 38%, #4a1712 100%),
    var(--wood-dark);
  border-bottom: 8px solid var(--wood-dark);
}

.topbar::after {
  content: "占  卜  命";
  position: absolute;
  left: 50%;
  bottom: -24px;
  transform: translateX(-50%);
  z-index: 2;
  min-width: 138px;
  padding: 5px 14px;
  color: #2c1710;
  background: var(--paper-deep);
  border: 2px solid #4b2119;
  text-align: center;
  font-weight: 900;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.82rem;
  letter-spacing: 0;
  color: #f7d58e;
  opacity: 1;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 1;
  font-weight: 900;
}

.seal {
  width: 60px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #4a140f;
  background: #f0c86c;
  border: 3px solid rgba(75, 24, 18, 0.72);
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 0 0 22px rgba(240, 200, 108, 0.28);
}

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  background: #130b09;
  border-bottom: 8px solid var(--wood-dark);
}

.step {
  min-height: 52px;
  border: 0;
  color: #f8dca2;
  background: #2d1511;
  cursor: pointer;
  border-right: 1px solid rgba(255, 244, 217, 0.18);
  transition:
    background-color 220ms ease,
    color 220ms ease,
    transform 220ms ease;
}

.step.is-active {
  color: #2c1710;
  background: #e7b84e;
  font-weight: 800;
  transform: translateY(2px);
}

.paper-panel {
  position: relative;
  overflow: hidden;
  display: grid;
  align-items: center;
  min-height: 560px;
  background:
    linear-gradient(rgba(255, 221, 151, 0.88), rgba(255, 221, 151, 0.92)),
    repeating-linear-gradient(0deg, rgba(142, 31, 27, 0.08) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(90deg, rgba(142, 31, 27, 0.08) 0 1px, transparent 1px 42px),
    linear-gradient(90deg, rgba(122, 45, 24, 0.12) 1px, transparent 1px),
    var(--paper);
  background-size: auto, auto, auto, 34px 34px, auto;
  border: 3px solid #2d1511;
  padding: clamp(22px, 4vw, 44px);
  transition:
    box-shadow 420ms ease,
    transform 420ms ease;
}

.paper-panel.is-switching {
  transform: translateY(-2px);
  box-shadow: inset 0 0 0 999px rgba(255, 248, 225, 0.12);
}

.view {
  display: none;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
}

.view.is-active {
  display: block;
  animation: pageReveal 560ms cubic-bezier(0.2, 0.78, 0.22, 1);
  transform-origin: 50% 12%;
}

.section-head {
  display: grid;
  gap: 4px;
  margin-bottom: 24px;
}

.section-head p {
  margin-bottom: 0;
  color: #674027;
  line-height: 1.6;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1.1;
}

.saju-form {
  display: grid;
  gap: 18px;
  max-width: 680px;
  margin: 0 auto;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 800;
}

.date-field {
  display: grid;
  gap: 8px;
  font-weight: 800;
}

.date-picker {
  display: grid;
  gap: 10px;
}

.date-inputs {
  display: grid;
  grid-template-columns: 1.35fr 0.82fr 0.82fr;
  gap: 10px;
}

.date-inputs label {
  gap: 6px;
  color: #674027;
  font-size: 0.86rem;
}

.date-inputs input {
  min-height: 56px;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 900;
  text-align: center;
  background: rgba(255, 244, 214, 0.94);
}

.date-inputs input::-webkit-outer-spin-button,
.date-inputs input::-webkit-inner-spin-button {
  margin: 0;
}

.date-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.date-button {
  min-height: 42px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(228, 183, 93, 0.72);
  cursor: pointer;
  font-weight: 900;
  transition:
    background-color 180ms ease,
    transform 180ms ease;
}

.date-button:active {
  transform: translateY(1px);
}

input,
select {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 244, 214, 0.94);
  padding: 0 14px;
  outline: 0;
}

input:focus,
select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(142, 31, 27, 0.18);
}

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

.primary-action,
.secondary-action {
  min-height: 52px;
  border: 0;
  padding: 0 20px;
  cursor: pointer;
  font-weight: 900;
}

.primary-action {
  color: #ffecc1;
  background: #7f1714;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}

.secondary-action {
  color: var(--ink);
  background: #edc467;
  border: 1px solid var(--line);
}

.next {
  margin-top: 24px;
}

.pillars {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.pillar {
  min-height: 142px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 245, 218, 0.88), rgba(239, 200, 107, 0.52)),
    rgba(255, 252, 239, 0.72);
  animation: itemRise 500ms cubic-bezier(0.2, 0.78, 0.22, 1) both;
}

.pillar:nth-child(2) {
  animation-delay: 70ms;
}

.pillar:nth-child(3) {
  animation-delay: 140ms;
}

.pillar:nth-child(4) {
  animation-delay: 210ms;
}

.pillar strong {
  font-size: 2.4rem;
}

.element-bars {
  display: grid;
  gap: 12px;
}

.element-row {
  display: grid;
  grid-template-columns: 54px 1fr 34px;
  gap: 12px;
  align-items: center;
  animation: itemRise 480ms cubic-bezier(0.2, 0.78, 0.22, 1) both;
}

.element-row:nth-child(2) {
  animation-delay: 60ms;
}

.element-row:nth-child(3) {
  animation-delay: 120ms;
}

.element-row:nth-child(4) {
  animation-delay: 180ms;
}

.element-row:nth-child(5) {
  animation-delay: 240ms;
}

.bar {
  height: 18px;
  background: rgba(61, 20, 14, 0.16);
  overflow: hidden;
}

.fill {
  height: 100%;
  width: var(--value);
  background: var(--color);
  transform-origin: left center;
  animation: barGrow 780ms cubic-bezier(0.18, 0.8, 0.22, 1) both;
}

.advice,
.result-sheet {
  margin-top: 24px;
  border-left: 6px solid var(--green);
  background: rgba(255, 238, 190, 0.82);
  padding: 18px;
  line-height: 1.7;
  animation: itemRise 520ms cubic-bezier(0.2, 0.78, 0.22, 1) 180ms both;
}

.fortune-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.fortune-card {
  min-height: 240px;
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 12px;
  border-top: 6px solid var(--accent);
  background:
    linear-gradient(180deg, rgba(255, 244, 214, 0.92), rgba(237, 196, 103, 0.34)),
    rgba(255, 252, 239, 0.78);
  box-shadow: inset 0 0 0 1px var(--line);
  animation: cardUnfold 560ms cubic-bezier(0.2, 0.78, 0.22, 1) both;
}

.fortune-card:nth-child(2) {
  animation-delay: 90ms;
}

.fortune-card:nth-child(3) {
  animation-delay: 180ms;
}

.fortune-card h3 {
  margin: 0;
  font-size: 1.35rem;
}

.score {
  display: flex;
  gap: 4px;
}

.coin {
  width: 22px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.28;
  transform: scale(0.84);
  transition:
    opacity 260ms ease,
    transform 260ms ease;
}

.coin.is-on {
  opacity: 1;
  transform: scale(1);
}

.result-sheet {
  border-left-color: var(--red);
  width: 100%;
}

.result-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 14px;
}

.result-grid.is-compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-block {
  min-height: 104px;
  padding: 14px;
  background: rgba(255, 238, 190, 0.76);
  border: 1px solid var(--line);
}

.result-block h4 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.result-block p {
  margin-bottom: 0;
}

.result-block.is-wide {
  grid-column: 1 / -1;
}

.result-more {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.result-more[hidden] {
  display: none;
}

.more-toggle {
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  border: 1px solid var(--line);
  color: #ffecc1;
  background: #7f1714;
  cursor: pointer;
  font-weight: 900;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.mini-elements {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.mini-element {
  min-height: 74px;
  display: grid;
  place-items: center;
  gap: 2px;
  color: #fff4cf;
  background: var(--color);
  font-weight: 900;
}

.mini-element span {
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.9;
}

.summary-fortunes {
  display: grid;
  gap: 8px;
}

.summary-fortune {
  display: grid;
  grid-template-columns: 74px 1fr 34px;
  align-items: center;
  gap: 10px;
}

.summary-meter {
  height: 10px;
  background: rgba(61, 36, 24, 0.12);
}

.summary-meter span {
  display: block;
  width: var(--value);
  height: 100%;
  background: var(--accent);
}

.result-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.result-title h3 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.tag {
  flex: 0 0 auto;
  padding: 8px 10px;
  color: #ffecc1;
  background: #7f1714;
  font-weight: 900;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

@keyframes pageReveal {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
    filter: blur(4px);
  }

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

@keyframes itemRise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

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

@keyframes cardUnfold {
  from {
    opacity: 0;
    transform: translateY(20px) rotateX(-7deg);
  }

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

@keyframes barGrow {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

@media (max-width: 720px) {
  body {
    background:
      radial-gradient(circle at 50% -10%, rgba(217, 164, 65, 0.22), transparent 42%),
      linear-gradient(180deg, #190d0b 0%, #2b120f 48%, #140908 100%);
  }

  .app-shell {
    min-height: 100svh;
    align-items: start;
    padding: 0;
  }

  .hanok-stage {
    width: 100%;
    max-width: 100vw;
    min-height: 100svh;
    filter: none;
  }

  .hanok-stage::before,
  .hanok-stage::after {
    display: none;
  }

  .hanok-stage::before {
    left: 8px;
  }

  .hanok-stage::after {
    right: 8px;
  }

  .roof {
    display: none;
  }

  .wood-frame {
    width: 100%;
    min-height: 100svh;
    overflow: hidden;
    border: 0;
    padding: 0;
    background:
      linear-gradient(180deg, rgba(126, 23, 20, 0.2), transparent 160px),
      #1a0d0a;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    min-width: 0;
    min-height: 76px;
    padding: 14px 42px 12px;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 236, 193, 0.2);
    box-shadow: 0 14px 26px rgba(0, 0, 0, 0.28);
  }

  .topbar::after {
    left: auto;
    right: 42px;
    bottom: -13px;
    transform: none;
    min-width: 74px;
    padding: 3px 8px;
    font-size: 0.72rem;
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
  }

  .topbar > div:first-child {
    min-width: 0;
    width: 100%;
    text-align: center;
  }

  .eyebrow {
    font-size: 0.74rem;
  }

  h1 {
    font-size: 1.82rem;
  }

  h2 {
    font-size: 1.55rem;
  }

  .seal {
    position: absolute;
    right: 12px;
    width: 40px;
    font-size: 1.25rem;
  }

  .steps {
    position: sticky;
    top: 76px;
    z-index: 9;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 100%;
    overflow: hidden;
    border-bottom: 1px solid rgba(255, 236, 193, 0.18);
    background: rgba(19, 11, 9, 0.96);
  }

  .step {
    min-width: 0;
    min-height: 44px;
    padding: 0 4px;
    white-space: nowrap;
    font-size: 0.86rem;
    border-right-color: rgba(255, 244, 217, 0.1);
  }

  .form-grid,
  .date-inputs,
  .pillars,
  .fortune-cards,
  .result-grid,
  .result-grid.is-compact {
    grid-template-columns: 1fr;
  }

  .paper-panel {
    width: 100%;
    min-height: calc(100svh - 121px);
    padding: 18px 14px 28px;
    align-items: start;
    border: 0;
    background:
      linear-gradient(rgba(255, 224, 157, 0.94), rgba(255, 224, 157, 0.96)),
      repeating-linear-gradient(0deg, rgba(142, 31, 27, 0.07) 0 1px, transparent 1px 36px),
      var(--paper);
  }

  .view {
    max-width: 100%;
  }

  .section-head {
    gap: 6px;
    margin-bottom: 18px;
    text-align: left;
  }

  .section-head p {
    font-size: 0.92rem;
  }

  .saju-form {
    gap: 14px;
    max-width: none;
  }

  label,
  .date-field {
    gap: 7px;
  }

  input,
  select,
  .date-inputs input,
  .primary-action,
  .secondary-action {
    min-height: 50px;
    border-radius: 0;
  }

  input,
  select,
  .date-inputs input {
    font-size: 1rem;
  }

  .date-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .date-button {
    min-height: 46px;
    padding: 0 6px;
  }

  .primary-action,
  .secondary-action,
  .more-toggle {
    width: 100%;
  }

  .pillars {
    gap: 10px;
  }

  .pillar {
    min-height: 84px;
    grid-template-columns: 54px 1fr auto;
    align-content: center;
    justify-items: start;
    padding: 12px 14px;
  }

  .pillar strong {
    font-size: 1.74rem;
  }

  .element-row {
    grid-template-columns: 38px 1fr 28px;
    gap: 8px;
  }

  .fortune-card {
    min-height: 0;
    padding: 16px;
  }

  .fortune-card h3 {
    font-size: 1.2rem;
  }

  .mini-elements {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .mini-element {
    min-height: 64px;
    font-size: 0.95rem;
  }

  .summary-fortune {
    grid-template-columns: 62px 1fr 30px;
    gap: 8px;
    font-size: 0.92rem;
  }

  .result-sheet,
  .advice {
    margin-top: 18px;
    padding: 14px;
  }

  .result-block {
    min-height: 0;
    padding: 12px;
  }

  .result-title {
    display: grid;
    gap: 10px;
    text-align: left;
  }

  .tag {
    justify-self: start;
  }

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

@media (max-width: 380px) {
  .wood-frame {
    border: 0;
    padding: 0;
  }

  .topbar {
    padding: 12px 36px 10px;
  }

  .topbar::after {
    right: 36px;
  }

  h1 {
    font-size: 1.58rem;
  }

  .paper-panel {
    padding: 16px 10px 22px;
  }

  .mini-elements {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mini-element:last-child {
    grid-column: 1 / -1;
  }
}

@media print {
  body {
    background: white;
  }

  .roof,
  .topbar,
  .steps,
  .actions,
  .fortune-cards,
  .pillars,
  .element-bars,
  .advice,
  .section-head {
    display: none;
  }

  .wood-frame,
  .paper-panel,
  .result-sheet {
    border: 0;
    box-shadow: none;
    background: white;
    padding: 0;
  }

  .view {
    display: none;
  }

  .view[data-view="result"] {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
