:root {
  --paper: #eef2f6;
  --paper-strong: #f8fafc;
  --ink: #1f2937;
  --ink-soft: #5b6778;
  --line: #d8dee7;
  --line-strong: #aab5c4;
  --accent: #4e647d;
  --accent-strong: #43576d;
  --accent-soft: #e7edf4;
  --slate: #5f7084;
  --slate-soft: #edf2f7;
  --danger: #a33e4c;
  --shadow: 0 8px 18px rgba(31, 41, 55, 0.05);
  --radius: 6px;
  --radius-sm: 4px;
  --font-head: "Bitter", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(78, 100, 125, 0.06), transparent 220px),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
}

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

button {
  cursor: pointer;
}

.login-shell {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(248, 250, 252, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1,
.hero h1,
.card h2,
.modal-card h2 {
  margin: 0;
  font-family: var(--font-head);
  letter-spacing: -0.01em;
}

.login-panel h1,
.hero h1 {
  color: #182433;
}

.login-copy,
.hero p,
.meta-text,
.login-note {
  color: var(--ink-soft);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-form,
.card-body,
.modal-card,
.column {
  display: grid;
  gap: 12px;
}

.login-form label,
.field-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(78, 100, 125, 0.11);
}

textarea {
  resize: vertical;
}

.login-error {
  border: 1px solid rgba(163, 62, 76, 0.2);
  background: rgba(163, 62, 76, 0.08);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.primary-btn,
.ghost-btn,
.view-tab,
.tool-tab,
.writing-tab {
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary-btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #f8fafc;
}

.primary-btn:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.ghost-btn,
.view-tab,
.tool-tab,
.writing-tab {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink-soft);
}

.ghost-btn:hover,
.logout-link:hover,
.view-tab:hover,
.tool-tab:hover,
.writing-tab:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.logout-link {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(248, 250, 252, 0.96);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 7px 10px;
  text-decoration: none;
}

.app-shell {
  max-width: 1560px;
  margin: 0 auto;
  padding: 18px 18px 30px;
}

.view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.9);
  box-shadow: var(--shadow);
}

.view-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.view-tab.is-active,
.tool-tab.is-active,
.writing-tab.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #223446;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.94);
  box-shadow: var(--shadow);
}

.hero-copy {
  display: grid;
  gap: 1px;
}

.hero-copy .eyebrow {
  margin-bottom: 0;
}

.hero-copy p {
  margin: 0;
}

.hero-copy h1 {
  font-size: clamp(14px, 1.2vw, 16px);
  line-height: 1.08;
}

.hero-copy p:last-child {
  font-size: 10px;
  max-width: 680px;
}

.hero-status {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-pill {
  min-width: 88px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.75);
}

.status-pill strong {
  font-size: 11px;
  line-height: 1.2;
}

.status-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 1px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.column {
  align-content: start;
  gap: 16px;
}

.card {
  background: rgba(248, 250, 252, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-tall {
  min-height: 500px;
}

.card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(231, 237, 244, 0.72), rgba(248, 250, 252, 0.08));
}

.card-head h2 {
  font-size: 20px;
}

.card-body {
  padding: 16px;
}

.card-body-stretch {
  min-height: 100%;
  grid-template-rows: 1fr auto;
}

.chip {
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: var(--slate-soft);
  color: var(--slate);
  font-family: var(--font-mono);
  font-size: 11px;
}

.tool-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 16px 0;
  flex-wrap: wrap;
}

.writing-tabs {
  padding-top: 10px;
}

.tool-panel {
  display: none;
  gap: 12px;
}

.tool-panel.is-active {
  display: grid;
}

.writing-panel {
  display: none;
  gap: 12px;
  min-height: 100%;
  grid-template-rows: auto 1fr auto;
}

.writing-panel.is-active {
  display: grid;
}

.head-actions,
.action-row,
.split-fields,
.inline-add,
.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.head-actions,
.action-row,
.modal-actions {
  flex-wrap: wrap;
}

.compact-select {
  width: auto;
  min-width: 180px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.88);
}

.split-fields > * {
  flex: 1;
}

.capture-box {
  min-height: 132px;
}

.scratch-box {
  min-height: 500px;
}

.journal-box {
  min-height: 500px;
}

.journal-box.is-readonly,
.scratch-box.is-readonly {
  background: #f1f4f7;
  color: var(--ink-soft);
}

.timer-status {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  background: rgba(78, 100, 125, 0.06);
  color: var(--accent-strong);
}

.preview-list,
.checklist-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.preview-list {
  display: grid;
  gap: 8px;
}

.preview-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.72);
}

.preview-item strong,
.checklist-group h3 {
  font-family: var(--font-head);
}

.preview-item span {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
}

.checklist-shell {
  display: grid;
  gap: 14px;
}

.checklist-group h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.checklist-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 7px 0;
  border-bottom: 1px solid rgba(216, 222, 231, 0.85);
}

.checklist-item:last-child {
  border-bottom: none;
}

.check-toggle {
  width: 21px;
  height: 21px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: transparent;
  padding: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
}

.check-toggle.is-done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.check-copy.is-done {
  color: var(--ink-soft);
  text-decoration: line-through;
}

.empty-state {
  color: var(--ink-soft);
  font-style: italic;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 6px;
  background: #1f2937;
  color: #f8fafc;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

#toast.error {
  background: var(--danger);
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 41, 55, 0.24);
  backdrop-filter: blur(2px);
}

.modal-shell[hidden] {
  display: none;
}

.modal-card {
  width: min(900px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

#editor-text {
  min-height: 420px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.view-scratch-only .hero,
.view-scratch-only .column:not(.column-wide),
.view-scratch-only .column-wide .card:not(.scratch-card),
.view-scratch-only .mode-note,
.view-scratch-only .writing-tabs {
  display: none;
}

.view-scratch-only .dashboard-grid {
  grid-template-columns: 1fr;
}

.view-scratch-only .column-wide {
  max-width: 980px;
  margin: 0 auto;
}

.view-scratch-only .scratch-card {
  min-height: calc(100vh - 150px);
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid > .column.column-wide {
    order: 1;
  }

  .dashboard-grid > .column:first-child {
    order: 2;
  }

  .dashboard-grid > .column:last-child {
    order: 3;
  }

  .hero {
    align-items: start;
    flex-wrap: wrap;
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 14px 12px 24px;
  }

  .view-bar {
    position: sticky;
    top: 8px;
    z-index: 15;
  }

  .view-scratch-only .hero,
  .view-scratch-only .column:not(.column-wide),
  .view-scratch-only .column-wide .card:not(.scratch-card),
  .view-scratch-only .mode-note,
  .view-scratch-only .writing-tabs {
    display: none;
  }

  .view-scratch-only .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .view-scratch-only .column-wide {
    max-width: none;
  }

  .view-scratch-only .scratch-card {
    min-height: calc(100vh - 92px);
  }
}

@media (max-width: 720px) {
  .card-head,
  .card-body,
  .tool-tabs {
    padding-left: 14px;
    padding-right: 14px;
  }

  .split-fields,
  .inline-add,
  .action-row,
  .head-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-copy p:last-child {
    font-size: 10px;
  }

  .compact-select {
    min-width: 0;
    width: 100%;
  }
}
