:root {
  --paper: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #ddd9cf;
  --chrome: #f7f5ef;
  --accent: #1f5f45;
  --danger: #a61b29;
  --shadow: 0 1px 8px rgba(31, 35, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--chrome);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 239, 0.96);
}

.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.28rem;
  font-weight: 700;
  white-space: nowrap;
}

.mode-tabs { display: flex; gap: 4px; }
.tab, .btn, .tool-btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.tab { padding: 7px 11px; }
.tab.active {
  background: var(--paper);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.app-main {
  height: calc(100dvh - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 0;
}

.view {
  height: 100%;
  min-height: 0;
}

.view[hidden] { display: none !important; }

#notesView, .drawing-view {
  display: flex;
  flex-direction: column;
}

.compact-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}

.title-input {
  flex: 1 1 auto;
  min-width: 120px;
  height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
}

.title-input:focus { border-color: #91a99e; }
.actions { display: flex; gap: 6px; flex: 0 0 auto; }
.btn {
  padding: 7px 11px;
  border-color: var(--line);
  background: var(--paper);
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:active, .tool-btn:active, .tab:active { transform: translateY(1px); }

.note-paper {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding: clamp(20px, 5vw, 54px);
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(19px, 2.1vw, 24px);
  line-height: 1.62;
  caret-color: var(--accent);
  -webkit-overflow-scrolling: touch;
}

.note-paper::placeholder { color: #a7a7a7; }

.status {
  min-height: 22px;
  flex: 0 0 22px;
  padding: 2px 12px 4px;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--chrome);
}

.drawing-toolbar {
  flex: 0 0 auto;
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--chrome);
  scrollbar-width: none;
}
.drawing-toolbar::-webkit-scrollbar { display: none; }
.tool-group { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; }
.divider { width: 1px; height: 28px; background: var(--line); flex: 0 0 1px; }

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--chrome);
  box-shadow: 0 0 0 1px #b9b5ac;
  background: #111111;
  cursor: pointer;
}
.color-dot.red { background: #d7263d; }
.color-dot.green { background: #18864b; }
.color-dot.blue { background: #1769d2; }
.color-dot.selected { box-shadow: 0 0 0 2px var(--ink); }

.tool-btn {
  min-width: 38px;
  padding: 6px 9px;
  border-color: var(--line);
  background: var(--paper);
  white-space: nowrap;
}
.tool-btn.selected { background: #e9efe9; border-color: #9cb4a7; }
.tool-btn.danger { color: var(--danger); }
.tool-btn:disabled { opacity: 0.38; cursor: default; }

.line-sample {
  display: block;
  width: 24px;
  border-radius: 99px;
  background: #111;
}
.line-sample.thin { height: 2px; }
.line-sample.medium { height: 5px; }
.line-sample.thick { height: 9px; }

.canvas-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #d8d5cd;
  padding: 8px;
}

#drawingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 2px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.archive-view {
  overflow-y: auto;
  padding: 18px clamp(14px, 4vw, 38px) 40px;
  background: #f5f3ed;
  -webkit-overflow-scrolling: touch;
}
.archive-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}
.archive-header h1 { margin: 0 0 4px; font-family: Georgia, serif; font-size: 1.55rem; }
.archive-header p { margin: 0; color: var(--muted); }
.archive-list { display: grid; gap: 10px; }
.archive-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(31,35,40,.04);
}
.archive-title { margin: 0 0 4px; font-weight: 650; overflow-wrap: anywhere; }
.archive-meta { color: var(--muted); font-size: .82rem; }
.archive-actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.archive-actions .btn { min-height: 34px; padding: 5px 9px; }
.archive-actions .delete { color: var(--danger); }
.empty-state { padding: 36px 10px; text-align: center; color: var(--muted); }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 720px) {
  .app-header { height: 52px; padding: 6px 8px; }
  .app-main { height: calc(100dvh - 52px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .brand { font-size: 1.1rem; }
  .tab { padding: 6px 8px; min-height: 36px; }
  .compact-bar { padding: 6px 8px; }
  .btn { padding: 6px 8px; min-height: 36px; }
  .tool-label { display: none; }
  .drawing-toolbar { min-height: 46px; padding: 5px 7px; }
  .color-dot { width: 29px; height: 29px; }
  .canvas-shell { padding: 5px; }
  .archive-item { grid-template-columns: 1fr; }
  .archive-actions { justify-content: flex-start; }
}

@media (max-width: 470px) {
  .brand { display: none; }
  .app-header { justify-content: center; }
  .mode-tabs { width: 100%; justify-content: space-around; }
  .tab { flex: 1; }
  .drawing-title-bar .actions .btn:first-child { display: none; }
}
