/* 德译智 shared component primitives.
 * New UI should prefer these classes over page-specific inline styles.
 * Existing page classes remain supported during gradual migration.
 */

:root {
  --component-control-sm: 34px;
  --component-control-md: 42px;
  --component-control-lg: 48px;
  --component-card-padding: 20px;
  --component-card-padding-compact: 16px;
  --component-gap-sm: 8px;
  --component-gap-md: 12px;
  --component-gap-lg: 16px;
}

/* Shared navigation and feedback */
.account-menu-wrap { position: relative; }
.account-menu-btn {
  min-width: 44px; min-height: 44px; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 18px;
}
.account-menu-btn.has-avatar {
  display: grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  border-radius: 50%; border-color: transparent;
  background: var(--primary-light); font-size: 24px; line-height: 1;
}
.account-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 130;
  width: 180px; max-width: calc(100vw - 24px); padding: 6px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface);
  box-shadow: var(--shadow-lg); display: grid; gap: 2px;
}
.account-menu a, .account-menu button {
  display: block; width: 100%; min-height: 42px; padding: 10px 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--text); text-align: left; text-decoration: none;
  font: inherit; font-size: 14px; white-space: nowrap; cursor: pointer;
}
.account-menu :is(a, button):hover,
.account-menu [aria-current="page"] { background: var(--primary-light); color: var(--primary); }
.inline-message {
  margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-error); background: var(--color-error-bg);
  color: var(--color-error); font-size: 14px; line-height: 1.5;
}
.inline-message--success {
  border-color: var(--color-success); background: var(--color-success-bg);
  color: var(--color-success);
}
.empty-state { text-align: center; padding: 28px 16px; color: var(--text-secondary); }
.empty-state-icon { display: block; font-size: 32px; margin-bottom: 10px; }
.empty-state h2, .empty-state h3 { margin: 0 0 8px; color: var(--text); font-size: 18px; }
.empty-state p { margin: 0 auto 16px; max-width: 32ch; line-height: 1.6; }
.empty-state .btn { text-decoration: none; }
.auth-required-state { width: 100%; }
.btn[aria-busy="true"] { cursor: wait; opacity: .75; }
.modal-panel { max-height: min(90dvh, 720px); overflow-y: auto; }
.modal-panel .auth-resend-btn { min-height: 44px; margin-bottom: var(--component-gap-sm); }
#login-panel #login-register-btn { margin-top: var(--component-gap-md); }
.toast-container { width: min(360px, calc(100vw - 24px)); }
.toast { width: 100%; }
@media (max-width: 768px) {
  .account-menu-wrap { display: none; }
  .account-menu-wrap.auth-active { display: block; }
  .account-menu-wrap.auth-active .account-menu-btn {
    min-width: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
  }
  .account-menu-wrap .account-menu {
    right: 0;
    top: calc(100% + 8px);
  }
  .modal-panel { max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px); }
  .toast-container { bottom: calc(12px + env(safe-area-inset-bottom)); }
}

.ui-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}

.ui-card--compact {
  padding: var(--component-card-padding-compact);
}

.ui-row {
  display: flex;
  align-items: center;
  gap: var(--component-gap-md);
}

.ui-row--between {
  justify-content: space-between;
}

.ui-stack {
  display: grid;
  gap: var(--component-gap-sm);
}

.ui-meta {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.ui-button-sm {
  min-height: var(--component-control-sm);
  padding: 7px 14px;
  font-size: 13px;
}

.ui-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--component-gap-sm);
}

.ui-list-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
}

.ui-update-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 76px);
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 10000;
  min-height: var(--component-control-md);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 65%, #fff);
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.ui-update-banner:focus-visible {
  outline: 3px solid color-mix(in srgb, #fff 85%, var(--primary));
  outline-offset: 3px;
}

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

@media (max-width: 768px) {
  .ui-row--responsive {
    align-items: flex-start;
  }

  .ui-card--compact {
    padding: 16px 18px;
  }
}


.dictionary-match-notice {
  margin: 0 0 var(--component-gap-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--component-gap-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 92%, var(--primary) 8%);
}

.dictionary-match-arrow {
  color: var(--text-muted);
}

.dictionary-morphology-alternatives {
  margin-top: var(--component-gap-md);
}

.dictionary-morphology-alternatives .ui-list-item {
  padding: 10px 12px;
}

@media (max-width: 768px) {
  .dictionary-match-notice {
    align-items: flex-start;
  }
}


/* Dictionary V2 result composition — uses existing tokens only. */
.dictionary-entry {
  display: grid;
  gap: var(--component-gap-lg);
  min-width: 0;
}

.dictionary-entry-header {
  align-items: flex-start;
}

.dictionary-entry-title-wrap {
  min-width: 0;
}

.dictionary-entry-title {
  margin: 0;
  overflow-wrap: anywhere;
}

.dictionary-entry-badges {
  margin-top: 6px;
  flex-wrap: wrap;
  gap: 6px;
}

.dictionary-entry-actions {
  flex-shrink: 0;
  gap: 6px;
}

.dictionary-section {
  min-width: 0;
}

.dictionary-section > h3,
.dictionary-section-heading h3 {
  margin: 0 0 8px;
}

.dictionary-section-heading {
  align-items: baseline;
}

.dictionary-sense-list,
.dictionary-collocation-list {
  gap: 8px;
}

.dictionary-sense-item,
.dictionary-collocation-item {
  padding: 10px 12px;
}

.dictionary-sense-main {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.dictionary-sense-number {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.dictionary-sense-usage,
.dictionary-register {
  margin-top: 4px;
}

.dictionary-sense-examples {
  margin: 8px 0 0;
  padding-left: 18px;
}

.dictionary-sense-examples li {
  display: grid;
  gap: 2px;
  margin-top: 4px;
}

.dictionary-collocation-head {
  align-items: baseline;
}

.dictionary-collocation-type {
  flex-shrink: 0;
}

.dictionary-collocation-zh {
  margin-top: 4px;
}

.dictionary-forms-disclosure,
.dictionary-compound-section {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.dictionary-compound-body {
  margin-top: 10px;
}

.dictionary-compound-flow {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.dictionary-compound-part {
  display: grid;
  gap: 4px;
  min-width: 110px;
  max-width: 220px;
}

.dictionary-compound-plus {
  align-self: center;
  color: var(--text-muted);
  font-weight: 700;
}

.dictionary-ai-deconstruct {
  margin-top: 10px;
}

.dictionary-ai-deconstruct-result,
.dictionary-ai-entry-result {
  margin-top: 8px;
}

.dictionary-compound-result {
  display: grid;
  gap: 12px;
}

.dictionary-ai-section {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.dictionary-empty {
  margin: 0;
}

.dictionary-word-family-section {
  display: grid;
  gap: var(--component-gap-md);
}

.dictionary-family-list {
  gap: 10px;
}

.dictionary-family-item {
  min-width: 0;
  padding: 12px 14px;
  overflow-wrap: anywhere;
}

.dictionary-family-item-head {
  align-items: flex-start;
  min-width: 0;
  flex-wrap: wrap;
}

.dictionary-family-word {
  min-width: 0;
}

.dictionary-family-link {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 650;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--primary) 38%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.dictionary-family-link:hover {
  color: var(--text);
}

.dictionary-family-badges {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.dictionary-family-badges .pos-tag {
  min-height: 24px;
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  line-height: 1;
}

.dictionary-family-meaning {
  margin-top: 6px;
  color: var(--text);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.dictionary-family-label,
.dictionary-family-note,
.dictionary-family-meaning-difference,
.dictionary-family-via {
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.dictionary-family-more {
  margin-top: 10px;
}

.dictionary-family-other {
  margin-top: 10px;
  min-width: 0;
}

.dictionary-family-more > summary {
  width: fit-content;
  list-style: none;
  cursor: pointer;
}

.dictionary-family-more > summary::-webkit-details-marker {
  display: none;
}

.dictionary-family-more[open] > summary {
  margin-bottom: 10px;
}

.dictionary-family-group-label {
  margin-bottom: -4px;
}

@media (max-width: 768px) {
  .dictionary-entry-header {
    gap: 10px;
  }

  .dictionary-entry-actions {
    width: 100%;
  }

  .dictionary-section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .dictionary-collocation-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .dictionary-compound-flow {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .dictionary-compound-plus {
    justify-self: center;
  }

  .dictionary-compound-part {
    max-width: none;
    width: 100%;
  }

  .dictionary-entry,
  .dictionary-section,
  .dictionary-sense-item,
  .dictionary-collocation-item,
  .dictionary-family-item {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .dictionary-family-item-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .dictionary-family-badges {
    justify-content: flex-start;
  }
}


/* Dictionary V2 visual polish — align result surfaces with the unified site system. */
.result-back-nav {
  width: fit-content;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  padding: 7px 10px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.result-back-nav:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 78%, var(--primary) 6%);
}

.result-back-nav:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 2px;
}

.dictionary-entry {
  gap: 18px;
}

.dictionary-entry-header {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--surface) 95%, var(--primary) 5%),
      color-mix(in srgb, var(--surface) 98%, transparent));
  box-shadow: var(--shadow-sm);
}

.dictionary-entry-title {
  font-size: clamp(30px, 5vw, 38px);
  line-height: 1.04;
  letter-spacing: -0.035em;
  font-weight: 680;
}

.dictionary-entry-badges {
  margin-top: 12px;
}

.dictionary-entry-badges .level-badge,
.dictionary-entry-badges .pos-tag,
.dictionary-entry-badges .gender-badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 620;
  line-height: 1;
}

.dictionary-entry-actions {
  gap: 8px;
}

.dictionary-entry-actions .speak-btn,
.dictionary-entry-actions .bookmark-btn,
.dictionary-entry-actions .copy-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  color: var(--text-secondary);
  box-shadow: none;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    transform var(--transition-fast);
}

.dictionary-entry-actions .speak-btn:hover,
.dictionary-entry-actions .bookmark-btn:hover,
.dictionary-entry-actions .copy-btn:hover {
  transform: none;
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 24%, var(--border));
  background: var(--primary-light);
}

.dictionary-section {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 97%, var(--bg) 3%);
}

.dictionary-section > h3,
.dictionary-section-heading h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.dictionary-section-heading {
  margin-bottom: 12px;
}

.dictionary-senses-section {
  padding-top: 20px;
}

.dictionary-sense-list,
.dictionary-collocation-list {
  margin-top: 12px;
  gap: 10px;
}

.dictionary-sense-item,
.dictionary-collocation-item {
  padding: 13px 14px;
  border-color: color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg) 72%, var(--surface) 28%);
}

.dictionary-sense-main {
  gap: 10px;
}

.dictionary-sense-number {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 22px;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-light);
  font-size: 11px;
}

.dictionary-sense-main strong {
  font-size: 16px;
  line-height: 1.5;
  font-weight: 590;
}

.dictionary-sense-usage,
.dictionary-register {
  margin-left: 32px;
}

.dictionary-collocation-item strong {
  font-weight: 590;
}

.dictionary-collocation-type {
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--surface) 88%, var(--primary) 7%);
}

.dictionary-collocation-empty {
  padding: 13px 14px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg) 74%, var(--surface) 26%);
}

.dictionary-forms-disclosure,
.dictionary-compound-section {
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 97%, var(--bg) 3%);
}

.dictionary-forms-disclosure > summary,
.dictionary-compound-section > summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 590;
  cursor: pointer;
}

.dictionary-forms-disclosure > summary:hover,
.dictionary-compound-section > summary:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 86%, var(--primary) 4%);
}

.dictionary-forms-disclosure[open] > summary,
.dictionary-compound-section[open] > summary {
  border-bottom: 1px solid var(--border);
}

.dictionary-forms-disclosure .forms-toggle-body,
.dictionary-compound-section .dictionary-compound-body {
  margin: 0;
  padding: 16px 18px;
}

.dictionary-compound-section .dictionary-ai-deconstruct {
  margin: 0 18px 16px;
}

.dictionary-examples-section .example-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.dictionary-examples-section .example-item {
  margin: 0;
  padding: 14px 15px;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg) 74%, var(--surface) 26%);
  box-shadow: none;
}

.dictionary-examples-section .ex-de {
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 520;
}

.dictionary-examples-section .ex-zh {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.dictionary-ai-section {
  padding: 16px 18px;
  border: 1px solid color-mix(in srgb, var(--primary) 16%, var(--border));
  background: color-mix(in srgb, var(--surface) 93%, var(--primary) 7%);
}

.dictionary-ai-section strong,
.dictionary-practice-copy strong {
  font-size: 14px;
  font-weight: 630;
}

.dictionary-ai-entry-result {
  padding-top: 10px;
}

.dictionary-practice-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 14px;
}

.dictionary-practice-copy {
  display: grid;
  gap: 3px;
}

.dictionary-practice-status,
.dictionary-practice-result {
  grid-column: 1 / -1;
}

.dictionary-match-notice {
  margin-bottom: 16px;
  border-color: color-mix(in srgb, var(--primary) 14%, var(--border));
  background: color-mix(in srgb, var(--surface) 94%, var(--primary) 6%);
}

@media (max-width: 768px) {
  .result-back-nav {
    margin-bottom: 14px;
    padding-left: 6px;
  }

  .dictionary-entry {
    gap: 14px;
  }

  .dictionary-entry-header {
    padding: 18px;
    gap: 16px;
  }

  .dictionary-entry-title {
    font-size: 30px;
  }

  .dictionary-entry-actions {
    width: auto;
  }

  .dictionary-section {
    padding: 16px;
    border-radius: 18px;
  }

  .dictionary-section-heading {
    margin-bottom: 10px;
  }

  .dictionary-sense-list,
  .dictionary-collocation-list,
  .dictionary-examples-section .example-list {
    gap: 8px;
  }

  .dictionary-sense-item,
  .dictionary-collocation-item,
  .dictionary-examples-section .example-item {
    padding: 12px 13px;
  }

  .dictionary-forms-disclosure,
  .dictionary-compound-section {
    border-radius: 18px;
  }

  .dictionary-practice-section {
    grid-template-columns: 1fr;
  }

  .dictionary-practice-section .btn {
    justify-self: start;
  }

  .dictionary-practice-status,
  .dictionary-practice-result {
    grid-column: auto;
  }
}

.dictionary-examples-section .example-source {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.dictionary-examples-section .example-source > summary {
  width: fit-content;
  padding: 4px 0;
  cursor: pointer;
}

.dictionary-examples-section .example-source > summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-radius: 4px;
}

.dictionary-examples-section .ex-attribution {
  margin-top: 4px;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.dictionary-examples-section .ex-attribution a {
  color: inherit;
  text-decoration: underline;
}
.sidebar[aria-hidden="true"] { visibility: hidden; pointer-events: none; }
