:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #f0f4f2;
  --ink: #17211d;
  --muted: #63706a;
  --faint: #8b9691;
  --line: #dfe5e1;
  --accent: #1f8a70;
  --accent-strong: #126752;
  --accent-soft: #dff4ed;
  --amber: #b87718;
  --danger: #c4473d;
  --danger-soft: #fae8e6;
  --shadow: 0 20px 60px rgba(25, 37, 32, 0.10);
  --radius: 8px;
  --font: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141817;
  --surface: #1d2421;
  --surface-soft: #24302c;
  --ink: #eff5f2;
  --muted: #a9b6b0;
  --faint: #7d8c85;
  --line: #33403a;
  --accent: #69c3a7;
  --accent-strong: #8fd8c0;
  --accent-soft: #17372f;
  --amber: #ddb165;
  --danger: #ef8379;
  --danger-soft: #422421;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.30);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 22px 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 25px;
}

h2 {
  font-size: 22px;
}

.icon-button,
.ghost-button,
.danger-button,
.secondary-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: var(--radius);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.icon-button {
  width: 40px;
  background: var(--surface-soft);
  color: var(--ink);
}

.icon-button.small {
  width: 32px;
  min-height: 32px;
}

.ghost-button {
  padding: 0 14px;
  background: var(--surface-soft);
  color: var(--ink);
}

.danger-button {
  padding: 0 14px;
  background: var(--danger-soft);
  color: var(--danger);
}

.secondary-button {
  padding: 0 16px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.primary-button {
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.compact {
  min-height: 42px;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 22px 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
}

.status-strip div {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 99px;
  background: var(--amber);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--amber) 18%, transparent);
}

.status-dot.synced {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 18%, transparent);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 0 22px 16px;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

#searchInput {
  min-width: 0;
  min-height: 42px;
  padding: 0 13px;
}

.note-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow: auto;
  padding: 0 14px 18px;
}

.note-item {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.note-item:hover,
.note-item.active {
  border-color: var(--line);
  background: var(--surface);
}

.note-item.active {
  box-shadow: var(--shadow);
}

.note-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.note-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-mark {
  color: var(--amber);
  font-size: 12px;
}

.note-preview {
  display: -webkit-box;
  min-height: 0;
  margin: 3px 0 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.28;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-meta {
  color: var(--faint);
  font-size: 11px;
}

.workspace {
  min-width: 0;
  background: radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 8%, transparent), transparent 26%),
    var(--bg);
}

.empty-state {
  display: grid;
  align-content: center;
  max-width: 680px;
  min-height: 100vh;
  padding: 56px;
}

.empty-state h2 {
  margin-bottom: 12px;
  font-size: 34px;
}

.empty-state p:last-child {
  max-width: 520px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.editor {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 100vh;
  padding: 22px;
}

.mobile-topline {
  display: none;
}

.editor-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.title-input {
  width: 100%;
  min-height: 56px;
  padding: 0 16px;
  border-color: transparent;
  background: transparent;
  font-size: 30px;
  font-weight: 800;
}

.title-input:focus {
  border-color: var(--line);
  background: var(--surface);
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.content-input {
  width: 100%;
  min-height: 0;
  padding: 22px;
  resize: none;
  border-color: var(--line);
  background: color-mix(in srgb, var(--surface) 94%, var(--bg));
  box-shadow: var(--shadow);
  font-size: 17px;
  line-height: 1.75;
}

.tool-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.translate-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

select {
  min-height: 38px;
  padding: 0 34px 0 12px;
}

#saveState {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.translation-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 16px;
}

#translationOutput {
  width: 100%;
  min-height: 160px;
  padding: 16px;
  resize: vertical;
  border: 0;
  background: transparent;
  line-height: 1.7;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
    min-height: 100svh;
  }

  .sidebar,
  .workspace {
    min-height: 100svh;
  }

  .sidebar {
    border-right: 0;
  }

  body.editor-open .sidebar {
    display: none;
  }

  body:not(.editor-open) .workspace {
    display: none;
  }

  .brand-bar {
    padding: 18px 16px 12px;
  }

  h1 {
    font-size: 22px;
  }

  .status-strip,
  .search-row {
    margin-left: 16px;
    margin-right: 16px;
    padding-left: 0;
    padding-right: 0;
  }

  .status-strip {
    padding: 10px 12px;
  }

  .note-list {
    gap: 4px;
    padding: 0 10px 16px;
  }

  .note-item {
    padding: 10px 12px;
  }

  .note-preview {
    min-height: 0;
    margin: 5px 0 6px;
    line-height: 1.35;
  }

  .editor {
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  }

  body.editor-open {
    overflow: hidden;
  }

  .mobile-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
  }

  .editor-header {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 8px;
  }

  .title-input {
    min-height: 42px;
    padding: 0 8px;
    font-size: 22px;
  }

  .editor-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .editor-actions button {
    min-width: 0;
    min-height: 34px;
    padding: 0 4px;
    font-size: 13px;
    white-space: nowrap;
  }

  .content-input {
    height: 100%;
    min-height: 0;
    padding: 14px;
    font-size: 16px;
    line-height: 1.65;
  }

  .tool-panel {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    margin-top: 8px;
    padding: 8px;
  }

  .translate-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 68px;
    gap: 6px;
  }

  select,
  .secondary-button {
    min-width: 0;
    min-height: 34px;
    padding-left: 9px;
    padding-right: 24px;
    font-size: 13px;
  }

  #saveState {
    font-size: 12px;
    white-space: normal;
  }
}

@media (max-width: 460px) {
  .translate-controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 68px;
  }

  .editor-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
