:root {
  --ink: #222;
  --ink-2: #333;
  --muted: #666;
  --line: #eee;
  --bg: #f3f3f3;
  --card: #fff;
  --accent: #222;
  --font: "Avenir Next", "Avenir Next W01", "Avenir", helvetica, arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(#fff 0%, #f3f3f3 100%);
  color: var(--ink);
  font: 500 16px/1.4 var(--font);
}

.shell { width: min(1200px, 92vw); margin: 0 auto; }
.site-header { border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.9); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 30; }
.header-row { display: flex; align-items: center; justify-content: space-between; min-height: 58px; }
.brand { color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: 0.2px; }
.nav { display: flex; gap: 14px; align-items: center; }
.nav a, .linkish { color: var(--ink-2); text-decoration: none; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.page { padding: 18px 0 28px; }

.flash { margin: 0 0 14px; border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); background: #fff; }
.flash.alert { border-color: #d8b4b4; background: #fff5f5; }
.flash.notice { border-color: #bfd8bf; background: #f4fff4; }

h1, h2, h3, h4, p { margin: 0 0 10px; }

.btn {
  cursor: pointer;
  border: 0;
  border-radius: 5rem;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 10px 16px;
  font: 700 15px/1 var(--font);
  transition: background-color .3s ease;
}

.btn:hover { background: #333; text-decoration: none; }
.btn.secondary { background: #525252; }
.btn.secondary.google-auth-btn {
  width: 100%;
  min-height: 48px;
  background: #f2f4f7;
  color: #1f2328;
  border: 1px solid #d8dee4;
  font-size: 16px;
}
.btn.secondary.google-auth-btn:hover { background: #e9edf2; }

input, textarea, select {
  width: 100%;
  border: 4px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: 600 14px/1.4 var(--font);
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--ink); }

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: 1.1fr 1fr;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.conversation-list { display: grid; gap: 10px; }
.conversation-item {
  --row-accent: #1f6feb;
  display: block;
  color: #fff;
  text-decoration: none;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--row-accent);
  box-shadow: none;
}
.conversation-item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.conversation-item * { color: inherit; }
.conversation-item strong { display: block; margin-bottom: 3px; }
.conversation-item small { color: rgba(255, 255, 255, 0.96); }

.learning-records-toggle { margin-top: 12px; }
.learning-records-summary {
  cursor: pointer;
  display: block;
  width: 100%;
  text-align: center;
  list-style: none;
  border: 1px solid #d6d6d6;
  border-radius: 5rem;
  background: #fff;
  color: #222;
  font: 700 15px/1 var(--font);
  padding: 10px 16px;
  box-shadow: none;
  text-decoration: none;
}
.learning-records-summary::-webkit-details-marker { display: none; }
.learning-records-summary:hover { background: #fafafa; }
.learning-records-toggle[open] .learning-records-summary { margin-bottom: 10px; }
.learning-records-list { display: grid; gap: 10px; }
.learning-record-item {
  display: block;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}
.learning-record-item strong { display: block; margin-bottom: 4px; font-weight: 800; color: #222; }
.learning-record-item small { display: block; color: #4e4e4e; margin-bottom: 4px; }
.learning-record-item:hover { border-color: #d7d7d7; }

.chat-layout { display: grid; gap: 12px; align-items: start; }
.chat-header {
  padding: 12px 14px;
  background: var(--conversation-accent, #1f6feb);
  border: 0;
  color: #fff;
}
.chat-header h3 { margin: 0 0 4px; }
.chat-header .meta-muted { color: rgba(255, 255, 255, 0.95); }
.chat-header-actions { margin-top: 8px; }
.chat-header-actions form { margin: 0; }
.chat-header .btn.btn-danger {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  padding: 8px 12px;
  font-size: 13px;
}
.chat-header .btn.btn-danger:hover { background: rgba(0, 0, 0, 0.34); }
.feedback-form-wrap { margin-top: 10px; }
.feedback-form {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  align-items: end;
}
.feedback-form textarea {
  margin: 0;
  min-height: 44px;
  max-height: 120px;
  resize: vertical;
}
.feedback-form .btn {
  height: 44px;
  padding: 0 14px;
  align-self: end;
}
.chat-header .feedback-form textarea {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.65);
  color: #222;
}
.chat-header .feedback-form .btn {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
}
.chat-header .feedback-form .btn:hover { background: rgba(0, 0, 0, 0.34); }
.feedback-list { margin-top: 12px; display: grid; gap: 10px; }
.feedback-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}
.feedback-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: #555;
  margin-bottom: 6px;
}
.feedback-item p { margin: 0; }

.chat-card {
  padding: 0;
  min-height: 60vh;
}

.messages {
  overflow: visible;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 0;
}
.chat-card.has-composer .messages { padding-bottom: 116px; }
.chat-card.has-viewer-cta .messages { padding-bottom: 86px; }

.bubble {
  max-width: 88%;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 16px;
  overflow: hidden;
}

.bubble.user {
  justify-self: end;
  background: var(--conversation-accent, #222);
  border-color: var(--conversation-accent, #222);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 12px 14px;
  font-weight: 600;
  white-space: pre-wrap;
}

.assistant-meta {
  font-size: 12px;
  color: #666;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
  background: #fff;
}

.assistant-frame {
  width: 100%;
  border: 0;
  display: block;
  min-height: 90px;
  background: #fff;
}

.assistant-content {
  --assistant-accent: var(--conversation-accent, #222);
  padding: 10px;
  font: 600 15px/1.45 var(--font);
  color: #222;
  background: #fff;
}
.assistant-content h3, .assistant-content h4 { margin: 0 0 8px; font-weight: 800; line-height: 1.2; }
.assistant-content h3 { font-size: 20px; }
.assistant-content h4 { font-size: 16px; }
.assistant-content p { margin: 5px 0 3px; }
.assistant-content ul, .assistant-content ol { margin: 0 0 8px 18px; padding: 0; }
.assistant-content section { margin-bottom: 8px; }
.assistant-content form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #eee;
  border-radius: 10px;
  background: #fff;
}
.assistant-content label { display: block; font-size: 13px; font-weight: 700; margin: 0 0 4px; }
.assistant-content form ul, .assistant-content form ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.assistant-content form li { margin: 0; padding: 8px 10px; border: 1px solid #eee; border-radius: 8px; background: #fff; }
.assistant-content form li label {
  display: block;
  position: relative;
  margin: 0;
  padding-left: 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.assistant-content input, .assistant-content textarea, .assistant-content select {
  width: 100%;
  border: 3px solid #eee;
  border-radius: 8px;
  padding: 8px 10px;
  font: 600 14px/1.35 var(--font);
  outline: none;
  background: #fff;
  color: #222;
}
.assistant-content input[type="radio"], .assistant-content input[type="checkbox"] { width: auto; padding: 0; margin: 0; accent-color: var(--assistant-accent); }
.assistant-content form li label > input[type="radio"],
.assistant-content form li label > input[type="checkbox"] {
  position: absolute;
  left: 0;
  top: 0.18em;
}
.assistant-content form li label code {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.assistant-content input:focus, .assistant-content textarea:focus, .assistant-content select:focus { border-color: #222; }
.assistant-content button {
  border: 0;
  border-radius: 999px;
  background: var(--assistant-accent);
  color: #fff;
  padding: 8px 14px;
  font: 700 14px/1 var(--font);
  cursor: pointer;
  justify-self: start;
}
.assistant-content button:hover { filter: brightness(0.95); }
.assistant-content code {
  font: 400 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f1f5fb;
  border: 1px solid #dbe4f0;
  border-radius: 6px;
  padding: 1px 5px;
  color: #1d2530;
}
.assistant-content pre { margin: 6px 0 8px; padding: 10px 12px; background: #f8fbff; border: 1px solid #dbe4f0; border-radius: 8px; overflow: auto; }
.assistant-content pre code {
  display: block;
  background: transparent;
  border: none;
  padding: 0;
  font: 400 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.assistant-content .katex { font-size: 1.02em; }
.assistant-content .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; }
.assistant-content [data-role="feedback"] { padding: 10px; border: 1px solid #eee; border-radius: 10px; background: #f5f5f5; }
.assistant-content details[data-role="deep-dive"] { margin: 8px 0; padding: 8px 10px; border: 1px solid #e6e6e6; border-radius: 10px; background: #fafafa; }
.assistant-content details[data-role="deep-dive"] > summary { cursor: pointer; font-size: 13px; font-weight: 800; color: #444; list-style: none; }
.assistant-content details[data-role="deep-dive"] > summary::-webkit-details-marker { display: none; }
.assistant-content details[data-role="deep-dive"] > *:not(summary) { margin-top: 8px; }

.bubble.assistant-thinking {
  border-radius: 16px 16px 16px 4px;
}

.assistant-thinking-wrap {
  display: grid;
  grid-template-columns: 68px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #fff;
}

.assistant-thinking-svg {
  width: 58px;
  height: 58px;
  display: block;
}

.assistant-thinking-core {
  fill: var(--thinking-accent, #1f6feb);
  opacity: 0.18;
}

.assistant-thinking-ring {
  fill: none;
  stroke: var(--thinking-accent, #1f6feb);
  stroke-width: 2;
  opacity: 0.28;
}

.assistant-thinking-wave {
  fill: none;
  stroke: var(--thinking-accent, #1f6feb);
  stroke-linecap: round;
}

.assistant-thinking-wave.wave-a { stroke-width: 2.2; opacity: 0.7; }
.assistant-thinking-wave.wave-b { stroke-width: 1.6; opacity: 0.45; }
.assistant-thinking-wave.wave-c { stroke-width: 1.2; opacity: 0.3; }

.assistant-thinking-dot {
  fill: var(--thinking-accent, #1f6feb);
  opacity: 0.9;
}

.assistant-thinking-copy {
  display: grid;
  gap: 2px;
}

.assistant-thinking-title {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  color: #222;
}

.assistant-thinking-sub {
  font-size: 12px;
  color: #666;
  line-height: 1.2;
}

.composer {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(1200px, 92vw);
  z-index: 40;
  border: 1px solid #ddd;
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
  padding: 12px;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(6px);
}

.composer textarea {
  min-height: 52px;
  max-height: 140px;
  resize: vertical;
  font-size: 15px;
  border: 4px solid #eee;
  border-radius: 8px;
}

.composer textarea:focus { border-color: #222; }
.chat-layout .composer .btn { background: var(--conversation-accent, #222); }
.chat-layout .composer .btn:hover { filter: brightness(0.95); }

.new-conversation-cta {
  position: fixed;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 8px));
  transform: translateX(-50%);
  width: min(1200px, 92vw);
  z-index: 40;
}
.new-conversation-cta .btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  font-size: 17px;
  text-decoration: none;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}
.workspace-new-btn { box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18); }

.meta-muted { color: var(--muted); font-size: 13px; }

.memory-sync-toast {
  position: fixed;
  left: 50%;
  top: 68px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 24px));
  z-index: 46;
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #ffffff;
  color: #222;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  border: 1px solid #e7e7e7;
}
.memory-sync-toast[hidden] { display: none; }
.memory-sync-text { font: 700 14px/1.2 var(--font); }
.memory-sync-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #d9d9d9;
  border-top-color: var(--conversation-accent, #222);
  border-radius: 50%;
  animation: memory-sync-spin 1s linear infinite;
}
.memory-sync-toast.done .memory-sync-spinner {
  animation: none;
  border-color: #41a46d;
  border-top-color: #41a46d;
}

@keyframes memory-sync-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.raw-inspector { border-top: 1px solid var(--line); padding-top: 10px; }
.raw-toggle > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  list-style: none;
}
.raw-toggle > summary::-webkit-details-marker { display: none; }
.raw-toggle[open] > summary { margin-bottom: 8px; }
.raw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.raw-panel { border: 1px solid #e6ebf2; border-radius: 10px; overflow: hidden; background: #fbfcff; min-height: 180px; }
.raw-title { padding: 6px 8px; font-size: 12px; font-weight: 700; color: #42526a; border-bottom: 1px solid #e6ebf2; background: #f3f7fd; }
.raw-text { margin: 0; padding: 8px; max-height: 220px; overflow: auto; white-space: pre-wrap; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: #1d2530; background: #fbfcff; }
.raw-preview { width: 100%; min-height: 220px; border: 0; background: #fff; }

@media (max-width: 960px) {
  .grid.two { grid-template-columns: 1fr; }
  .composer {
    width: calc(100vw - 16px);
    bottom: 8px;
  }
  .new-conversation-cta .btn { font-size: 16px; }
  .raw-grid { grid-template-columns: 1fr; }
  .memory-sync-toast { top: 62px; }
}

@media (max-width: 768px) {
  input, textarea, select { font-size: 16px; }
  .assistant-content input, .assistant-content textarea, .assistant-content select {
    font-size: 16px;
    line-height: 1.35;
  }
  .composer textarea { font-size: 16px; }
  .composer .btn {
    width: 52px;
    min-width: 52px;
    height: 52px;
    min-height: 52px;
    padding: 0;
    border-radius: 50%;
    justify-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }
  .composer {
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    width: 100%;
    z-index: auto;
    margin-top: 12px;
    display: grid;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  }
  .chat-card.has-composer .messages { padding-bottom: 0; }
  .feedback-form {
    grid-template-columns: 1fr;
  }
  .feedback-form .btn {
    width: 100%;
    height: auto;
    padding: 10px 14px;
  }
}
