:root {
  --system-blue: #007AFF;
  --system-green: #34C759;
  --system-orange: #FF9500;
  --system-red: #FF3B30;
  --system-gray: #8E8E93;
  --system-gray2: #AEAEB2;
  --system-gray3: #C7C7CC;
  --system-gray4: #D1D1D6;
  --system-gray5: #E5E5EA;
  --system-gray6: #F2F2F7;
  --label-primary: #000000;
  --label-secondary: rgba(60, 60, 67, 0.6);
  --label-tertiary: rgba(60, 60, 67, 0.3);
  --bg-primary: #FFFFFF;
  --bg-secondary: #F2F2F7;
  --bg-tertiary: #FFFFFF;
  --separator: rgba(60, 60, 67, 0.12);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0, 0, 0.58, 1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --system-blue: #0A84FF;
    --system-green: #30D158;
    --system-orange: #FF9F0A;
    --system-red: #FF453A;
    --system-gray: #8E8E93;
    --system-gray2: #636366;
    --system-gray3: #48484A;
    --system-gray4: #3A3A3C;
    --system-gray5: #2C2C2E;
    --system-gray6: #1C1C1E;
    --label-primary: #FFFFFF;
    --label-secondary: rgba(235, 235, 245, 0.6);
    --label-tertiary: rgba(235, 235, 245, 0.3);
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --separator: rgba(84, 84, 88, 0.36);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-secondary);
  color: var(--label-primary);
  font-family: var(--font-system);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

.app-shell {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  background: var(--bg-secondary);
}

.view {
  display: none;
  padding: 16px 16px 92px;
  min-height: 100dvh;
}

.view.is-active {
  display: block;
  animation: view-in 220ms var(--ease-out);
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.nav-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px 0 16px;
}

.nav-title h1 {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--label-secondary);
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--system-blue);
  border-radius: 50%;
  background: var(--bg-tertiary);
  box-shadow: var(--shadow);
  transition: transform 120ms var(--ease-out);
}

.icon-button:active {
  transform: scale(0.94);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  color: var(--label-tertiary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.search-wrap:focus-within {
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 17px;
  padding: 10px 0;
  color: var(--label-primary);
}

.search-wrap input::placeholder {
  color: var(--label-tertiary);
}

.clear-button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--system-gray2);
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 8px;
  font-size: 13px;
  color: var(--label-secondary);
}

.summary-row .related-hint {
  color: var(--system-blue);
  font-weight: 600;
}

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

.list-section-title {
  margin: 18px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  text-transform: uppercase;
}

.list-card {
  background: var(--bg-tertiary);
  border-radius: 12px;
  overflow: hidden;
}

.entry-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  text-align: left;
  background: transparent;
  border-bottom: 1px solid var(--separator);
  transition: transform 120ms var(--ease-out);
}

.entry-row:last-child {
  border-bottom: 0;
}

.entry-row:active {
  background: var(--system-gray6);
  transform: scale(0.99);
}

.entry-main {
  flex: 1;
  min-width: 0;
}

.entry-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.entry-word {
  font-size: 17px;
  font-weight: 600;
}

.entry-pinyin {
  margin-top: 2px;
  font-size: 13px;
  color: var(--label-secondary);
}

.entry-snippet {
  margin-top: 4px;
  font-size: 14px;
  color: var(--label-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-related {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chevron {
  color: var(--system-gray3);
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-official {
  color: #0040A8;
  background: rgba(0, 122, 255, 0.14);
}

.badge-public {
  color: var(--system-gray);
  background: rgba(142, 142, 147, 0.16);
}

.badge-custom {
  color: #1C6B39;
  background: rgba(52, 199, 89, 0.16);
}

.badge-draft {
  color: #A05A00;
  background: rgba(255, 149, 0, 0.18);
}

@media (prefers-color-scheme: dark) {
  .badge-official {
    color: #64D2FF;
    background: rgba(10, 132, 255, 0.24);
  }

  .badge-public {
    color: #AEAEB2;
    background: rgba(142, 142, 147, 0.24);
  }

  .badge-custom {
    color: #30D158;
    background: rgba(48, 209, 88, 0.2);
  }

  .badge-draft {
    color: #FF9F0A;
    background: rgba(255, 159, 10, 0.2);
  }
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 13px;
  background: var(--system-gray6);
  color: var(--label-secondary);
}

.chip.is-blue {
  color: var(--system-blue);
}

.chip.is-red {
  color: var(--system-red);
}

.empty-state {
  padding: 72px 24px;
  text-align: center;
  color: var(--label-secondary);
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--system-gray6);
  color: var(--system-gray);
}

.empty-state p {
  margin: 4px 0;
  font-size: 15px;
}

.empty-state p:first-of-type {
  color: var(--label-primary);
  font-weight: 600;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  margin-bottom: 14px;
  background: var(--system-gray6);
  border-radius: 10px;
}

.segmented button {
  flex: 1;
  min-height: 32px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--label-secondary);
  transition: all 160ms var(--ease-out);
}

.segmented button.is-selected {
  background: var(--bg-tertiary);
  color: var(--label-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.group-card {
  background: var(--bg-tertiary);
  border-radius: 12px;
  overflow: hidden;
}

.group-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 4px;
}

.group-card-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
}

.group-card-desc {
  padding: 6px 16px 14px;
  color: var(--label-secondary);
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.member-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--separator);
  text-align: left;
}

.member-row:active {
  background: var(--system-gray6);
}

.member-role {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--system-blue);
}

.member-word {
  flex: 1;
  font-weight: 600;
}

.settings-group {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}

.settings-group h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.settings-note {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--label-secondary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 76px;
  border-radius: 10px;
  background: var(--system-gray6);
}

.stat-tile strong {
  font-size: 22px;
  font-weight: 700;
}

.stat-tile span {
  font-size: 12px;
  color: var(--label-secondary);
}

.button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-full);
  font-size: 16px;
  font-weight: 600;
  transition: transform 120ms var(--ease-out);
}

.button:active {
  transform: scale(0.98);
}

.button-primary {
  color: #FFFFFF;
  background: var(--system-blue);
}

.button-secondary {
  color: var(--system-blue);
  background: rgba(0, 122, 255, 0.12);
}

.button-destructive {
  color: var(--system-red);
  background: rgba(255, 59, 48, 0.12);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

textarea,
input[type="text"],
input[type="search"],
select {
  width: 100%;
  min-height: 44px;
  border: 0;
  outline: 0;
  border-radius: 10px;
  background: var(--system-gray6);
  padding: 10px 12px;
  font-size: 16px;
  color: var(--label-primary);
}

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

textarea:focus,
input:focus,
select:focus {
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.22);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--label-tertiary) 50%),
    linear-gradient(135deg, var(--label-tertiary) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.footer-note {
  padding: 18px 8px 10px;
  text-align: center;
  font-size: 13px;
  color: var(--label-tertiary);
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  height: calc(49px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(242, 242, 247, 0.94);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--separator);
  max-width: 520px;
  margin: 0 auto;
}

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

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  min-height: 44px;
  color: var(--system-gray);
  font-size: 10px;
}

.tab-item.is-active {
  color: var(--system-blue);
}

.tab-item span {
  font-size: 10px;
  line-height: 1;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-tertiary);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(0);
  animation: sheet-in 260ms var(--ease-out);
}

@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.sheet[hidden] {
  display: none;
}

.grabber {
  width: 36px;
  height: 5px;
  margin: 8px auto 4px;
  border-radius: 3px;
  background: var(--system-gray4);
}

.sheet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 16px;
}

.toolbar-button {
  min-height: 44px;
  padding: 0 4px;
  font-size: 17px;
  color: var(--system-blue);
}

.toolbar-button-primary {
  font-weight: 600;
}

.sheet-content {
  max-height: 68dvh;
  overflow-y: auto;
  padding: 4px 16px calc(20px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.detail-title {
  margin: 6px 0 2px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
}

.detail-pinyin {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--label-secondary);
}

.detail-block {
  margin: 18px 0;
}

.detail-block h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  text-transform: uppercase;
}

.detail-block p {
  margin: 0;
  font-size: 17px;
  line-height: 1.55;
}

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

.related-link {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--system-gray6);
  color: var(--system-blue);
  font-size: 15px;
  font-weight: 500;
}

.group-panel {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  background: var(--system-gray6);
}

.group-panel h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.group-panel p {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--label-secondary);
  line-height: 1.5;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.detail-actions .button {
  flex: 1;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row label {
  font-size: 15px;
  font-weight: 600;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.4);
}

.overlay[hidden] {
  display: none;
}

.alert {
  width: 270px;
  padding: 20px 16px 0;
  background: var(--bg-tertiary);
  border-radius: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

.alert h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
}

.alert p {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--label-secondary);
}

.alert-actions {
  display: flex;
  border-top: 1px solid var(--separator);
  margin: 0 -16px;
}

.alert-button {
  flex: 1;
  min-height: 44px;
  font-size: 17px;
  color: var(--system-blue);
  border-right: 1px solid var(--separator);
}

.alert-button:last-child {
  border-right: 0;
}

.alert-button-destructive {
  color: var(--system-red);
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: 320px;
  padding: 10px 16px;
  border-radius: var(--radius-full);
  background: rgba(28, 28, 30, 0.92);
  color: #FFFFFF;
  font-size: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (prefers-color-scheme: light) {
  .toast {
    background: rgba(28, 28, 30, 0.92);
  }
}

@media (min-width: 700px) {
  .app-shell {
    border-left: 1px solid var(--separator);
    border-right: 1px solid var(--separator);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
