:root {
  --ink: #1c2430;
  --ink-soft: #4a5565;
  --paper: #f3f6f4;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(28, 36, 48, 0.1);
  --accent: #0f7a6c;
  --accent-deep: #0a5249;
  --bot-bg: #e8f3ef;
  --user-bg: #1c2430;
  --user-fg: #f6f8f7;
  --shadow: 0 18px 50px rgba(28, 36, 48, 0.1);
  --radius: 18px;
  --font-display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --font-body: "Manrope", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--paper);
  overflow: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 55% at 12% -10%, #b7e0d4 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 0%, #d9e4c8 0%, transparent 50%),
    linear-gradient(165deg, #eef4f1 0%, #f7f4ee 48%, #e8eef2 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  padding: 1.25rem 1rem 1rem;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 0.35rem 1rem;
  animation: rise 0.55s ease both;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 4.5vw, 2.45rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--accent-deep);
}

.tagline {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.status {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.cs-picker {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.cs-picker select {
  min-width: 9.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.65rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-deep);
  background: rgba(255, 255, 255, 0.85);
  outline: none;
}

.cs-picker select:focus {
  border-color: rgba(15, 122, 108, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 122, 108, 0.12);
}

.nav {
  display: flex;
  gap: 0.35rem;
}

.nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.nav a:hover {
  color: var(--accent-deep);
  background: rgba(255, 255, 255, 0.55);
}

.nav a[aria-current="page"] {
  color: var(--accent-deep);
  background: rgba(255, 255, 255, 0.75);
  border-color: var(--line);
}

.chat-shell {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overflow: hidden;
  animation: rise 0.7s ease 0.08s both;
}

.messages {
  overflow-y: auto;
  padding: 1.25rem 1.1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.msg {
  max-width: min(92%, 560px);
  animation: pop 0.32s ease both;
}

.msg.bot {
  align-self: flex-start;
}

.msg.user {
  align-self: flex-end;
}

.bubble {
  padding: 0.85rem 1rem;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.bot .bubble {
  background: var(--bot-bg);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.msg.user .bubble {
  background: var(--user-bg);
  color: var(--user-fg);
  border-bottom-right-radius: 6px;
}

.meta {
  margin: 0.45rem 0 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.sources {
  margin: 0.55rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sources li {
  font-size: 0.75rem;
  color: var(--ink-soft);
  border-left: 2px solid var(--accent);
  padding-left: 0.55rem;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
  padding: 0.85rem 0.9rem 0.95rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.composer textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  background: #fff;
  color: var(--ink);
  max-height: 140px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer textarea:focus {
  border-color: rgba(15, 122, 108, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 122, 108, 0.12);
}

.composer button {
  border: 0;
  border-radius: 14px;
  padding: 0.85rem 1.15rem;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

.composer button:hover:not(:disabled) {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.composer button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.typing {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  min-height: 1.2em;
}

.typing span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.45;
  animation: bounce 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.suggestions button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.suggestions button:hover {
  background: var(--bot-bg);
  color: var(--accent-deep);
  border-color: rgba(15, 122, 108, 0.3);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

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

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

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 0.9;
  }
}

/* Learn page */
body.page-learn {
  overflow: auto;
}

.learn-app {
  max-width: 1080px;
  height: auto;
  min-height: 100dvh;
}

.learn-shell {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 0.9rem;
  min-height: 0;
  padding-bottom: 1rem;
  animation: rise 0.7s ease 0.08s both;
}

.learn-panel,
.docs-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 1.15rem 1.2rem 1.25rem;
}

.panel-head h1,
.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent-deep);
}

.panel-head h1 {
  font-size: clamp(1.5rem, 3vw, 1.9rem);
}

.panel-head h2 {
  font-size: 1.25rem;
}

.panel-head p {
  margin: 0.4rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.upload-zone,
.text-form {
  margin-top: 1.1rem;
}

.drop-target {
  width: 100%;
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  padding: 1.7rem 1rem;
  border: 1.5px dashed rgba(15, 122, 108, 0.35);
  border-radius: 16px;
  background: rgba(232, 243, 239, 0.55);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}

.drop-target strong {
  font-size: 1rem;
  color: var(--accent-deep);
}

.drop-target span {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.drop-target:hover,
.drop-target.dragover {
  border-color: var(--accent);
  background: rgba(232, 243, 239, 0.95);
  transform: translateY(-1px);
}

.hint {
  margin: 0.55rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.text-form {
  display: grid;
  gap: 0.45rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.text-form label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 0.35rem;
}

.text-form input,
.text-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.text-form input:focus,
.text-form textarea:focus {
  border-color: rgba(15, 122, 108, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 122, 108, 0.12);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.primary,
.ghost,
.doc-item button {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover:not(:disabled) {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.ghost {
  background: transparent;
  color: var(--accent-deep);
  border: 1px solid var(--line);
}

.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.7);
}

.primary:disabled,
.ghost:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.toast {
  margin: 0.9rem 0 0;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: var(--bot-bg);
  color: var(--accent-deep);
  font-size: 0.85rem;
  animation: pop 0.28s ease both;
}

.toast.error {
  background: #fdecea;
  color: #8a2b22;
}

.doc-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 62dvh;
  overflow: auto;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  animation: pop 0.28s ease both;
}

.doc-item strong {
  display: block;
  font-size: 0.9rem;
}

.doc-item span {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.doc-item button {
  background: transparent;
  color: #8a2b22;
  border: 1px solid rgba(138, 43, 34, 0.2);
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
}

.doc-item button:hover {
  background: #fdecea;
}

.doc-empty {
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

@media (max-width: 900px) {
  .learn-shell {
    grid-template-columns: 1fr;
  }

  .doc-list {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 0.85rem 0.65rem 0.65rem;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-right {
    align-items: flex-start;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer button {
    width: 100%;
  }

  .actions {
    flex-direction: column;
  }

  .actions .primary,
  .actions .ghost {
    width: 100%;
  }
}
