:root {
  --body-bg: radial-gradient(circle at top, #202020 0%, #111 55%, #080808 100%);
  --page-padding: clamp(0.5rem, 1.2vw, 2rem);
  --mobile-chat-height: 70vh;
  --mobile-shared-height: 30vh;
  --panel-bg: rgba(10, 10, 10, 0.82);
  --panel-border: #2a2a2a;
  --panel-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --chat-max-width: 3000px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Cutive Mono", monospace;
  margin: 0;
  min-height: 100vh;
  padding: var(--page-padding);
  background: var(--body-bg);
  color: #e3e0d7;
}

#eda-app-shell {
  min-height: 100vh;
}

.route {
  display: none;
  min-height: 100vh;
}

.route.route--active {
  display: block;
}

.route--hidden {
  display: none !important;
}

/* route-nav was the old per-route header; superseded by unified .menu-bar */

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows:
    minmax(var(--mobile-chat-height), 1fr)
    minmax(calc(var(--mobile-shared-height) * 0.5), 0.5fr)
    minmax(calc(var(--mobile-shared-height) * 0.5), 0.5fr);
  grid-template-areas:
    "main"
    "left"
    "right";
  gap: 0;
  min-height: calc(100vh - (var(--page-padding) * 2));
  isolation: isolate;
}

.mobile-shared-notes {
  display: none;
}

main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: clamp(1rem, 2vw, 2.5rem);
  background: rgba(0, 0, 0, 0.45);
  border-radius: clamp(0.5rem, 1vw, 1.25rem) clamp(0.5rem, 1vw, 1.25rem) 0 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  z-index: 10;
}

#left-philosopher {
  grid-area: left;
}

#right-philosopher {
  grid-area: right;
}

.philosopher-notes {
  position: relative;
  overflow: visible;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: clamp(0.5rem, 1vw, 1rem);
  border-radius: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  min-height: 0;
  height: 100%;
}

.philosopher-notes-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #9d9686;
  letter-spacing: 0.08em;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  text-align: center;
}

/* Non-dev: hide philosopher area title, bounding boxes, menu bar outline (see note-pages.css, landing.css); remove philosopher region outline */
body:not([data-dev-mode="true"]) .philosopher-notes-title {
  display: none !important;
}

body:not([data-dev-mode="true"]) .philosopher-notes,
body:not([data-dev-mode="true"]) .mobile-shared-notes {
  border: none !important;
}

.left-philosopher .philosopher-notes-title {
  text-align: left;
}

.right-philosopher .philosopher-notes-title {
  text-align: right;
}

.philosopher-notes-content {
  flex: 1;
  min-height: 0;
  position: relative;
  height: 100%;
}

h1 {
  font-size: clamp(1.25rem, 1.6vw, 1.75rem);
  margin: 0 0 0.5rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 1rem;
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  /* Anchor conversation at the bottom when there are only a few messages,
     then let the container scroll naturally as it fills. */
  justify-content: flex-end;
  gap: 1rem;
}

.messages .message,
.messages .chat-editor-wrapper {
  flex: 0 0 auto;
  width: 100%;
  max-width: 70ch;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
}

.message.assistant {
  align-items: flex-start;
  align-self: flex-start;
}

.message .label {
  font-size: 0.75rem;
  font-family: var(--chat-editor-font, "Cutive Mono", monospace);
  font-weight: bold;
  letter-spacing: 0.18em;
  color: #1a1a1a;
  text-transform: uppercase;
}

.message .label--detective {
  text-align: right;
  width: 100%;
}

.message .label--querent {
  text-align: left;
}

.message .content {
  display: block;
  min-height: 0;
  padding: 0;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  font-family: var(--chat-editor-font, "Cutive Mono", monospace);
  max-width: 70ch;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.message.user .content {
  align-self: flex-start;
  text-align: left;
  padding-left: 1.5rem;
  background: transparent;
  border: none;
}

.message.assistant .content {
  align-self: flex-start;
  text-align: left;
  padding-left: 1.5rem;
  background: transparent;
  border: none;
}

body[data-dev-mode="true"] .message.user .content,
body[data-dev-mode="true"] .message.assistant .content {
  border: 1px solid #000;
}

.status {
  font-size: 0.875rem;
  color: #888;
  margin-top: 0.5rem;
  min-height: 1.25rem;
}

.status.error {
  color: #f87171;
}

.form button {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 0.5rem;
  background: #3b82f6;
  color: #fff;
  font-weight: 500;
  cursor: pointer;
}

.form button:hover:not(:disabled) {
  background: #2563eb;
}

.form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  body {
    padding-bottom: calc(var(--mobile-shared-height, 30vh) + 2rem);
  }

  .route-nav {
    justify-content: flex-start;
    padding: 0.5rem 0;
  }

  main {
    border-radius: clamp(0.5rem, 1vw, 1.25rem);
  }

  .philosopher-notes-title {
    display: none;
  }

  .philosopher-notes {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.75rem 0;
  }

  body[data-viewport="mobile"] #left-philosopher,
  body[data-viewport="mobile"] #right-philosopher {
    display: none;
  }

  .app-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "main";
  }

  .messages {
    padding-bottom: 3rem;
  }

  .chat-editor-wrapper {
    margin-top: auto;
    position: sticky;
    bottom: 0;
    background: var(--chat-bg, #e8e4d8);
    padding: 0.75rem 0;
  }

  .mobile-shared-notes {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--mobile-shared-height, 30vh);
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: transparent;
    padding: 0.75rem;
    z-index: 60;
  }

  .mobile-shared-notes .philosopher-notes-content {
    position: relative;
    width: 100%;
    height: 100%;
  }

  button,
  [role="button"] {
    min-width: 40px;
    min-height: 40px;
  }
}

@media (min-width: 769px) and (max-width: 1440px) {
  .app-layout {
    /* Chat 10% less horizontal: 50% / 50% so philosophers get more space */
    grid-template-columns: minmax(0, 0.5fr) minmax(0, 0.5fr);
    grid-template-rows: minmax(50vh, 1fr) minmax(50vh, 1fr);
    grid-template-areas:
      "main left"
      "main right";
  }

  main {
    border-radius: 1.25rem 0 0 1.25rem;
  }

  /* Right philosopher overlaps 20% of top (left) philosopher's space; both share the area */
  /* Philosopher panels above chat (z-index 10) so notes can cover or be dragged over chat */
  #left-philosopher {
    z-index: 15;
  }

  #right-philosopher {
    margin-top: -10vh; /* 20% of 50vh row height = shared overlap */
    z-index: 20;
  }

  .philosopher-notes {
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 0 1.25rem 1.25rem 0;
    background: transparent;
    padding: 1.25rem;
    box-shadow: none;
  }

  .philosopher-notes-title {
    display: block;
  }
}

@media (min-width: 1441px) {
  body {
    padding-left: 20px;
    padding-right: 20px;
  }

  .app-layout {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left main right";
    column-gap: 0;
    width: 100%;
    max-width: none;
    margin: 0;
  }

  main {
    border-radius: 1.25rem;
  }

  #left-philosopher {
    border-radius: 1.25rem 0 0 1.25rem;
  }

  #right-philosopher {
    border-radius: 0 1.25rem 1.25rem 0;
  }

  .philosopher-notes {
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: transparent;
    padding: 1.5rem;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
