:root {
  color-scheme: light;
  --ink: #202735;
  --muted: #717b8c;
  --line: #e1e5ed;
  --surface: #ffffff;
  --surface-soft: #f4f6fb;
  --accent: #5b57d8;
  --accent-dark: #4e49c4;
  --narration: #eceef7;
  --danger: #b93f56;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--surface-soft); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% -10%, #ffffff 0, #ffffff00 38%),
    var(--surface-soft);
  color: var(--ink);
}

button, input, textarea { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { border: 0; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 16px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 14px 0 12px;
  background: linear-gradient(var(--surface-soft) 74%, #f4f6fb00);
}

.topbar h1, .conversation-heading h2, .sheet h2, .intro-card h2 {
  margin: 0;
  font-weight: 750;
  letter-spacing: -.03em;
}

.topbar h1 { font-size: 22px; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; }

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: #ffffffaa;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.intro-card {
  margin-top: 34px;
  padding: 30px 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 12px 36px #424c7310;
  text-align: center;
}

.intro-icon {
  display: grid;
  width: 62px;
  height: 62px;
  margin: 0 auto 16px;
  place-items: center;
  border-radius: 20px;
  background: #efedff;
  color: var(--accent);
  font-size: 30px;
}

.intro-card h2 { font-size: 20px; }
.intro-card p { max-width: 420px; margin: 10px auto 22px; color: var(--muted); font-size: 14px; line-height: 1.7; }

.intro-actions, .sheet-actions { display: flex; gap: 9px; align-items: center; }
.intro-actions { justify-content: center; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  border-radius: 13px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
}

.button:active { transform: scale(.97); }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: #eef0f7; color: var(--ink); }
.button.danger { background: #fff0f2; color: var(--danger); }
.button:disabled { cursor: wait; opacity: .5; }

.conversation { padding-top: 18px; }
.conversation-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 0 3px 14px; }
.conversation-heading h2 { font-size: 17px; }
.count { color: var(--muted); font-size: 12px; font-weight: 700; }

.message-list { display: flex; flex-direction: column; gap: 11px; }

.message-card {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.message-card-inner {
  display: block;
  width: fit-content;
  max-width: min(94%, 640px);
  padding: 13px 15px 14px;
  border: 1px solid var(--line);
  border-radius: 17px 17px 17px 5px;
  background: var(--surface);
  box-shadow: 0 4px 16px #424c730b;
  transition: border-color .15s ease, transform .15s ease;
}

.message-card:active .message-card-inner { transform: scale(.99); }
.message-card:hover .message-card-inner { border-color: #b8b9e7; }
.message-card.narrator { display: flex; justify-content: center; }
.message-card.narrator .message-card-inner { max-width: 96%; border-color: transparent; border-radius: 12px; background: var(--narration); box-shadow: none; color: #50586d; }
.speaker-label { display: block; margin-bottom: 5px; color: var(--accent-dark); font-size: 12px; font-weight: 800; }
.narrator .speaker-label { color: #7f8797; }
.message-body { display: block; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.75; }

.add-inline {
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  border: 1px dashed #b9bfd0;
  border-radius: 15px;
  background: #ffffff88;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.bottom-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #dfe3ec;
  background: #ffffffdd;
  backdrop-filter: blur(16px);
}

.bottom-bar .button { flex: 1; min-width: 0; padding-right: 7px; padding-left: 7px; font-size: 12px; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #1b20304d;
  backdrop-filter: blur(2px);
}

.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 11;
  width: min(100%, 760px);
  max-height: min(90vh, 720px);
  margin: 0 auto;
  padding: 9px 18px calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: 0 -12px 35px #242a451c;
}

.sheet-handle { width: 42px; height: 4px; margin: 0 auto 15px; border-radius: 99px; background: #cdd2de; }
.sheet-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 17px; }
.sheet h2 { font-size: 19px; }
.sheet .icon-button { margin-top: -6px; background: var(--surface-soft); }
.field-label { display: block; margin: 13px 0 6px; color: var(--muted); font-size: 12px; font-weight: 750; }
.text-input, .large-textarea { width: 100%; border: 1px solid #d3d8e4; border-radius: 13px; outline: 0; background: #fbfcff; color: var(--ink); }
.text-input { min-height: 46px; padding: 10px 12px; }
.large-textarea { min-height: 160px; padding: 12px; resize: vertical; font-size: 14px; line-height: 1.65; }
.message-editor { min-height: 220px; }
.text-input:focus, .large-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #5b57d81c; }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--danger); font-size: 12px; }
.sheet-actions { margin-top: 13px; }
.edit-actions .button { min-width: 44px; }
.action-spacer { flex: 1; }

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 20;
  max-width: 520px;
  margin: 0 auto;
  padding: 11px 14px;
  border-radius: 12px;
  background: #242a38eF;
  color: white;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }
[hidden] { display: none !important; }

@media (min-width: 600px) {
  .app-shell { padding-right: 24px; padding-left: 24px; }
  .topbar { min-height: 88px; }
  .intro-card { margin-top: 70px; padding: 44px 28px; }
  .bottom-bar { right: auto; left: 50%; width: min(100%, 760px); transform: translateX(-50%); border-right: 1px solid #dfe3ec; border-left: 1px solid #dfe3ec; border-radius: 18px 18px 0 0; }
}
