:root {
  --ios-blue: #007AFF;
  --ios-blue-dark: #0A84FF;
  --ios-green: #34C759;
  --ios-red: #FF3B30;
  --ios-gray: #8E8E93;
  --ios-bg: #F2F2F7;
  --ios-card: #FFFFFF;
  --ios-text: #000000;
  --ios-text-secondary: #3C3C43;
  --ios-border: rgba(60, 60, 67, 0.15);
  --ios-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --nav-height: 44px;
  --tab-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ios-bg: #1C1C1E;
    --ios-card: #2C2C2E;
    --ios-text: #FFFFFF;
    --ios-text-secondary: #EBEBF5;
    --ios-border: rgba(235, 235, 245, 0.15);
    --ios-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--ios-bg);
  color: var(--ios-text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  position: relative;
}

/* 顶部导航 */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--nav-height) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--ios-border);
  position: relative;
  z-index: 10;
}

@media (prefers-color-scheme: dark) {
  .nav-bar {
    background: rgba(28, 28, 30, 0.85);
  }
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.nav-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--ios-blue);
  cursor: pointer;
  border-radius: 12px;
}

.nav-btn:active {
  opacity: 0.5;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

/* 主内容 */
.main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(var(--tab-height) + var(--safe-bottom) + 4px);
  display: none;
}

.view--active {
  display: flex;
}

#editor-view {
  flex-direction: column;
}

#library-view {
  flex-direction: column;
}

/* 编辑器 */
.editor-card {
  background: var(--ios-card);
  border-radius: 16px;
  box-shadow: var(--ios-shadow);
  overflow: hidden;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.note-title {
  width: 100%;
  border: none;
  border-bottom: 0.5px solid var(--ios-border);
  background: transparent;
  color: var(--ios-text);
  font-size: 20px;
  font-weight: 700;
  padding: 16px;
  outline: none;
  font-family: inherit;
}

.note-title[readonly] {
  color: var(--ios-text-secondary);
}

.note-body {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ios-text);
  font-size: 17px;
  line-height: 1.6;
  padding: 16px;
  outline: none;
  resize: none;
  font-family: inherit;
  flex: 1;
  min-height: 120px;
}

.note-body::placeholder {
  color: var(--ios-gray);
}

/* 编辑器工具栏 */
.editor-toolbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-top: 0.5px solid var(--ios-border);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  padding: 0 8px;
  border-radius: 7px;
  border: none;
  background: rgba(120, 120, 128, 0.12);
  color: var(--ios-text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}

.tool-btn:active {
  opacity: 0.6;
}

.tool-btn svg {
  width: 14px;
  height: 14px;
}

/* 图片网格 */
.image-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px 12px;
  max-height: 160px;
  overflow-y: auto;
}

.image-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--ios-bg);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.delete-image {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(60, 60, 60, 0.8);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.delete-image:active {
  background: rgba(60, 60, 60, 1);
}

.editor-actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

/* 按钮 */
.btn {
  flex: 1;
  height: 36px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--ios-blue);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .btn-primary {
    background: var(--ios-blue-dark);
  }
}

.btn-secondary {
  background: var(--ios-card);
  color: var(--ios-blue);
  box-shadow: inset 0 0 0 1px var(--ios-border);
}

.btn-ghost {
  background: transparent;
  color: var(--ios-blue);
}

.btn-sm {
  height: 32px;
  font-size: 15px;
  padding: 0 12px;
  flex: none;
}

.btn-block {
  width: 100%;
}

.btn:active {
  opacity: 0.7;
}

/* 笔记库 */
.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.library-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.segmented-control {
  display: inline-flex;
  background: rgba(120, 120, 128, 0.16);
  border-radius: 8px;
  padding: 2px;
}

.segment {
  border: none;
  background: transparent;
  color: var(--ios-text);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
}

.segment--active {
  background: var(--ios-card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.folder-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.folder-chip {
  flex: none;
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--ios-card);
  color: var(--ios-text-secondary);
  font-size: 14px;
  font-weight: 500;
  border: 0.5px solid var(--ios-border);
  cursor: pointer;
}

.folder-chip--active {
  background: var(--ios-blue);
  color: #fff;
  border-color: var(--ios-blue);
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-item {
  background: var(--ios-card);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--ios-shadow);
  cursor: pointer;
}

.note-item:active {
  opacity: 0.7;
}

.note-item__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item__preview {
  font-size: 14px;
  color: var(--ios-text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.note-item__meta {
  font-size: 12px;
  color: var(--ios-gray);
  display: flex;
  justify-content: space-between;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ios-gray);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 17px;
  margin-bottom: 20px;
}

/* 底部标签栏 */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(242, 242, 247, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--ios-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 10;
}

@media (prefers-color-scheme: dark) {
  .tab-bar {
    background: rgba(28, 28, 30, 0.92);
  }
}

.tab {
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--ios-gray);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  padding-bottom: 8px;
  font-family: inherit;
  font-size: 9px;
  font-weight: 500;
  cursor: pointer;
}

.tab svg {
  width: 20px;
  height: 20px;
}

.tab--active {
  color: var(--ios-blue);
}

/* 模态框 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.modal-sheet {
  position: relative;
  background: var(--ios-bg);
  border-radius: 24px 24px 0 0;
  padding: 12px 16px calc(24px + var(--safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-sheet--alert {
  margin: auto 32px 80px;
  border-radius: 18px;
  padding: 20px;
  text-align: center;
  max-height: none;
}

.modal-handle {
  width: 36px;
  height: 5px;
  background: var(--ios-gray);
  border-radius: 3px;
  margin: 0 auto 12px;
  opacity: 0.5;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  position: relative;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  position: absolute;
  right: 0;
  border: none;
  background: transparent;
  color: var(--ios-blue);
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
}

.folder-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.folder-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--ios-card);
  border-radius: 12px;
  border: none;
  color: var(--ios-text);
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.folder-option:active {
  opacity: 0.7;
}

.folder-option__count {
  font-size: 15px;
  color: var(--ios-gray);
}

.text-input {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  border: 0.5px solid var(--ios-border);
  background: var(--ios-card);
  color: var(--ios-text);
  font-size: 17px;
  padding: 0 12px;
  margin-bottom: 16px;
  font-family: inherit;
  outline: none;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions--row {
  flex-direction: row;
}

/* Toast */
.toast {
  position: fixed;
  top: calc(var(--nav-height) + var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(60, 60, 60, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 500;
  z-index: 200;
  white-space: nowrap;
}

/* 响应式优化 */
@media (min-width: 768px) {
  .main {
    max-width: 680px;
    margin: 0 auto;
    width: 100%;
  }
}
