:root {
  color-scheme: light;
  --title: #1e2a3a;
  --accent: #b34a4a;
  --text: #444444;
  --muted: #aaaaaa;
  --bg: #f7f5f0;
  --card: #ffffff;
  --line: #e8e4de;
  --shadow: 0 18px 45px rgba(30, 42, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
}

button {
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(760px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 40px 32px;
}

.home-screen {
  min-height: calc(100vh - 80px);
  display: grid;
  grid-template-rows: 20fr 10fr 50fr 10fr 10fr;
  gap: 22px;
  animation: pageIn 0.6s ease both;
}

.home-screen.is-leaving .prompt-block,
.home-screen.is-leaving .mood-section,
.home-screen.is-leaving .random-section {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.title-block {
  display: grid;
  align-content: center;
  min-height: 0;
  text-align: center;
}

.title-block h1 {
  margin: 0;
  color: var(--title);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0;
}

.title-block h1 span {
  color: var(--accent);
}

.title-block p {
  margin: 12px 0 0;
  color: #999999;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 4px;
}

.prompt-block {
  min-height: 0;
  text-align: center;
}

.prompt-block h2 {
  margin: 0 0 8px;
  color: var(--title);
  font-size: 1.1rem;
  font-weight: 450;
  letter-spacing: 0;
}

.prompt-block p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.mood-section {
  display: grid;
  align-content: center;
  min-height: 0;
}

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

.mood-card {
  min-height: 90px;
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: var(--card);
  text-align: left;
  box-shadow: 0 0 0 rgba(30, 42, 58, 0);
  animation: cardIn 0.48s ease both;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.mood-card:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .mood-card:hover {
    transform: translateY(-3px);
    background: var(--hover-bg);
    border-color: var(--hover-border);
    box-shadow: 0 12px 24px rgba(30, 42, 58, 0.1);
  }

  .random-button:hover,
  .modal-button:hover {
    transform: translateY(-2px);
    background: #2c3e5a;
    box-shadow: 0 13px 26px rgba(30, 42, 58, 0.2);
  }
}

.mood-card:nth-child(1) { animation-delay: 0.02s; }
.mood-card:nth-child(2) { animation-delay: 0.07s; }
.mood-card:nth-child(3) { animation-delay: 0.12s; }
.mood-card:nth-child(4) { animation-delay: 0.17s; }
.mood-card:nth-child(5) { animation-delay: 0.22s; }
.mood-card:nth-child(6) { animation-delay: 0.27s; }

.mood-emoji {
  font-size: 1.45rem;
  line-height: 1;
}

.mood-title {
  color: var(--title);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.mood-desc {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 400;
  line-height: 1.45;
}

.random-section {
  min-height: 0;
  display: grid;
  place-items: center;
}

.random-button {
  min-height: 52px;
  padding: 14px 40px;
  border: 0;
  border-radius: 60px;
  color: white;
  background: var(--title);
  font-size: 1.05rem;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(30, 42, 58, 0.16);
  transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.random-button:active,
.modal-button:active {
  transform: scale(0.96);
}

.fortune-line {
  min-height: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  animation: pulseText 4s ease-in-out infinite;
}

.loading-screen {
  min-height: calc(100vh - 80px);
  display: grid;
  grid-template-rows: 20fr 70fr 10fr;
  gap: 22px;
  animation: fadeIn 0.25s ease both;
}

.loading-title-block {
  min-height: 0;
}

.loading-card {
  width: min(460px, 100%);
  align-self: center;
  justify-self: center;
  padding: 44px 28px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.82);
  text-align: center;
  box-shadow: var(--shadow);
}

.loading-icon {
  font-size: 3.2rem;
  animation: popIn 0.28s ease both;
}

.loading-card h2 {
  margin: 18px 0 8px;
  color: var(--title);
  font-size: 1.4rem;
  font-weight: 700;
}

.loading-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-dots {
  height: 24px;
  margin: 18px 0 22px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  display: inline-block;
  margin: 0 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.1s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

.ghost-button {
  min-height: 40px;
  padding: 8px 24px;
  border: 1px solid var(--line);
  border-radius: 40px;
  color: var(--title);
  background: white;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  animation: fadeIn 0.24s ease both;
}

.modal.is-closing {
  animation: fadeOut 0.2s ease both;
}

.modal.is-closing .modal-card {
  animation: modalOut 0.25s ease-in both;
}

.modal-card {
  position: relative;
  width: min(460px, 100%);
  padding: 36px 30px 28px;
  border-radius: 28px;
  background: var(--card);
  text-align: center;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.22);
  animation: modalIn 0.3s ease both;
}

.modal-card.is-switching {
  animation: contentSwitch 0.2s ease both;
}

.close-button {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
}

.modal-kicker {
  margin: 0 0 18px;
  color: var(--title);
  font-size: 0.9rem;
  font-weight: 600;
}

#modal-song-title {
  margin: 0 0 12px;
  color: var(--title);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.modal-meta {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.85rem;
}

.modal-tag {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 22px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.7rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.modal-reason {
  min-height: 64px;
  margin: 0 auto 24px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.8;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-button {
  min-height: 42px;
  padding: 10px 24px;
  border: 0;
  border-radius: 40px;
  color: white;
  background: var(--title);
  font-weight: 600;
  transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.modal-button.secondary {
  color: var(--title);
  background: #f0eee8;
}

.modal-button.secondary:hover {
  color: white;
}

.modal-fortune {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

button:focus-visible {
  outline: 3px solid rgba(179, 74, 74, 0.25);
  outline-offset: 3px;
}

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

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.82);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes modalOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

@keyframes contentSwitch {
  0% {
    opacity: 0.45;
    transform: scale(0.985);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes dotPulse {
  0%, 80%, 100% {
    opacity: 0;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-5px);
  }
}

body.modal-open {
  overflow: hidden;
}

@keyframes pulseText {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@media (max-width: 768px) {
  .app-shell {
    padding: 24px 16px;
  }

  .home-screen,
  .loading-screen {
    min-height: calc(100vh - 48px);
    gap: 20px;
  }

  .title-block h1 {
    font-size: 2rem;
  }

  .mood-card {
    padding: 16px 14px;
  }
}

@media (max-width: 500px) {
  .app-shell {
    padding: 24px 16px;
  }

  .mood-grid {
    gap: 12px;
  }

  .mood-card {
    min-height: 82px;
    padding: 15px 12px;
  }

  .mood-desc {
    display: none;
  }

  .random-button {
    width: min(100%, 260px);
    padding-inline: 20px;
  }

  .modal {
    padding: 16px;
  }

  .modal-card {
    padding: 32px 22px 24px;
  }
}

@media (max-width: 400px) {
  .mood-grid {
    gap: 10px;
  }

  .mood-card {
    padding: 13px 10px;
  }

  .mood-title {
    font-size: 0.9rem;
  }
}
