:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --text: #17171a;
  --muted: #6e747d;
  --line: rgba(24, 24, 27, 0.09);
  --line-strong: rgba(24, 24, 27, 0.15);
  --blue: #007aff;
  --yellow: #f5b800;
  --shadow: 0 12px 34px rgba(15, 23, 42, 0.07);
  --glass-blur: blur(24px) saturate(160%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8f9fa 0, var(--bg) 220px),
    var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

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

button {
  border: 0;
}

button,
summary {
  touch-action: manipulation;
}

.app {
  width: min(820px, calc(100vw - 16px));
  margin: 0 auto;
  padding: 6px 0 max(28px, env(safe-area-inset-bottom));
}

.nav-shell {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) 0 7px;
  background: rgba(243, 244, 246, 0.78);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  min-width: 0;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 12px;
  background: rgba(226, 228, 232, 0.7);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 7px 20px rgba(24, 24, 27, 0.05);
}

.tab,
.account-button,
.compact-button,
.icon-button,
.dialog-close,
.auth-segment button,
.primary-button,
.logout-button {
  cursor: pointer;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease;
}

.tab {
  min-width: 0;
  min-height: 36px;
  border-radius: 9px;
  padding: 6px 5px;
  background: transparent;
  color: #686d75;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.15;
  white-space: normal;
}

.tab.is-active {
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.95) inset,
    0 2px 9px rgba(15, 23, 42, 0.09);
}

.account-button {
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 12px;
  padding: 0 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.panel {
  display: none;
  padding-top: 4px;
}

.panel.is-active {
  display: block;
}

.panel-tools {
  position: sticky;
  top: 55px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 45px;
  padding: 5px;
  margin-bottom: 6px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow);
}

.search {
  flex: 0 1 230px;
  width: min(42vw, 230px);
  min-width: 106px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.search::placeholder {
  color: #91969e;
}

.search:focus {
  border-color: rgba(0, 122, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.icon-button,
.compact-button {
  flex: 0 0 auto;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
}

.icon-button {
  width: 34px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.favorite-filter.is-active {
  border-color: rgba(245, 184, 0, 0.35);
  background: rgba(255, 248, 219, 0.96);
  color: #b98200;
}

.compact-button {
  min-width: 44px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 650;
}

.result-count {
  min-width: 26px;
  margin-right: auto;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.stack {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(145%);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
  box-shadow: var(--shadow);
}

.list-empty {
  padding: 16px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: stretch;
  min-height: 54px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 110px;
  transition: background-color 140ms ease;
}

.item:first-child,
.group-head + .item {
  border-top: 0;
}

.item-main {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 0;
  padding: 9px 4px 9px 11px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.item-no-star {
  grid-template-columns: minmax(0, 1fr);
}

.item-no-star .item-main {
  padding-right: 11px;
}

.item-left,
.item-right {
  min-width: 0;
}

.item-left {
  display: grid;
  gap: 2px;
}

.latin,
.han {
  font-size: 15px;
  font-weight: 680;
  line-height: 1.2;
  word-break: break-word;
}

.freq {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.item-right {
  justify-self: end;
  color: #27282d;
  font-size: 14px;
  line-height: 1.3;
  text-align: right;
  word-break: break-word;
  transition:
    filter 150ms ease,
    color 150ms ease,
    opacity 150ms ease;
}

.item[data-revealed="false"] .item-right {
  filter: blur(6px);
  opacity: 0.72;
  user-select: none;
}

.item[data-revealed="true"] {
  background: rgba(0, 122, 255, 0.045);
}

.star-button {
  align-self: center;
  width: 30px;
  height: 38px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #a9adb3;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition:
    transform 150ms ease,
    color 150ms ease;
}

.star-button.is-active {
  color: var(--yellow);
}

.stack-templates {
  display: grid;
  gap: 7px;
}

.template {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(145%);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
  box-shadow: var(--shadow);
  scroll-margin-top: 60px;
}

.template summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  user-select: none;
}

.template summary::-webkit-details-marker {
  display: none;
}

.template-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.template-meta {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-align: right;
}

.template-body {
  border-top: 1px solid var(--line);
  padding: 0 12px 12px;
}

.template-lede {
  margin: 10px 0 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.template pre {
  margin: 0;
  overflow: auto;
  border-radius: 8px;
  padding: 11px;
  background: #1c1c1e;
  color: #f5f5f7;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.translation-group {
  border-top: 1px solid var(--line);
}

.translation-group:first-child {
  border-top: 0;
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px 8px;
  background: rgba(237, 239, 242, 0.68);
}

.group-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.group-meta {
  color: var(--muted);
  font-size: 10px;
}

.auth-dialog {
  width: min(390px, calc(100vw - 24px));
  border: 0;
  border-radius: 18px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.auth-dialog::backdrop {
  background: rgba(19, 20, 23, 0.24);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.auth-sheet {
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 18px;
  padding: 14px;
  background: rgba(250, 250, 252, 0.86);
  backdrop-filter: blur(32px) saturate(170%);
  -webkit-backdrop-filter: blur(32px) saturate(170%);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.2);
}

.auth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.auth-head strong {
  font-size: 17px;
}

.dialog-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.12);
  color: #555961;
  font-size: 20px;
  line-height: 1;
}

.auth-segment {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(118, 118, 128, 0.12);
}

.auth-segment button {
  min-height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.auth-segment button.is-active {
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.auth-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.auth-form label {
  display: grid;
  gap: 5px;
}

.auth-form label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.auth-form input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 11px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  outline: none;
}

.auth-form input:focus {
  border-color: rgba(0, 122, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.auth-message {
  min-height: 17px;
  margin: 0;
  color: #c9342f;
  font-size: 12px;
  line-height: 1.4;
}

.primary-button,
.logout-button {
  min-height: 42px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: white;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.account-session {
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 5px 0 2px;
}

.session-avatar {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 3px;
  border-radius: 50%;
  background: linear-gradient(145deg, #202124, #555b65);
  color: white;
  font-size: 20px;
  font-weight: 750;
}

.account-session > span {
  color: var(--muted);
  font-size: 12px;
}

.logout-button {
  width: 100%;
  margin-top: 10px;
  background: rgba(255, 59, 48, 0.09);
  color: #d62f28;
}

.tab:hover,
.account-button:hover,
.compact-button:hover,
.icon-button:hover,
.dialog-close:hover,
.auth-segment button:hover,
.primary-button:hover,
.logout-button:hover {
  transform: translateY(-1px);
}

.tab:active,
.account-button:active,
.compact-button:active,
.icon-button:active,
.dialog-close:active,
.star-button:active,
.primary-button:active,
.logout-button:active {
  transform: scale(0.96);
}

.item-main:active {
  background: rgba(0, 122, 255, 0.055);
}

[hidden] {
  display: none !important;
}

@media (max-width: 560px) {
  .app {
    width: min(100vw - 12px, 820px);
    padding-top: 3px;
  }

  .nav-shell {
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 4px;
    padding-bottom: 5px;
  }

  .tabs {
    gap: 2px;
  }

  .tab {
    min-height: 34px;
    padding: 5px 3px;
    font-size: 11px;
  }

  .account-button {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 10px;
  }

  .panel-tools {
    top: 47px;
    min-height: 42px;
    padding: 4px;
  }

  .search {
    flex-basis: 150px;
    width: 34vw;
    height: 32px;
    font-size: 12px;
  }

  .icon-button,
  .compact-button {
    height: 32px;
  }

  .icon-button {
    width: 32px;
  }

  .compact-button {
    min-width: 40px;
    padding: 0 7px;
    font-size: 11px;
  }

  .result-count {
    min-width: 22px;
    font-size: 10px;
  }

  .item {
    min-height: 50px;
    scroll-margin-top: 96px;
  }

  .item-main {
    gap: 8px;
    padding: 8px 3px 8px 10px;
  }

  .latin,
  .han {
    font-size: 14px;
  }

  .item-right {
    font-size: 13px;
  }

  .template summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .template-meta {
    text-align: left;
  }
}

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