:root {
  color-scheme: light;
  --editor-font-size: 17px;
  --editor-line-height: 32px;
  --paper: #fffdf8;
  --surface: #f7f3ea;
  --ink: #24211d;
  --muted: #81786d;
  --line: #ddd4c6;
  --accent: #126c63;
  --accent-strong: #0b4e49;
  --accent-soft: #d7eee9;
  --warn: #a4492a;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

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

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--paper);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  position: relative;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: rgba(255, 253, 248, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  z-index: 3;
}

.title-stack {
  min-width: 0;
  flex: 1;
}

.title-input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  outline: 0;
  padding: 0;
}

.save-state {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.save-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.sync-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  color: var(--accent-strong);
  background: transparent;
}

.sync-button svg {
  width: 15px;
  height: 15px;
}

.sync-button:active {
  transform: rotate(28deg);
}

.icon-button,
.tool-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf0;
}

.icon-button:active,
.tool-button:active,
.text-button:active {
  transform: translateY(1px);
}

.icon-button.accent {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px;
  background: #fbf7ef;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.tool-button {
  width: 40px;
  height: 38px;
  font-size: 15px;
  font-weight: 700;
}

.font-size-button {
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
}

.font-size-button-small {
  font-size: 13px;
}

.font-size-button-large {
  font-size: 22px;
}

.editor {
  width: 100%;
  min-width: 0;
  height: 100%;
  resize: none;
  border: 0;
  outline: 0;
  padding: 18px 16px 28px;
  color: var(--ink);
  background: linear-gradient(
    #fffdf8 calc(var(--editor-line-height) - 1px),
    rgba(221, 212, 198, 0.36) var(--editor-line-height)
  );
  background-size: 100% var(--editor-line-height);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  caret-color: var(--accent);
}

.editor::selection {
  background: var(--accent-soft);
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px calc(env(safe-area-inset-bottom) + 9px);
  color: var(--muted);
  background: rgba(255, 253, 248, 0.96);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.auth-panel {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(247, 243, 234, 0.96);
  backdrop-filter: blur(18px);
  z-index: 8;
}

.auth-panel.open {
  display: flex;
}

.auth-card {
  width: min(100%, 360px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 18px;
  box-shadow: 0 18px 52px rgba(58, 48, 32, 0.18);
}

.auth-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.auth-copy,
.auth-status,
.auth-device {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-field {
  display: grid;
  gap: 6px;
  margin: 16px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.auth-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 0 11px;
  outline: 0;
}

.auth-submit {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.auth-status {
  margin-top: 12px;
  color: var(--accent-strong);
  font-weight: 700;
}

.auth-device {
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.document-drawer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--surface);
  transform: translateX(-104%);
  transition: transform 180ms ease;
  z-index: 5;
  box-shadow: 18px 0 34px rgba(64, 52, 36, 0.16);
}

.document-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
}

.text-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #fffaf0;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--muted);
}

.search-field input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.sort-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sort-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sort-field-button {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf8;
  padding: 0 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.sort-direction-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #fffdf8;
}

.sort-direction-button svg {
  width: 18px;
  height: 18px;
}

.sort-direction-button[data-direction="asc"] svg {
  transform: rotate(180deg);
}

.document-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-bottom: 6px;
}

.document-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fffdf8;
  text-align: left;
}

.document-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.document-meta {
  min-width: 0;
}

.document-name,
.document-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-name {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}

.document-time {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.document-preview {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.delete-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  color: var(--warn);
  background: transparent;
}

.empty-state {
  margin: 28px 8px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

@media (min-width: 760px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .app-shell {
    height: min(900px, calc(100dvh - 48px));
    border: 1px solid var(--line);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 28px 80px rgba(58, 48, 32, 0.16);
  }
}

@media (display-mode: standalone) {
  body {
    background: var(--paper);
    padding: 0;
  }

  .app-shell {
    max-width: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
