:root {
  --page: #f7f5f0;
  --surface: #f7f5f0;
  --surface-2: #efece5;
  --line: #e2ddd5;
  --line-strong: #e2ddd5;
  --text: #23211e;
  --muted: #7a756d;
  --accent: #23211e;
  --font: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
}

body {
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100dvh;
}

.toolbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 249, 246, 0.92);
  min-width: 0;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  color: var(--text);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.icon-button {
  appearance: none;
  border: 1px solid var(--line);
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 9999px;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--text);
}

.icon-button svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.7;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.notes-rail {
  background: linear-gradient(180deg, #f7f5f0, #f3f0e9);
  color: var(--text);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 14px 0 10px;
  font-family: var(--font);
}

.notes-rail-header {
  padding: 4px 16px 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.01em;
  font-family: var(--font);
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0 6px 6px;
  overflow: auto;
  min-height: 0;
}

.note-item {
  display: block;
  width: 100%;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 14px 12px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  line-height: 1.25;
  font-family: var(--font);
  position: relative;
}

.note-item:hover {
  background: var(--surface-2);
}

.note-item.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.note-item-title {
  display: block;
  padding-right: 28px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-title-input {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  line-height: inherit;
}

.note-title-input:focus {
  box-shadow: inset 0 -1px var(--line-strong);
}

.note-edit-button {
  position: absolute;
  top: 11px;
  right: 9px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  appearance: none;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  cursor: pointer;
}

.note-item:hover .note-edit-button,
.note-edit-button:focus {
  opacity: 1;
}

.note-edit-button:hover,
.note-edit-button:focus-visible {
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.note-edit-button svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.note-item-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font);
}

.editor-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.editor-columns {
  display: flex;
  flex: 1;
  gap: 28px;
  min-height: 0;
  width: 100%;
}

.editor-column {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.editor-topbar {
  height: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 24px 0;
  background: rgba(247, 245, 240, 0.9);
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.01em;
  position: sticky;
  top: 0;
  z-index: 1;
}

.editor-title {
  appearance: none;
  border: 0;
  outline: none;
  background: transparent;
  padding: 0;
  font: inherit;
  color: var(--text);
  flex: 1 1 auto;
  width: auto;
  margin: 0 0 16px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.editor-title:focus {
  outline: none;
  box-shadow: none;
}

.editor {
  flex: 1;
  width: 100%;
  background: transparent;
  padding: 0 24px 40px;
  max-width: none;
  min-height: 0;
  overflow: auto;
}

.editor-block {
  display: block;
  width: 100%;
  min-height: 27px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  font: 16px/1.7 var(--font);
}

.editor-block::placeholder {
  color: #aaa39b;
  font-style: italic;
  font-weight: 300;
}

.editor-block:focus {
  outline: 0;
}

.critique-panel {
  display: flex;
  flex: 0 0 380px;
  flex-direction: column;
  min-width: 280px;
  min-height: 0;
  border-left: 1px solid var(--line-strong);
  background: rgba(247, 245, 240, 0.62);
}

.critique-header {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.feedback-run-button {
  flex: 0 0 auto;
  min-width: 72px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid #d8c9bc;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: #f8eee5;
  color: #765a45;
  font: 600 11px var(--font);
  cursor: pointer;
}

.feedback-run-button:hover {
  background: #f1e2d5;
}

.feedback-run-button:focus-visible {
  outline: 2px solid var(--line-strong);
  outline-offset: 2px;
}

.feedback-run-button.is-loading::after {
  width: 11px;
  height: 11px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: review-spin 0.7s linear infinite;
}

.feedback-run-button:disabled,
.feedback-pill:disabled {
  cursor: wait;
  opacity: 0.72;
}

@keyframes review-spin {
  to {
    transform: rotate(360deg);
  }
}

.critique-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.critique-title strong {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.critique-title span {
  color: var(--muted);
  font-size: 12px;
}

.critique-body {
  flex: 1;
  min-height: 0;
  padding: 24px;
  overflow: auto;
}

.critique-response {
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}

.critique-response.loading,
.critique-empty {
  color: var(--muted);
}

.critique-empty {
  display: grid;
  min-height: 120px;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 13px;
}

.critique-response p {
  margin: 0 0 14px;
}

.critique-response p:last-child {
  margin-bottom: 0;
}

.critique-response strong {
  font-weight: 600;
}

.feedback-alert {
  color: #9a4d4d;
  font-size: 13px;
  line-height: 1.5;
}

.tensions {
  display: grid;
  gap: 8px;
}

.tension-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  border: 1px solid #e8d9cb;
  border-radius: 14px;
  padding: 14px;
  background: #fbf3ea;
  box-shadow: 0 3px 12px rgba(112, 75, 48, 0.06);
  transition: opacity 0.15s ease, background 0.15s ease;
}

.tension-card.resolved {
  background: #f5eee7;
  color: #a39e96;
}

.tension-card.resolved .tension-text {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.tension-text {
  grid-column: 1 / -1;
  font-size: 13px;
  line-height: 1.45;
}

.suggestion-tag {
  justify-self: start;
  border: 1px solid #e2cdbb;
  border-radius: 999px;
  padding: 3px 8px;
  color: #8b6a52;
  background: #f8e9dc;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.copy-button {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.copy-button:hover,
.copy-button:focus-visible {
  color: var(--text);
  outline: 0;
}

.copy-button svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.resolve-button {
  grid-column: 2;
  justify-self: end;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
  font: 500 11px var(--font);
  cursor: pointer;
}

.resolve-button:hover,
.tension-card.resolved .resolve-button {
  border-color: rgba(45, 112, 58, 0.24);
  color: #397343;
}

.mobile-menu-button,
.feedback-pill,
.mobile-backdrop {
  display: none;
}

@media (max-width: 767px) {
  html,
  body {
    min-height: 100dvh;
  }

  body {
    overflow: hidden;
  }

  .app {
    min-height: 100dvh;
    height: 100dvh;
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .toolbar {
    height: 56px;
    padding: 0 14px;
  }

  .toolbar-left,
  .toolbar-right {
    gap: 8px;
  }

  .mobile-menu-button {
    display: inline-grid;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 0;
    width: 100%;
  }

  .notes-rail {
    position: fixed;
    z-index: 20;
    inset: 56px auto 0 0;
    width: min(86vw, 320px);
    max-height: none;
    border-right: 1px solid var(--line-strong);
    border-bottom: 0;
    box-shadow: 16px 0 36px rgba(35, 33, 30, 0.12);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

  body.mobile-notes-open .notes-rail {
    transform: translateX(0);
  }

  .editor-column {
    min-height: 0;
    width: 100%;
  }

  .critique-panel {
    position: fixed;
    z-index: 21;
    inset: auto 0 0;
    width: 100%;
    height: min(78dvh, 620px);
    min-width: 0;
    min-height: 0;
    border-top: 1px solid var(--line-strong);
    border-left: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 36px rgba(35, 33, 30, 0.16);
    transform: translateY(105%);
    transition: transform 0.24s ease;
  }

  body.mobile-feedback-open .critique-panel {
    transform: translateY(0);
  }

  .critique-header {
    position: relative;
    padding-top: 14px;
  }

  .critique-header::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 34px;
    height: 4px;
    border-radius: 999px;
    background: var(--line-strong);
    transform: translateX(-50%);
  }

  .mobile-backdrop {
    position: fixed;
    z-index: 19;
    inset: 56px 0 0;
    display: block;
    background: rgba(35, 33, 30, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  body.mobile-notes-open .mobile-backdrop,
  body.mobile-feedback-open .mobile-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .feedback-pill {
    position: fixed;
    z-index: 18;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 42px;
    padding: 0 15px;
    border: 1px solid #d8c9bc;
    border-radius: 999px;
    background: #f8eee5;
    color: #765a45;
    box-shadow: 0 8px 22px rgba(35, 33, 30, 0.18);
    font: 600 12px var(--font);
    cursor: pointer;
  }

  body.mobile-feedback-open .feedback-pill {
    opacity: 0;
    pointer-events: none;
  }

  .editor {
    width: 100%;
    padding: 0 18px calc(34px + env(safe-area-inset-bottom));
  }

  .critique-header,
  .critique-body {
    padding-left: 18px;
    padding-right: 18px;
  }
}
