:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --panel: #ffffff;
  --line: #deded8;
  --line-soft: #ecece7;
  --text: #1e1f1c;
  --muted: #797a73;
  --accent: #22231f;
  --danger: #a53e35;
  --chart: #383a34;
  --shadow: 0 12px 36px rgba(0,0,0,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button, input, textarea, select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  min-height: 100dvh;
  border-right: 1px solid var(--line);
  background: #f1f1ed;
  display: flex;
  flex-direction: column;
  padding: max(22px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.sidebar-header,
.dialog-header,
.editor-toolbar,
.editor-footer,
.mobile-editor-bar,
.stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar h1, .dialog-header h2 {
  margin: 2px 0 0;
  font-size: 24px;
  letter-spacing: -.03em;
}

.eyebrow {
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--muted);
  font-weight: 700;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 14px 2px 18px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b8c84;
}

.status-dot.online { background: #4d7f56; }
.status-dot.syncing { background: #b58b3c; }

.primary-button,
.secondary-button {
  border: 1px solid var(--accent);
  border-radius: 10px;
  min-height: 42px;
  padding: 9px 14px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  background: transparent;
  color: var(--accent);
}

.new-button {
  width: 100%;
  margin-bottom: 10px;
}

.writing-summary {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.35);
  color: var(--text);
  border-radius: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
}

.writing-summary-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-bottom: 3px;
}

.writing-summary strong {
  font-size: 15px;
  letter-spacing: -.01em;
}

.writing-summary-arrow {
  color: var(--muted);
  font-size: 22px;
}

.icon-button,
.text-button,
.danger-text-button {
  border: 0;
  background: transparent;
  padding: 7px;
  cursor: pointer;
  color: var(--muted);
}

.icon-button {
  font-size: 21px;
  width: 40px;
  height: 40px;
  border-radius: 9px;
}

.icon-button:hover { background: rgba(0,0,0,.04); }

.text-button { color: var(--text); }
.danger-text-button { color: var(--danger); }
.full-width { width: 100%; margin-top: 8px; }

.project-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.project-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 10px;
  padding: 12px 12px 11px;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  margin-bottom: 3px;
}

.project-item:hover { background: rgba(0,0,0,.035); }
.project-item.active { background: #deded7; }

.project-title {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.42;
  font-weight: 620;
}

.project-meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.project-empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 10px;
  font-size: 13px;
  line-height: 1.7;
}

.sidebar-footer { padding-top: 8px; }

.editor-pane {
  background: var(--panel);
  min-height: 100dvh;
  position: relative;
}

.empty-state {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
  padding: 30px;
}

.empty-state h2 {
  color: var(--text);
  margin: 13px 0 6px;
  font-size: 20px;
}

.empty-state p {
  margin: 0;
  max-width: 360px;
  line-height: 1.6;
  font-size: 13px;
}

.empty-icon { font-size: 30px; }

.editor {
  min-height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  padding: max(26px, env(safe-area-inset-top)) 44px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.editor-toolbar { min-height: 34px; }

.save-status,
.editor-footer {
  color: var(--muted);
  font-size: 11px;
}

.title-input,
.body-input,
.dialog-card input {
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
}

.title-input {
  display: block;
  width: 100%;
  resize: none;
  overflow: hidden;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 720;
  line-height: 1.13;
  letter-spacing: -.04em;
  margin: 28px 0 18px;
  padding: 0;
  min-height: 1.2em;
  overflow-wrap: anywhere;
}

.body-input {
  width: 100%;
  flex: 1;
  min-height: 58vh;
  resize: none;
  font-size: 17px;
  line-height: 1.85;
  padding: 0;
}

.editor-footer {
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  margin-top: 18px;
}

.mobile-editor-bar { display: none; }
.mobile-bar-actions { display: flex; align-items: center; gap: 2px; }
.hidden { display: none !important; }


.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(20,20,18,.34);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-layer > .dialog-card {
  max-height: calc(100dvh - 28px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: none;
}

dialog::backdrop {
  background: rgba(20,20,18,.34);
  backdrop-filter: blur(3px);
}

.dialog-card {
  width: min(560px, calc(100vw - 28px));
  background: var(--panel);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.stats-card {
  width: min(820px, calc(100vw - 28px));
}

.dialog-copy {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  margin: 14px 0 20px;
}

.stats-copy { margin-bottom: 8px; }

.dialog-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 14px 0;
}

.dialog-card input {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 12px;
  margin-top: 6px;
  font-size: 15px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 18px;
}

.connection-message {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
  line-height: 1.5;
}

.connection-message.error { color: var(--danger); }
.connection-message.success { color: #4d7f56; }

.stats-head {
  margin: 24px 0 2px;
  align-items: flex-end;
}

.stats-kicker {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 3px;
}

.stats-today {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.035em;
}

.range-label {
  margin: 0 !important;
  text-align: right;
}

.range-label select {
  display: block;
  margin-top: 5px;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 30px 5px 9px;
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
  padding-top: 8px;
}

.writing-chart {
  display: block;
  width: 100%;
  min-width: 620px;
  height: auto;
}

.chart-grid {
  stroke: var(--line-soft);
  stroke-width: 1;
}

.chart-axis-text {
  fill: var(--muted);
  font-size: 11px;
}

.chart-line {
  fill: none;
  stroke: var(--chart);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-point {
  fill: var(--panel);
  stroke: var(--chart);
  stroke-width: 2;
}

.chart-area {
  fill: var(--chart);
  opacity: .06;
}

.stats-empty {
  color: var(--muted);
  padding: 48px 0 30px;
  text-align: center;
  font-size: 13px;
}

@media (max-width: 700px) {
  #app { display: block; }

  .sidebar {
    border-right: 0;
    min-height: 100dvh;
  }

  body.editing-mobile .sidebar { display: none; }
  body:not(.editing-mobile) .editor-pane { display: none; }

  .editor-pane { min-height: 100dvh; }

  .mobile-editor-bar {
    display: flex;
    min-height: 50px;
    padding: max(8px, env(safe-area-inset-top)) 12px 5px;
    border-bottom: 1px solid var(--line-soft);
  }

  .editor {
    padding: 8px 20px max(14px, env(safe-area-inset-bottom));
    min-height: calc(100dvh - 50px);
  }

  .title-input {
    margin-top: 18px;
    font-size: 30px;
  }

  .body-input {
    font-size: 17px;
    min-height: 56vh;
  }

  .editor-toolbar { margin-top: 3px; }

  .stacked-mobile { flex-direction: column-reverse; }
  .stacked-mobile button { width: 100%; }

  .stats-card {
    width: calc(100vw - 18px);
    padding: 18px;
  }

  .stats-today { font-size: 26px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #181916;
    --panel: #1e1f1c;
    --line: #3a3b36;
    --line-soft: #30312d;
    --text: #efefe9;
    --muted: #a2a39b;
    --accent: #efefe9;
    --danger: #ef8c80;
    --chart: #d9dad2;
    --shadow: 0 12px 36px rgba(0,0,0,.35);
  }

  .sidebar { background: #191a17; }
  .primary-button { color: #181916; }
  .project-item.active { background: #30312d; }
  .writing-summary { background: rgba(255,255,255,.025); }
}


.activity-sync-label {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 500;
}

.activity-sync-label.pending {
  color: #a77e2c;
}

.activity-sync-label.error {
  color: var(--danger);
}

.activity-sync-label.synced {
  color: #4d7f56;
}


.writing-summary-main {
  display: block;
  min-width: 0;
  flex: 1;
}

.goal-summary {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 3px;
}

.goal-progress-track {
  display: block;
  width: 100%;
  max-width: 220px;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--line);
  margin-top: 8px;
}

.goal-progress-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--text);
  transition: width .18s ease;
}

.goal-percent {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 650;
  color: var(--text);
}

.stats-percent {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.goal-setting-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin: 18px 0 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 18px;
  align-items: center;
}

.goal-setting-title {
  font-size: 13px;
  font-weight: 700;
}

.goal-setting-copy {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.goal-setting-controls {
  display: flex;
  align-items: center;
  gap: 7px;
}

.goal-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.goal-input-wrap input {
  width: 112px !important;
  margin: 0 !important;
  padding: 8px 9px !important;
}

.compact-button {
  min-height: 36px;
  padding: 7px 10px;
}

.goal-save-message {
  grid-column: 1 / -1;
  min-height: 14px;
  color: var(--muted);
  font-size: 11px;
}

.goal-save-message.success {
  color: #4d7f56;
}

.goal-save-message.error {
  color: var(--danger);
}

.chart-goal-line {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 7 6;
}

.chart-goal-text {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

@media (max-width: 700px) {
  .goal-setting-card {
    grid-template-columns: 1fr;
  }

  .goal-setting-controls {
    flex-wrap: wrap;
  }

  .goal-input-wrap {
    width: 100%;
  }

  .goal-input-wrap input {
    flex: 1;
    width: auto !important;
  }
}
