:root {
  --bg: #000;
  --fg: #eee;
  --card: #111;
  --border: #333;
  --muted: #888;
  --accent: #ff7bac;
  --font-serif: "Noto Serif JP", serif;
  --font-sans: "Space Grotesk", sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg);
}

#petal-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

#petal-layer.muted {
  display: none;
}

.petal {
  position: absolute;
  top: -10%;
  width: 18px;
  height: 26px;
  border-radius: 40% 60% 70% 30%;
  background: rgba(255, 182, 193, 0.65);
  filter: blur(0.5px);
  animation: fall linear forwards;
}

@keyframes fall {
  0% {
    transform: translate3d(0, -10vh, 0) rotate(0deg);
  }
  70% {
    transform: translate3d(10vw, 60vh, 0) rotate(120deg);
  }
  100% {
    transform: translate3d(-5vw, 110vh, 0) rotate(260deg);
    opacity: 0;
  }
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  z-index: 1;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  letter-spacing: 0.24rem;
  text-transform: uppercase;
  margin: 0.2rem 0 0;
}

.app-header span {
  margin-left: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.8em;
  color: var(--muted);
}

.eyebrow {
  text-transform: uppercase;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  letter-spacing: 0.4rem;
  color: var(--muted);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.timer {
  width: 3rem;
  height: 3rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-family: var(--font-sans);
  font-size: 1.1rem;
  letter-spacing: 0.1em;
}

.black-garden {
  z-index: 1;
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.6fr;
  gap: 1.5rem;
  align-items: stretch;
}

.poem-card,
.detail-panel,
.control-panel {
  background: #111 !important;
  border: 1px solid #333;
  border-radius: 1.2rem;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  color: #fff;
}

.poem-card {
  cursor: pointer;
  transition: border-color 0.3s ease, transform 0.3s ease;
}

.poem-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.poem-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.25);
}

.poem-card.loading {
  cursor: progress;
  border-color: rgba(255, 255, 255, 0.2);
}

.poem-card.loading::after {
  content: "生成中...";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  letter-spacing: 0.3rem;
  font-size: 0.9rem;
}

.poem-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.poem-text {
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  line-height: 1.8;
  letter-spacing: 0.08em;
}

.poem-caption {
  margin-top: 1.8rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--muted);
}

.detail-panel h2 {
  margin: 0;
  letter-spacing: 0.4rem;
  font-size: 1rem;
  font-family: var(--font-sans);
}

.detail-panel.empty .analysis {
  opacity: 0.55;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.detail-stars {
  font-size: 0.9rem;
  letter-spacing: 0.3rem;
  color: var(--accent);
}

.analysis {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.08);
  max-height: 22rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.analysis-label {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.2rem;
  margin-top: 1rem;
  color: var(--muted);
}

.truth {
  font-size: 1rem;
  letter-spacing: 0.1em;
  margin-top: 0.4rem;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-family: var(--font-sans);
  color: #fff !important;
}

.control-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  letter-spacing: 0.4rem;
  text-transform: uppercase;
  color: #999;
}

.switch,
.range {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.switch input {
  display: none;
}

.switch span:first-child {
  font-size: 0.85rem;
  color: #fff;
}

.slider {
  width: 46px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid #666;
  background: #333;
  position: relative;
  cursor: pointer;
}

.slider::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #888;
  top: 2px;
  left: 3px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch input:checked + .slider {
  background: rgba(255, 255, 255, 0.3);
  border-color: #fff;
}

.switch input:checked + .slider::after {
  transform: translateX(20px);
  background: #fff;
}

.range input[type="range"] {
  width: 120px;
}

button {
  border: none;
  cursor: pointer;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.detail {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  color: #eee;
  padding: 4vh 4vw;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail.active {
  opacity: 1;
  pointer-events: auto;
}

.detail-content {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  background: rgba(20, 20, 20, 0.8);
  border: 1px solid #333;
  border-radius: 1.2rem;
  padding: 2.5rem;
  max-height: 85vh;
  overflow-y: auto;
}

.detail-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  border: 1px solid #555;
  border-radius: 999px;
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.5);
  font-size: 1.2rem;
  line-height: 34px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.detail-close:hover {
  border-color: #fff;
}

.detail-poem {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  line-height: 2;
  letter-spacing: 0.1em;
  text-align: center;
  padding: 1.5rem 0;
  border-bottom: 1px solid #333;
  margin-bottom: 1.5rem;
}

.detail-poem p {
  margin: 0;
}

.detail-analysis {
  line-height: 1.8;
  font-size: 0.95rem;
  color: #bbb;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 30vh;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.detail-analysis p {
  margin: 0;
}

.detail-analysis::-webkit-scrollbar {
  width: 4px;
}

.detail-analysis::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 2px;
}

.detail-hint {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #333;
  font-size: 0.9rem;
  color: #888;
  font-style: italic;
}

.detail-controls {
  margin-top: 1.5rem;
  text-align: center;
}

.detail-controls button {
  border: 1px solid #555;
  padding: 0.6rem 1.8rem;
  letter-spacing: 0.2rem;
  font-size: 0.85rem;
  border-radius: 999px;
  transition: all 0.2s ease;
}

.detail-controls button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.detail-controls button.active {
  color: var(--accent);
  border-color: var(--accent);
}

.detail::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.05), transparent 40%);
  pointer-events: none;
}

.seed-toggle {
  position: fixed;
  bottom: calc(3vh + env(safe-area-inset-bottom, 0px));
  right: 3vw;
  width: 32px;
  height: 32px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  text-align: center;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 32px;
  z-index: 100;
  background: rgba(0, 0, 0, 0.8);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.seed-toggle:hover {
  transform: scale(1.1);
  border-color: #fff;
  color: #fff;
  box-shadow: 0 0 20px rgba(255, 123, 172, 0.4);
}

.seed-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.seed-modal.active {
  display: flex;
}

.seed-box {
  display: flex;
  flex-direction: column;
  gap: 2vh;
  padding: 2rem;
  border: 1px solid #444;
  border-radius: 1rem;
  background: rgba(10, 10, 10, 0.9);
}

#seedInput {
  width: min(60vw, 420px);
  padding: 10px;
  background: #111;
  border: 1px solid #444;
  color: #eee;
  font-size: 16px;
}

.file-upload {
  width: min(60vw, 420px);
}

.file-label {
  display: block;
  padding: 10px;
  background: #111;
  border: 1px dashed #555;
  color: #999;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.file-label:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.file-label.has-file {
  border-color: var(--accent);
  color: var(--accent);
  border-style: solid;
}

.seed-note {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.seed-message,
.seed-status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.seed-preview {
  width: min(60vw, 460px);
  border: 1px solid #333;
  border-radius: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.seed-preview[hidden] {
  display: none;
}

.seed-preview-lines {
  display: grid;
  gap: 0.4rem;
}

.seed-preview-lines p {
  margin: 0;
  font-size: 1rem;
  color: #fff !important;
}

.seed-preview-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.seed-field {
  width: min(60vw, 420px);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.8rem;
}

.seed-field-label {
  font-size: 14px;
  color: #999;
}

#seedAuthor {
  width: min(60vw, 420px);
  padding: 10px;
  background: #111;
  border: 1px solid #444;
  color: #eee;
  font-size: 16px;
}

#seedAuthor::placeholder {
  color: #999;
}

.seed-preview-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.seed-preview-actions button {
  flex: 1;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  border: 1px solid #fff;
  background: rgba(255, 255, 255, 0.08);
  color: #fff !important;
  font-size: 0.9rem;
  letter-spacing: 0.1rem;
  text-transform: none;
  cursor: pointer;
}

.seed-preview-actions button.primary {
  background: var(--fg);
  color: #000 !important;
  border-color: var(--fg);
}

.seed-preview-actions .ghost {
  border-color: #fff;
  color: #fff !important;
  letter-spacing: 0.2rem;
  font-size: 0.95rem;
  text-transform: uppercase;
}

.seed-preview-actions .ghost:hover {
  background: var(--fg);
  color: #000;
}

#seedSubmit {
  background: #fff !important;
  border: none;
  padding: 0.75rem 1rem;
  color: #000 !important;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.2rem;
  font-weight: 600;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#seedSubmit:active {
  transform: scale(0.98);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.ghost {
  border: 1px solid #fff;
  border-radius: 999px;
  padding: 0.4rem 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.3rem;
  font-size: 0.8rem;
  color: #fff !important;
  background: transparent;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.ghost.compact {
  width: 100%;
}

.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.heart {
  font-size: 1.2rem;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.heart.active {
  color: var(--accent);
  border-color: var(--accent);
}

#collection-modal {
  width: min(700px, calc(100vw - 2rem));
  border-radius: 1.5rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
}

#collection-modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

#collection-modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

#submit-modal {
  width: min(600px, calc(100vw - 2rem));
  border-radius: 1.5rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: inherit;
}

#submit-modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

#submit-modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.submit-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.submit-form input[type="text"] {
  font-family: var(--font-serif);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--glass);
  color: var(--fg);
}

.submit-form input[type="text"]::placeholder {
  color: var(--muted);
}

.submit-form button {
  margin-top: 0.5rem;
}

.submit-status {
  font-size: 0.9rem;
  text-align: center;
  color: var(--accent);
  min-height: 1.5rem;
}


.collection-content {
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.collection-item {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--glass);
}

.collection-item .lines p {
  font-size: 1rem;
  line-height: 1.6;
}

.collection-item .hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.collection-item .remove {
  align-self: flex-end;
  font-size: 0.75rem;
}

@media (max-width: 1100px) {
  .black-garden {
    grid-template-columns: 1fr;
  }
  .control-panel {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .control-panel .switch,
  .control-panel .range {
    width: calc(50% - 0.5rem);
  }
  .ghost.compact {
    width: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 1.5rem;
  }
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .control-panel {
    flex-direction: column;
    gap: 0.5rem;
  }
  .control-panel .switch,
  .control-panel .range {
    width: 100%;
  }
}
