* {
  box-sizing: border-box;
}

:root {
  --bg: #f3eadf;
  --bg-deep: #e8d5bf;
  --ink: #2f241d;
  --muted: #705b4b;
  --accent: #9d4b2f;
  --accent-2: #c27b4b;
  --card: rgba(255, 248, 240, 0.9);
  --line: rgba(91, 66, 49, 0.16);
  --success: #2f7a55;
  --danger: #a64034;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(194, 123, 75, 0.18), transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, #efe4d6 100%);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
}

.app-shell {
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 18px 14px 28px;
}

.hero {
  text-align: center;
  margin-bottom: 14px;
}

.hero-kicker,
.hero-sub,
.hint,
.hint-inline,
.status-subtext,
#charCount,
#selectedGenreLabel {
  color: var(--muted);
}

.hero-kicker {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.hero h1 {
  margin: 8px 0 6px;
  font-size: 1.95rem;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
}

.hero-sub {
  margin: 0;
  font-size: 0.95rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px rgba(91, 66, 49, 0.08);
}

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

.section-head h2,
.section-head label {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.78);
  padding: 12px 14px;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.6;
}

textarea:focus {
  outline: 2px solid rgba(157, 75, 47, 0.2);
  border-color: var(--accent);
}

.dpad-wrap {
  width: 260px;
  height: 260px;
  margin: 4px auto 0;
  position: relative;
}

.dpad-btn,
.dpad-center {
  position: absolute;
  border-radius: 999px;
}

.dpad-btn {
  width: 88px;
  height: 88px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f0dfcf);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 8px 16px rgba(91,66,49,.1);
}

.dpad-btn span {
  font-size: 0.84rem;
}

.dpad-btn.active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff7f1;
  border-color: transparent;
  transform: scale(1.04);
}

.dpad-btn.up { top: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.down { bottom: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.left { left: 0; top: 50%; transform: translateY(-50%); }
.dpad-btn.right { right: 0; top: 50%; transform: translateY(-50%); }
.dpad-btn.up.active { transform: translateX(-50%) scale(1.04); }
.dpad-btn.down.active { transform: translateX(-50%) scale(1.04); }
.dpad-btn.left.active { transform: translateY(-50%) scale(1.04); }
.dpad-btn.right.active { transform: translateY(-50%) scale(1.04); }

.dpad-center {
  width: 102px;
  height: 102px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 250, 244, 0.95);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
}

.genre-chip-label {
  font-size: 0.7rem;
  color: var(--muted);
}

#selectedMoodLabel {
  font-weight: 700;
  font-size: 0.88rem;
}

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

.genre-btn,
.player-actions button,
.download-link,
.generate-btn {
  border-radius: 14px;
  font-weight: 700;
}

.genre-btn {
  min-height: 46px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.72);
  color: var(--ink);
}

.genre-btn.active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff7f1;
  border-color: transparent;
}

.preview-card pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.84rem;
  line-height: 1.5;
  background: rgba(255,255,255,.6);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.generate-btn {
  width: 100%;
  border: none;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff8f4;
  padding: 16px;
  font-size: 1.08rem;
  box-shadow: 0 12px 24px rgba(157, 75, 47, 0.24);
  margin-bottom: 12px;
}

.generate-btn:disabled {
  opacity: 0.6;
}

.hidden {
  display: none;
}

.status-card {
  text-align: center;
}

.loading-orb {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  margin: 0 auto 10px;
  border: 4px solid rgba(157,75,47,.18);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

.progress-track {
  height: 10px;
  background: rgba(91,66,49,.1);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

#progressBar {
  height: 100%;
  width: 12%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .5s ease;
}

audio {
  width: 100%;
  margin: 8px 0 12px;
}

.player-actions {
  display: flex;
  gap: 8px;
}

.player-actions button,
.download-link {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.75);
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.download-link {
  flex: 0 0 auto;
  padding: 0 14px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 10px;
  }
  .dpad-wrap {
    width: 236px;
    height: 236px;
  }
  .dpad-btn {
    width: 80px;
    height: 80px;
  }
  .dpad-center {
    width: 92px;
    height: 92px;
  }
}
