:root {
  font-family: "Inter", "Segoe UI", "Noto Sans SC", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-synthesis: none;
  color: #252a25;
  background: #f8f7f3;
  --display-font: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
  --canvas: #f8f7f3;
  --surface: #fffefa;
  --ink: #252a25;
  --muted: #595f56;
  --line: #e2e1d8;
  --accent: #2d473b;
  --accent-hover: #1c3429;
  --sidebar: #192520;
  --sidebar-text: #f5f1e6;
  --sidebar-muted: #b5bdb1;
  --content-width: 48rem;
  --page-inset: clamp(1.05rem, 4vw, 3rem);
  --header-height: 4.25rem;
  --avatar-size: 2.375rem;
  --message-gap: .88rem;
  --assistant-inset: calc(var(--avatar-size) + var(--message-gap));
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible {
  outline: 2px solid #526c57;
  outline-offset: 3px;
}

[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 15.75rem minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.8rem 1.25rem 1.25rem;
  color: var(--sidebar-text);
  background: var(--sidebar);
  color-scheme: dark;
}

.sidebar button:focus-visible { outline-color: #d4c394; }
.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 0 .15rem 2.1rem;
}

.brand strong {
  display: block;
  color: var(--sidebar-text);
  font-family: var(--display-font);
  font-size: 1.32rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: .08em;
}

.brand div span {
  display: block;
  margin-top: .26rem;
  color: var(--sidebar-muted);
  font-size: .75rem;
  white-space: nowrap;
}

.orbit {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 2.55rem;
  height: 2.55rem;
  border: 1px solid #a69b735e;
  border-radius: 50%;
  color: #e2d1aa;
}

.orbit i {
  position: absolute;
  width: 55%;
  height: 25%;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.orbit i:nth-child(2) { transform: rotate(60deg); }
.orbit i:nth-child(3) { transform: rotate(-60deg); }
.orbit::after {
  content: "";
  width: 8%;
  height: 8%;
  border-radius: 50%;
  background: currentColor;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 2.75rem;
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid #e3e0d0;
  border-radius: .54rem;
  color: #24352c;
  background: #edeadf;
  font-size: .9rem;
  font-weight: 600;
  text-align: left;
}

.new-chat span { font-size: 1.2rem; line-height: 1; }
.new-chat:hover { background: #faf6e9; }
.history-section {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin-top: 2.25rem;
}

.history-section h2 {
  margin: 0 .55rem .6rem;
  color: var(--sidebar-muted);
  font-size: .85rem;
  font-weight: 500;
}

.history { overflow-y: auto; scrollbar-width: thin; }
.history button {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  padding: .62rem .55rem;
  margin-bottom: .15rem;
  border: 1px solid transparent;
  border-radius: .45rem;
  color: #e4e9e0;
  background: transparent;
  overflow: hidden;
  font-size: .9rem;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history button:hover, .history button[aria-current="true"] {
  background: #29382f;
  border-color: #405046;
  color: #fffaf0;
}

.history button:focus-visible { outline-offset: -3px; }
#no-history {
  margin: .1rem .55rem 0;
  color: var(--sidebar-muted);
  font-size: .8rem;
  line-height: 1.65;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .95rem .18rem .1rem;
  border-top: 1px solid #ffffff26;
  color: var(--sidebar-muted);
  font-size: .78rem;
}

.device-icon {
  position: relative;
  flex: none;
  width: .83rem;
  height: .55rem;
  border: 1px solid currentColor;
  border-radius: .1rem;
}

.device-icon::after {
  content: "";
  position: absolute;
  width: 55%;
  bottom: -.24rem;
  left: 22%;
  border-top: 1px solid currentColor;
}

.main {
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .9rem;
  padding-inline: var(--page-inset);
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: .72rem;
  font-size: .94rem;
  font-weight: 600;
}

.menu-button, .mobile-title { display: none; }
.engine {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .34rem .65rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: #46584c;
  background: #f0f2eb;
  font-size: .8rem;
  white-space: nowrap;
}

.engine-dot {
  width: .38rem;
  height: .38rem;
  border-radius: 50%;
  background: #557660;
}

.conversation, .composer-area {
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
}

.conversation { overflow-y: auto; overscroll-behavior: contain; }
.content-width {
  width: min(var(--content-width), calc(100% - 2 * var(--page-inset)));
  margin-inline: auto;
}

.main:has(.home:not([hidden])) .conversation { align-content: end; }
.home { padding-block: 1.15rem .95rem; }
.hero {
  position: relative;
  isolation: isolate;
  display: grid;
  align-items: center;
  min-height: clamp(12rem, 36dvh, 19rem);
  overflow: hidden;
  border: 1px solid #242b21;
  border-radius: .78rem;
  background: #151912;
  box-shadow: 0 12px 28px #282d2412;
}

.hero-text { position: relative; z-index: 1; padding: 1.8rem clamp(1.4rem, 5.4vw, 3.35rem); }
.hero-tag {
  width: fit-content;
  margin: 0;
  color: #f6efdc;
  font-family: var(--display-font);
  font-size: clamp(1.35rem, 2.5vw, 2.1rem);
  font-weight: 600;
  letter-spacing: .13em;
  line-height: 1.55;
}

.hero-tag span { display: block; }
.hero-tag::before {
  content: "";
  display: block;
  width: 1.65rem;
  margin-bottom: .85rem;
  border-top: 1px solid #d1b98a;
}

.hero-art {
  position: absolute;
  inset: 0;
  background: url('/socratic-study.png') right 32% / auto 135% no-repeat;
  mask-image: linear-gradient(90deg, transparent 8%, #000 47%);
}

.chat { padding-block: 2.2rem 1.4rem; }
.messages {
  display: grid;
  gap: 1.8rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: var(--message-gap);
  min-width: 0;
}

.message-bubble { min-width: 0; max-width: 100%; }
.message-assistant .message-bubble {
  max-width: min(39rem, calc(100% - var(--assistant-inset)));
  padding-top: .16rem;
}

.message-user { justify-content: flex-end; }
.message-user .message-bubble {
  max-width: 82%;
  padding: .74rem 1rem .8rem;
  border: 1px solid #dddfd3;
  border-radius: .85rem .85rem .28rem .85rem;
  background: #ebeee5;
}

.message-avatar {
  flex: none;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border: 1px solid #bbad8c;
  border-radius: 50%;
  background: #e5d5bd url('/socrates-avatar.png') center 7% / 138% auto no-repeat;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .52rem;
  margin-bottom: .4rem;
  color: #2e4337;
  font-size: .87rem;
  font-weight: 650;
}

.message-user .message-meta { color: var(--muted); font-size: .79rem; }
.message-mode {
  padding: .14rem .43rem;
  border-radius: .3rem;
  color: #465b4c;
  background: #ebeee5;
  font-size: .75rem;
  font-weight: 500;
}

.message-content {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.85;
}

.message-content .katex-display {
  max-width: 100%;
  margin: .65em 0;
  padding: .12em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.message-content .katex-display > .katex { text-align: left; }

.message-content code {
  padding: .12em .27em;
  border-radius: .25rem;
  color: #2c4636;
  background: #e9ede4;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: .92em;
}

.message-content + .message-photo { margin-top: .55rem; }
.message-photo a {
  display: block;
  width: fit-content;
  max-width: 100%;
  border-radius: .48rem;
}

.message-photo a:focus-visible { outline: 2px solid #526c57; outline-offset: 3px; }
.message-photo img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 27rem);
  max-height: min(44dvh, 24rem);
  border-radius: .48rem;
  background: var(--surface);
}

.message-photo-status {
  margin: 0;
  color: var(--muted);
  font-size: .81rem;
  line-height: 1.48;
}

.message-photo a + .message-photo-status { margin-top: .38rem; }
.response-status, .request-error, .actions { margin: .82rem 0 0 var(--assistant-inset); }
.response-status { color: var(--muted); font-size: .9rem; }
.response-status::before {
  content: "";
  display: inline-block;
  width: .43rem;
  height: .43rem;
  margin-right: .49rem;
  border-radius: 50%;
  background: #668575;
  vertical-align: .13em;
  animation: pulse 1.65s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: .36; } }

.request-error {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  color: #8d392c;
  font-size: .9rem;
}

.actions { display: flex; flex-wrap: wrap; gap: .45rem; }
.actions button, #retry {
  min-height: 2.75rem;
  padding: .38rem .75rem;
  border: 1px solid #dbded4;
  border-radius: 99px;
  color: #3b5043;
  background: var(--surface);
  font-size: .86rem;
}

.actions button:hover, #retry:hover { border-color: #a6b3a5; background: #edf1e9; }

.composer-area {
  overflow: hidden;
  padding-block: .52rem 1.15rem;
  background: var(--canvas);
}

.main:has(.home:not([hidden])) .composer-area {
  padding-bottom: clamp(1.15rem, 18dvh, 9rem);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding: .62rem;
  border: 1px solid #d7d9ce;
  border-radius: .79rem;
  background: var(--surface);
  box-shadow: 0 4px 17px #2128200b;
}

.composer:focus-within {
  border-color: #728b79;
  box-shadow: 0 0 0 2px #64857029;
}

.composer-row { display: flex; align-items: flex-end; gap: .52rem; }
.photo-picker, .photo-remove {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding-inline: .55rem;
  border: 1px solid #dce0d5;
  border-radius: .48rem;
  color: var(--accent);
  background: #f0f2eb;
  font-size: .86rem;
  white-space: nowrap;
}

.photo-picker:hover, .photo-remove:hover { border-color: #a6b3a5; background: #e9eee5; }
.photo-icon {
  position: relative;
  width: .94rem;
  height: .77rem;
  overflow: hidden;
  border: 1px solid currentColor;
  border-radius: .14rem;
}

.photo-icon::before, .photo-icon::after { position: absolute; content: ""; }
.photo-icon::before {
  top: .12rem;
  right: .12rem;
  width: .18rem;
  height: .18rem;
  border-radius: 50%;
  background: currentColor;
}

.photo-icon::after {
  left: .13rem;
  bottom: -.24rem;
  width: .55rem;
  height: .55rem;
  transform: rotate(45deg);
  border: 1px solid currentColor;
  border-radius: .06rem;
}

.composer-photo {
  display: flex;
  align-items: center;
  gap: .63rem;
  min-width: 0;
  padding: .37rem .45rem;
  border: 1px solid #e2e4db;
  border-radius: .55rem;
  background: #f3f4ee;
}

.composer-photo img {
  flex: none;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: .32rem;
  object-fit: contain;
  background: var(--surface);
}

.composer-photo-caption {
  flex: 1;
  display: grid;
  gap: .2rem;
  min-width: 0;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.38;
}

.composer-photo-caption strong { color: var(--ink); font-size: .86rem; font-weight: 600; }
.photo-remove { padding: 0; background: var(--surface); font-size: 1.2rem; line-height: 1; }
.photo-feedback { margin: 0 .25rem; color: var(--muted); font-size: .82rem; line-height: 1.48; }
.photo-feedback:empty { display: none; }
.photo-feedback.is-error { color: #8d392c; }

.composer textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.85rem;
  max-height: 8.5rem;
  padding: .22rem .44rem;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  resize: none;
  line-height: 1.57;
}

.composer textarea:focus-visible { outline: none; }
.composer textarea::placeholder { color: #646b60; }
.send {
  flex: none;
  min-height: 2.75rem;
  padding-inline: .92rem;
  border: 0;
  border-radius: .48rem;
  color: #fffef9;
  background: var(--accent);
  font-size: .9rem;
  font-weight: 600;
}

.send:not(:disabled):hover { background: var(--accent-hover); }
.send:disabled { color: #4f5e52; background: #e7ece4; cursor: default; }
.composer-help {
  margin: .48rem .15rem 0;
  color: #62685e;
  font-size: .77rem;
  text-align: center;
}

.composer-help span { margin-inline: .28rem; }
.composer-help kbd {
  padding: .04rem .24rem;
  border: 1px solid var(--line);
  border-radius: .25rem;
  background: var(--surface);
  font: inherit;
}

@media (max-width: 800px) {
  :root { --header-height: 3.72rem; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 3;
    width: min(17rem, 86vw);
    box-shadow: 8px 0 24px #17251c1c;
  }

  .sidebar.is-open { display: flex; }
  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 2;
    border: 0;
    background: #14231c65;
  }

  .menu-button {
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: .5rem;
    color: var(--accent);
    background: var(--surface);
  }

  .menu-button:hover { background: #e9ece4; }
  .menu-button span {
    position: relative;
    width: .89rem;
    height: .67rem;
    border-block: 1px solid;
  }

  .menu-button span::after {
    content: "";
    position: absolute;
    top: calc(50% - .5px);
    left: 0;
    width: 70%;
    border-top: 1px solid;
  }

  .desktop-title { display: none; }
  .mobile-title {
    display: inline;
    font-family: var(--display-font);
    font-weight: 650;
    letter-spacing: .08em;
  }
}

@media (max-width: 500px) {
  :root {
    --avatar-size: 2.1rem;
    --message-gap: .7rem;
    --page-inset: .94rem;
  }

  .topbar-title { gap: .58rem; }
  .main:has(.home:not([hidden])) .conversation { align-content: center; }
  .main:has(.home:not([hidden])) .composer-area { padding-bottom: max(.72rem, env(safe-area-inset-bottom)); }
  .hero { min-height: clamp(10rem, 33dvh, 15rem); }
  .hero-text { padding-inline: 1.18rem; }
  .hero-tag { font-size: clamp(1rem, 4.6vw, 1.23rem); letter-spacing: .07em; }
  .hero-tag::before { margin-bottom: .65rem; }
  .hero-art { background-position: right 29%; mask-image: linear-gradient(90deg, transparent 18%, #000 57%); }
  .chat { padding-top: 1.25rem; }
  .messages { gap: 1.45rem; }
  .message-user .message-bubble { max-width: 88%; padding: .65rem .8rem; }
  .composer-area { padding-bottom: max(.72rem, env(safe-area-inset-bottom)); }
  .composer-row { gap: .32rem; }
  .photo-picker { padding-inline: .42rem; }
  .composer textarea { padding-inline: .31rem; }
  .composer-help { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

/* Reply visuals share the chat rhythm while making their controls distinct. */
.physics-visual-stack { display: grid; gap: .85rem; margin-top: 1rem; }
.message-assistant .message-bubble:has(.physics-visual-stack) { width: 100%; }

.physics-visual {
  min-width: 0;
  margin: 0;
  padding: clamp(.7rem, 2.5vw, 1rem);
  overflow: hidden;
  border: 1px solid var(--visual-border, #dddcd1);
  border-radius: .9rem;
  color: var(--ink);
  background: var(--visual-paper, #fffefa);
}

.physics-simulation {
  --visual-ink: #394e79;
  --visual-border: #d5dfed;
  --visual-paper: #f3f7fd;
  --visual-stage: #e8effb;
}

.physics-simulation[data-simulation="free-fall"] {
  --visual-ink: #236b63;
  --visual-border: #cbded8;
  --visual-paper: #f1f8f4;
  --visual-stage: #e4f1eb;
}

.physics-simulation[data-simulation="braking"] {
  --visual-ink: #82482d;
  --visual-border: #e9d8c5;
  --visual-paper: #fcf5ec;
  --visual-stage: #f7e9d9;
}

.physics-visual-title {
  margin: 0;
  color: var(--visual-ink, #394e40);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
}

.physics-visual-description {
  margin: .3rem 0 .78rem;
  color: #505a60;
  font-size: .85rem;
  line-height: 1.6;
}

.physics-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: .65rem;
  background: var(--visual-stage);
}

.physics-controls { display: grid; gap: .65rem; margin-top: .85rem; }
.physics-sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
  gap: .6rem .85rem;
}

.physics-slider {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: .2rem .45rem;
  color: #303a41;
  font-size: .84rem;
  font-weight: 600;
}

.physics-slider-value {
  color: var(--visual-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.physics-slider input[type="range"] {
  grid-column: 1 / -1;
  align-self: center;
  width: 100%;
  min-width: 0;
  min-height: 1.65rem;
  margin: 0;
  accent-color: var(--visual-ink);
  cursor: pointer;
}

.physics-buttons { display: flex; flex-wrap: wrap; gap: .45rem; }
.physics-buttons button {
  min-height: 2.55rem;
  padding: .35rem .77rem;
  border: 1px solid var(--visual-border);
  border-radius: .5rem;
  color: var(--visual-ink);
  background: #fff;
  font-size: .84rem;
  font-weight: 600;
}

.physics-buttons .physics-play {
  border-color: var(--visual-ink);
  color: #fff;
  background: var(--visual-ink);
}

.physics-buttons button:hover { filter: brightness(.94); }
.physics-readings {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .7rem;
  margin: .75rem 0 0;
}

.physics-reading {
  min-width: 0;
  padding: .36rem .6rem;
  border: 1px solid var(--visual-border);
  border-radius: .45rem;
  background: #ffffffb8;
}

.physics-reading dt { color: #52605e; font-size: .76rem; }
.physics-reading dd {
  margin: .11rem 0 0;
  color: var(--visual-ink);
  font-size: .9rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.physics-table-visual {
  --visual-paper: #f4f6ef;
  --visual-border: #d8dfd1;
  --visual-ink: #355744;
}

.physics-table-scroll {
  max-width: 100%;
  margin-top: .65rem;
  overflow-x: auto;
  border: 1px solid var(--visual-border);
  border-radius: .55rem;
  background: #fff;
}

.physics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
  line-height: 1.6;
  text-align: left;
  overflow-wrap: anywhere;
}

.physics-table th, .physics-table td {
  padding: .58rem .65rem;
  border-bottom: 1px solid #e3e7df;
  vertical-align: top;
}

.physics-table tr:last-child td, .physics-table tr:last-child th[scope="row"] { border-bottom: 0; }
.physics-table thead th { color: #2e493a; background: #e6eee4; font-weight: 650; }
.physics-table tbody th { color: #2e493a; font-weight: 650; }
.physics-table tbody tr:nth-child(even) { background: #f6f8f4; }
.physics-status { margin: .5rem 0 0; font-size: .82rem; color: var(--visual-ink, #254e4a); }
.physics-status:empty { margin: 0; }

.photo-transcript {
  margin-top: .85rem;
  padding: .75rem .9rem;
  border: 1px solid #cddfd9;
  border-radius: .75rem;
  background: #edf5f1;
}
.photo-transcript summary { color: #254e4a; font-size: .87rem; font-weight: 650; cursor: pointer; }
.photo-transcript p {
  max-height: 14rem;
  margin: .55rem 0 0;
  overflow: auto;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: .9rem;
  line-height: 1.6;
}

#retry-photo { border-color: #e5c8a5; color: #794a24; background: #fff5e8; }

@media (max-width: 500px) {
  .physics-visual-stack { gap: .65rem; margin-top: .75rem; }
  .physics-sliders { grid-template-columns: minmax(0, 1fr); }
  .physics-table th, .physics-table td { padding: .43rem .45rem; }
  .physics-table { font-size: .8rem; }
}
