:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #686b70;
  --line: #d8dce2;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --accent: #2c5b52;
  --accent-strong: #173f39;
  --danger: #9b2c2c;
  font-family: "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  padding-bottom: 72px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
}

button:active {
  transform: translateY(1px);
}

.ghost-button,
.line-head button,
.version-row button,
.list-actions button,
.mode-tabs button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(100%, 420px);
  padding: 20px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-panel h1,
.topbar h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.login-form,
.editor-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  line-height: 1.65;
}

.form-message {
  min-height: 22px;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.96);
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f2f4f1;
}

.mode-tabs button.active {
  background: var(--accent-strong);
  color: #fff;
}

.workspace {
  display: block;
  min-height: 0;
}

.item-list-panel {
  display: none;
  background: #f7f7f4;
  min-height: calc(100vh - 178px);
  overflow: auto;
}

.list-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
}

.item-list {
  display: grid;
  gap: 6px;
  padding: 0 12px 16px;
}

.item {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 54px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.item strong {
  overflow-wrap: anywhere;
}

.item span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.editor-panel {
  display: none;
  min-width: 0;
  padding: 16px;
  overflow: auto;
}

.app-shell[data-work-view="read"] .editor-panel,
.app-shell[data-work-view="input"] .editor-panel {
  min-height: calc(100vh - 132px);
}

.app-shell[data-work-view="list"] .item-list-panel,
.app-shell[data-work-view="read"] .editor-panel,
.app-shell[data-work-view="input"] .editor-panel {
  display: block;
}

.empty-state {
  color: var(--muted);
  padding: 28px 0;
}

.status-row,
.save-row,
.vn-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-row {
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.dirty {
  color: var(--danger);
}

.clean {
  color: var(--accent-strong);
}

.editor-section {
  display: grid;
  gap: 12px;
}

.editor-form {
  min-height: calc(100vh - 164px);
  align-content: start;
}

.reader-panel {
  min-height: calc(100vh - 178px);
}

.reader-header {
  position: sticky;
  top: 60px;
  z-index: 2;
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.98);
}

.reader-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.reader-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.reader-body {
  padding: 16px 0 24px;
  line-height: 1.85;
}

.reader-body p {
  margin: 0 0 14px;
}

.reader-line {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.reader-line strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-strong);
}

.main-textarea {
  min-height: 45vh;
}

.segment-textarea {
  min-height: 120px;
}

.markdown-preview {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  line-height: 1.8;
}

.markdown-preview h2,
.markdown-preview h3 {
  margin: 12px 0 8px;
  letter-spacing: 0;
}

.line-editor {
  display: grid;
  gap: 10px;
}

.line-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.line-head,
.version-row,
.dialog-body header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.line-row textarea {
  min-height: 92px;
}

dialog {
  width: min(720px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-body h2 {
  margin: 0;
  font-size: 20px;
}

.versions-list {
  display: grid;
  gap: 8px;
  max-height: 60vh;
  overflow: auto;
}

.version-row {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.version-row span {
  color: var(--muted);
  font-size: 13px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.98);
}

.bottom-nav button {
  min-height: 46px;
  padding: 0 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.bottom-nav button.active {
  border-color: var(--accent);
  background: var(--accent-strong);
  color: #fff;
}

.app-shell:not([data-work-view="list"]) .mode-tabs {
  display: none;
}

.app-shell[data-work-view="input"] .markdown-preview {
  display: none;
}

.view-changing .item-list-panel,
.view-changing .reader-panel:not(.hidden),
.view-changing .editor-form:not(.hidden) {
  animation: view-in 140ms ease-out;
}

@keyframes view-in {
  from {
    opacity: 0.45;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 10px 12px;
  }

  .workspace {
    display: block;
  }

  .item-list-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    min-height: calc(100vh - 138px);
  }

  .editor-panel {
    padding: 12px;
  }

  .main-textarea {
    min-height: 40vh;
  }

  .save-row button,
  .vn-toolbar button {
    flex: 1 1 130px;
  }
}
