:root {
  --bg: #ffffff;
  --hero-bg: #fce3d0;
  --hero-bg-deep: #fbd8be;
  --paper: #ffffff;
  --paper-tint: #fbf6ee;
  --line: #ecdfd0;
  --line-soft: #f3e9db;
  --text: #2d2722;
  --text-soft: #4a4039;
  --muted: #857a6d;
  --subtle: #b5a99a;
  --accent: #3a2e26;
  --accent-soft: #fbeadb;
  --accent-deep: #2d2722;
  --button: #2d2722;
  --button-hover: #1a1612;
  --button-soft: #f4ece2;
  --shadow-card: 0 1px 2px rgba(45, 39, 34, 0.04), 0 16px 36px rgba(45, 39, 34, 0.07);
  --shadow-soft: 0 1px 2px rgba(45, 39, 34, 0.03), 0 8px 20px rgba(45, 39, 34, 0.05);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-sans: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-serif: "Cormorant Garamond", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}

* { box-sizing: border-box; }

/* hidden属性をdisplay:grid等より優先させる（重要） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
}

body {
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0.01em;
  line-height: 1.7;
}

a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }

.page { width: 100%; min-height: 100vh; }
.page-shell { width: 100%; margin: 0 auto; padding-bottom: 64px; }

/* HERO */
.hero {
  position: relative;
  background: linear-gradient(180deg, var(--hero-bg) 0%, var(--hero-bg-deep) 100%);
  padding: 24px 24px 56px;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  left: -10%; right: -10%; bottom: -1px;
  height: 56px;
  background: var(--bg);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}
.hero-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; position: relative; z-index: 1;
}
.brand {
  font-family: var(--font-serif);
  font-size: 1.55rem; font-weight: 500;
  letter-spacing: 0.04em; color: var(--text);
  font-style: italic;
}
.hero-inner {
  max-width: 560px; margin: 32px auto 0;
  text-align: center; position: relative; z-index: 1;
}
.hero-lead {
  margin: 0 0 14px;
  font-size: 0.95rem; color: var(--text-soft);
  letter-spacing: 0.04em; font-weight: 500;
}
.hero-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  line-height: 1.4; font-weight: 500;
  letter-spacing: 0.02em; color: var(--text);
}
.hero-title em { font-style: italic; }
.hero-symbol {
  display: block;
  width: clamp(220px, 60vw, 280px);
  height: auto;
  margin: 28px auto 0;
}
.hero-symbol svg { width: 100%; height: auto; }

/* SECTION */
.section {
  max-width: 560px; margin: 0 auto;
  padding: 56px 24px 0;
}
.section-eyebrow {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-align: center;
}
.section-title {
  margin: 0 0 32px;
  font-family: var(--font-serif);
  font-size: clamp(1.55rem, 4.5vw, 1.85rem);
  font-weight: 500; line-height: 1.55;
  letter-spacing: 0.02em; color: var(--text);
  text-align: center;
}
.hero-summary-center {
  max-width: 30rem; margin: 0 auto;
  color: var(--text-soft);
  font-size: 0.95rem; line-height: 2.0;
  text-align: center;
}

/* AUTH */
.auth-section {
  max-width: 560px; margin: 56px auto 0;
  padding: 0 24px;
}
.card {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px 26px;
}
.auth-card .section-title { margin-bottom: 12px; }
.card-lead {
  margin: 0 0 24px;
  color: var(--text-soft);
  font-size: 0.93rem; line-height: 1.95;
  text-align: center;
}
.stack-form { display: grid; gap: 18px; }
.field { display: grid; gap: 8px; }
.field span {
  font-size: 0.9rem; font-weight: 600;
  color: var(--text); letter-spacing: 0.02em;
}
.field input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(45, 39, 34, 0.08);
}

/* BUTTONS */
.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px 22px;
  border-radius: 999px;
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 200ms ease;
}
.primary-button {
  border: 0;
  background: var(--button);
  color: #fff;
}
.ghost-button {
  border: 0;
  background: var(--button-soft);
  color: var(--text);
}
.primary-button:hover { background: var(--button-hover); }
.ghost-button:hover { background: var(--accent-soft); }
.primary-button:disabled,
.ghost-button:disabled { opacity: 0.5; cursor: default; }

/* PROMISE */
.promise {
  max-width: 560px;
  margin: 40px auto 0;
  padding: 0 24px;
  text-align: center;
}
.promise-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.95;
}

/* MESSAGES */
.message { margin: 0; line-height: 1.85; font-size: 0.92rem; }
.message.error {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: #fbeee9;
  color: #7a3e30;
  border: 1px solid #f0d3c8;
}

/* LOGGED-IN */
.loggedin-shell {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

/* COMPACT HERO（ログイン後の小さなバー） */
.compact-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px 20px;
  margin: 0 -16px 20px;
  background: linear-gradient(180deg, var(--hero-bg) 0%, var(--hero-bg-deep) 100%);
}
.compact-hero-symbol {
  width: 48px; height: 40px;
  flex-shrink: 0;
}
.compact-hero-symbol svg { width: 100%; height: 100%; display: block; }
.compact-hero-text {
  display: flex;
  align-items: baseline;
}
.compact-hero-lead { display: none; }
.compact-hero-title {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.55rem;
  line-height: 1;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.04em;
}
.compact-hero-title em { font-style: italic; }
.chat-card { padding: 22px 18px; }
.chat-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.chat-topbar-minimal { justify-content: center; }
.chat-topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.88rem; color: var(--text-soft);
}
.chat-topbar-dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: #5ea974;
}

/* CHAT */
.chat { display: grid; gap: 16px; }
.chat-usage {
  display: inline-flex; align-items: center; gap: 6px;
  align-self: center;
  padding: 6px 14px;
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text-soft);
}
.chat-usage strong {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--accent-deep);
}

.chat-stream {
  position: relative;
  display: grid; gap: 14px;
  padding: 8px 0;
  max-height: 60vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.bubble-row { display: flex; gap: 10px; align-items: flex-end; }
.bubble-row-ai { justify-content: flex-start; }
.bubble-row-user { justify-content: flex-end; }
.bubble-avatar {
  flex-shrink: 0;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  overflow: hidden;
}
.bubble-avatar svg { width: 100%; height: 100%; display: block; }
.bubble {
  max-width: 78%;
  padding: 13px 18px;
  font-size: 0.95rem; line-height: 1.85;
  border-radius: 20px;
  white-space: pre-wrap; word-break: break-word;
}
.bubble-ai {
  background: var(--paper-tint);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 6px;
}
.bubble-user {
  background: var(--accent-deep);
  color: #fdf9f3;
  border-bottom-right-radius: 6px;
}
.bubble-typing {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 16px 18px;
}
.bubble-typing span {
  width: 6px; height: 6px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.5;
  animation: typing 1.2s infinite ease-in-out;
}
.bubble-typing span:nth-child(2) { animation-delay: 0.15s; }
.bubble-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
  40% { transform: translateY(-3px); opacity: 1; }
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble-row-appear { animation: bubble-in 280ms ease-out both; }

/* CHAT INPUT */
.chat-input {
  display: grid; gap: 10px;
  padding: 14px;
  background: var(--paper-tint);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
}
.chat-input textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 0.95rem; line-height: 1.8;
  resize: vertical;
  font-family: inherit;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(45, 39, 34, 0.08);
}

/* LETTER */
.letter {
  display: grid; gap: 18px;
  padding: 30px 24px 26px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fffaf4 0%, #fdf3ea 100%);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-soft);
  animation: bubble-in 420ms ease-out both;
}
.letter-head {
  display: flex; flex-direction: column;
  align-items: center; gap: 10px;
  text-align: center;
}
.letter-avatar { width: 52px; height: 52px; }
.letter-avatar svg { width: 100%; height: 100%; display: block; }
.letter-from {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  color: var(--accent-deep);
}
.letter-comfort, .letter-text, .letter-reframe {
  margin: 0; line-height: 2.05;
  font-size: 0.96rem; color: var(--text-soft);
}
.letter-comfort {
  font-size: 1.0rem; color: var(--text); font-weight: 500;
}
.letter-reframe {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--line-soft);
  color: var(--text);
}
.letter-step {
  display: grid; gap: 6px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: #fff;
  border: 1px dashed var(--line);
}
.letter-step-label {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--accent);
  letter-spacing: 0.06em;
}
.letter-step-text {
  margin: 0; line-height: 1.95;
  font-size: 0.94rem; color: var(--text);
}
.letter-summary {
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--font-serif);
  font-size: 1.02rem; line-height: 2.0;
  color: var(--accent-deep);
  text-align: center;
}
.letter-look-back {
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}
.letter-look-back summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  list-style: none;
}
.letter-look-back summary::-webkit-details-marker { display: none; }
.letter-look-back summary::before { content: "＋ "; color: var(--subtle); }
.letter-look-back[open] summary::before { content: "− "; }
.letter-history { display: grid; gap: 8px; margin-top: 12px; }
.letter-history-line {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--paper-tint);
  font-size: 0.9rem; line-height: 1.85;
  color: var(--text-soft);
}
.chat-done-actions { display: grid; gap: 10px; margin-top: 6px; }
.chat-done-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.8rem; line-height: 1.85;
  text-align: center;
}

/* SCENE LIST */
.scene-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 14px;
}
.scene-card {
  display: flex; gap: 16px;
  padding: 22px 22px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}
.scene-icon {
  flex-shrink: 0;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 1.3rem;
}
.scene-body { display: grid; gap: 6px; }
.scene-tag {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--accent-deep);
  letter-spacing: 0.03em;
}
.scene-text {
  margin: 0;
  line-height: 1.95;
  font-size: 0.92rem;
  color: var(--text-soft);
}

/* STEP LIST */
.step-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 14px;
}
.step-item {
  display: flex; gap: 16px;
  padding: 22px 22px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}
.step-num {
  flex-shrink: 0;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-deep);
  color: #fff;
  border-radius: 999px;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 500;
}
.step-body { display: grid; gap: 6px; }
.step-title {
  margin: 0;
  font-weight: 600;
  font-size: 0.96rem;
  color: var(--text);
}
.step-desc {
  margin: 0;
  line-height: 1.95;
  font-size: 0.9rem;
  color: var(--text-soft);
}

/* HISTORY */
.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 32px 0;
  font-size: 0.93rem;
}
.history-actions {
  display: flex; justify-content: flex-end;
  margin-bottom: 16px;
}
.history-stack { display: grid; gap: 16px; }
.history-card {
  display: grid; gap: 18px;
  padding: 24px 22px;
  border-radius: var(--radius-lg);
  background: var(--paper);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-soft);
}
.history-date {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: 0.04em;
}
.history-group { display: grid; gap: 8px; }
.history-group h2 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent-deep);
  letter-spacing: 0.04em;
}
.history-group p {
  margin: 0;
  line-height: 1.95;
  font-size: 0.94rem;
  color: var(--text-soft);
}
.history-messages { display: grid; gap: 6px; }
.history-msg {
  margin: 0;
  line-height: 1.85;
  font-size: 0.93rem;
  color: var(--text-soft);
}
.history-role {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent-deep);
  background: var(--accent-soft);
  border-radius: 999px;
  vertical-align: middle;
}

/* FOOTER */
.site-footer {
  max-width: 620px; margin: 0 auto;
  padding: 24px 24px 56px;
  text-align: center;
}
.site-footer-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.site-footer-link {
  padding: 10px 18px;
  border: 0; background: transparent;
  color: var(--muted);
  font-size: 0.88rem; font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-radius: 999px;
  font-family: inherit;
  transition: background 200ms ease, color 200ms ease;
}
.site-footer-link:hover {
  background: var(--accent-soft);
  color: var(--text);
}
.site-footer-logout { color: var(--accent-deep); }
.site-footer-brand {
  margin: 0;
  display: inline-flex; align-items: baseline; gap: 10px;
  color: var(--subtle);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}
.site-footer-tag { font-size: 0.78rem; }

/* RESPONSIVE */
@media (max-width: 480px) {
  .hero { padding: 20px 20px 48px; }
  .brand { font-size: 1.4rem; }
  .section { padding: 44px 20px 0; }
  .auth-section { padding: 0 20px; }
  .loggedin-shell { padding: 16px 12px 48px; }
  .chat-card { padding: 18px 14px; }
  .letter { padding: 24px 18px; }
}
