:root {
  color-scheme: light;
  --ink: #222128;
  --muted: #67616f;
  --paper: #fffaf2;
  --paper-strong: #ffffff;
  --line: rgba(44, 33, 55, 0.16);
  --rose: #b94762;
  --indigo: #313c78;
  --teal: #1d776c;
  --gold: #b37a2a;
  --shadow: 0 22px 70px rgba(35, 27, 45, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 250, 242, 0.88), rgba(244, 239, 232, 0.96)),
    url("assets/fortune-bg.png") center top / cover fixed;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 44px;
}

.hero {
  min-height: 330px;
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--line);
}

.hero__content {
  max-width: 660px;
  padding: 0 0 38px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--rose);
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 12px;
  font-size: clamp(3rem, 10vw, 6.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.lead {
  margin-bottom: 0;
  color: #3c3544;
  font-size: 1.18rem;
  line-height: 1.8;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
  padding: 28px 0;
}

.fortune-form,
.result-card,
.history-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.fortune-form {
  display: grid;
  gap: 18px;
  padding: 22px;
  border-radius: 8px;
}

label span,
legend {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

input[type="text"],
input[type="date"] {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  outline: none;
}

input:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(185, 71, 98, 0.28);
  outline-offset: 2px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segments {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.78);
}

.segments label {
  min-width: 0;
}

.segments input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segments span {
  display: grid;
  min-height: 36px;
  place-items: center;
  margin: 0;
  border-radius: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  cursor: pointer;
}

.segments input:checked + span {
  color: #fff;
  background: var(--indigo);
}

.primary-button {
  min-height: 50px;
  border: 0;
  border-radius: 7px;
  color: #fff;
  background: linear-gradient(135deg, var(--rose), var(--indigo));
  box-shadow: 0 14px 32px rgba(70, 46, 107, 0.28);
  font-weight: 850;
  cursor: pointer;
}

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

.result-card {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  padding: 30px;
  border-radius: 8px;
}

.card-orbit {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.card-orbit span {
  position: absolute;
  width: 120px;
  height: 120px;
  border: 1px solid rgba(179, 122, 42, 0.24);
  transform: rotate(18deg);
}

.card-orbit span:nth-child(1) {
  right: 28px;
  top: 28px;
}

.card-orbit span:nth-child(2) {
  right: 68px;
  top: 72px;
}

.card-orbit span:nth-child(3) {
  left: 30px;
  bottom: 28px;
}

.result-kicker {
  position: relative;
  margin-bottom: 12px;
  color: var(--teal);
  font-size: 0.88rem;
  font-weight: 850;
}

.result-card h2 {
  position: relative;
  max-width: 640px;
  margin-bottom: 14px;
  font-size: clamp(2rem, 5vw, 3.8rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.result-message {
  position: relative;
  max-width: 620px;
  color: #433b4a;
  font-size: 1.05rem;
  line-height: 1.85;
}

.fortune-details {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 24px 0;
}

.fortune-details div,
.score-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 250, 242, 0.68);
}

.fortune-details span,
.score-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.fortune-details strong {
  display: block;
  overflow-wrap: anywhere;
}

.score-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 24px;
}

.score-grid strong {
  font-size: 1.55rem;
}

.result-card.is-revealing {
  animation: reveal 540ms ease both;
}

.history-panel {
  padding: 20px;
  border-radius: 8px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.25rem;
}

#clear-history {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  cursor: pointer;
}

#history-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#history-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 250, 242, 0.7);
}

#history-list .empty {
  grid-column: 1 / -1;
  color: var(--muted);
}

.history-name {
  display: block;
  margin-bottom: 4px;
  font-weight: 850;
}

.history-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

@keyframes reveal {
  0% {
    opacity: 0.74;
    transform: translateY(8px) scale(0.99);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 820px) {
  body {
    background-attachment: scroll;
  }

  .app-shell {
    width: min(100% - 22px, 680px);
    padding-top: 18px;
  }

  .hero {
    min-height: 280px;
  }

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

  .fortune-details,
  .score-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 440px) {
  .segments {
    grid-template-columns: repeat(2, 1fr);
  }

  .fortune-details,
  .score-grid {
    grid-template-columns: 1fr;
  }

  .result-card,
  .fortune-form,
  .history-panel {
    padding: 18px;
  }
}
