/* CSS Custom Properties (Theme System) */

:root {
  --fg: #1f2937;
  --fg-subtle: #6b7280;
  --canvas: #fffff;
  --canvas-elevated: #ffffff;
  --canvas-inset: #f9fafb;
  --border: #e5e7eb;
  --border-subtle: #f3f4f6;
  --border-radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  
  --word-color: #111827;
  --pos-bg: #dbeafe;
  --pos-color: #1e40af;
  --pronunciation-color: #374151;
  --audio-color: #4b5563;
  --audio-hover-color: #1f2937;
  --definition-color: #374151;
  --example-color: #4b5563;
  --example-highlight: #3b82f6;
  --grammar-color: #14B8A6;
  --hr-color: #9ca3af;
  
  --button-bg: #f3f4f6;
  --button-hover-bg: #e5e7eb;
  --svg-path: #6b7280;
  
  --font-family: Georgia Regular;
  --font-serif: Georgia Regular;
  
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 36px;
  --text-5xl: 48px;
  
  --word-size: var(--text-5xl);
  --pos-size: var(--text-sm);
  --pronunciation-size: var(--text-xl);
  --definition-size: var(--text-lg);
  --example-size: var(--text-base);
  --grammar-size: var(--text-base);
  
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-base: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  
  --audio-button-size: calc(var(--text-base) * (36 / 18));
  --example-audio-offset: 10px;
  --search-button-offset: 4px;
  --pos-bottom-offset: 2px;
  
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;
}

/* Responsive Font Sizes */
@media (min-width: 475px) {
  :root {
    --text-xs: 14px;
    --text-sm: 16px;
    --text-base: 18px;
    --text-lg: 20px;
    --text-xl: 22px;
    --text-2xl: 26px;
    --text-3xl: 32px;
    --text-4xl: 40px;
    --text-5xl: 52px;
  }
}

/* Basic Style Reset */
*,
::after,
::before {
  box-sizing: border-box;
  border-width: 0;
  border-style: solid;
}

html,
body {
  margin: 0;
  padding: 0;
  line-height: var(--line-height-normal);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font-family);
  color: var(--fg);
}

:lang(zh-Hans) {
  font-family: "PingFang SC", "PingFang TC", "Noto Sans CJK SC", "Noto Sans SC", "Roboto", "Microsoft YaHei", "Microsoft JhengHei", "SimSun", "SimHei", "WenQuanYi Micro Hei", "WenQuanYi Zen Hei", "Source Han Sans SC", "Hiragino Sans GB", "Heiti SC", "STHeiti", serif;
}

h1, h2, h3, h4, h5, h6, p {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
}

ul, ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.card {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--spacing-lg);
  background-color: var(--canvas);
  border-radius: var(--border-radius);
  color: var(--fg);
  text-align: left;
  font-size: var(--text-base);
  line-height: var(--line-height-normal);
}

.search-button {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(calc(-50% + var(--search-button-offset)));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  cursor: pointer;
  border-radius: 8px;
  transition: opacity 0.2s ease;
  text-decoration: none;
}

.search-button:hover {
  opacity: 0.8;
}

.logo-light,
.logo-dark {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.logo-light {
  display: block;
}

.logo-dark {
  display: none;
}
:root.night-mode .logo-light,
:root .night_mode .logo-light,
:root .nightMode .logo-light,
[data-bs-theme='dark'] .logo-light {
  display: none;
}

:root.night-mode .logo-dark,
:root .night_mode .logo-dark,
:root .nightMode .logo-dark,
[data-bs-theme='dark'] .logo-dark {
  display: block;
}

.card-header {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-base);
  flex-wrap: wrap;
  padding-right: calc(50px + var(--spacing-sm));
}

.word {
  font-size: var(--word-size);
  font-weight: 700;
  color: var(--word-color);
  line-height: var(--line-height-tight);
  font-family: var(--font-serif);
  overflow-wrap: break-word;
  min-width: 0;
}

.pos-badge {
  background: var(--pos-bg);
  color: var(--pos-color);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 2px 8px var(--pos-bottom-offset) 8px;
  border-radius: calc(var(--border-radius) / 2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
  white-space: nowrap;
  height: fit-content;
  align-self: baseline;
  vertical-align: baseline;
}

.pos-badge.is-empty {
  visibility: hidden;
}

.grammar {
  color: var(--grammar-color);
  font-size: var(--grammar-size);
  font-style: italic;
  margin-bottom: var(--spacing-sm);
  line-height: var(--line-height-normal);
  font-family: var(--font-serif);
}

.pronunciation-audio {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
  flex-wrap: wrap;
}

.pronunciation-audio .translate-button {
  font-size: var(--text-xs);
  padding: 0;
  margin: 0;
  height: var(--audio-button-size);
  width: var(--audio-button-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  background: none !important;
  border: none !important;
  border-radius: 0;
  cursor: pointer;
  color: var(--svg-path);
  transition: color 0.2s ease;
  flex-shrink: 0;
  box-sizing: border-box;
  box-shadow: none !important;
}

.pronunciation {
  font-size: var(--pronunciation-size);
  color: var(--pronunciation-color);
  font-style: italic;
  font-family: var(--font-serif);
}

.audio-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--audio-button-size);
  height: var(--audio-button-size);
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.audio-button svg {
  width: 90% !important;
  height: 90% !important;
}

.audio-button svg path {
  fill: var(--svg-path);
  transition: fill 0.2s ease;
}

.audio-button:hover svg path {
  fill: var(--audio-hover-color);
}

.tts-button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--audio-button-size);
  height: var(--audio-button-size);
  border-radius: 50%;
  text-decoration: none;
  color: inherit;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.divider {
  margin: var(--spacing-base) 0;
  border: none;
  border-top: 1px solid var(--hr-color);
}

.definition-section {
  margin-bottom: var(--spacing-base);
}

.section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--fg);
  margin-bottom: var(--spacing-xs);
}

.definition-content {
  font-size: var(--definition-size);
  color: var(--definition-color);
  line-height: var(--line-height-relaxed);
}

.examples-section {
  margin-bottom: var(--spacing-base);
}

.examples-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0px;
}

.example-sentence {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--spacing-sm);
  margin-bottom: 0;
  min-width: 0;
  line-height: var(--line-height-relaxed);
}

.example-item {
  font-size: var(--example-size);
  color: var(--example-color);
  line-height: var(--line-height-relaxed);
  padding-left: var(--spacing-base);
  position: relative;
  flex: 1;
  min-width: 0;
}

.examples-list > .example-item {
  margin-bottom: var(--spacing-sm);
}

.examples-list > .example-item:last-child {
  margin-bottom: 0;
}

.example-item::before {
  content: '•';
  color: var(--example-highlight);
  font-weight: bold;
  position: absolute;
  left: 0;
}

/* Default state: no special coloring for i/b tags */
.example-item i,
.example-item b {
  color: inherit;
  font-style: italic;
  font-weight: 500;
}

/* Color highlighting only when parent has processed class */
.example-item.processed i:not(.in-brackets),
.example-item.processed b:not(.in-brackets) {
  color: var(--example-highlight);
  font-style: italic;
  font-weight: 500;
}

.example-audio {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  gap: 0.2em;
  width: var(--audio-button-size);
  min-height: var(--audio-button-size);
}

.example-audio .audio-button {
  transform: translateY(var(--example-audio-offset));
}

/* Mobile Optimization */
@media (max-width: 475px) {
  .card {
    padding: var(--spacing-base);
    margin: var(--spacing-xs);
  }
  
  .word {
    font-size: var(--text-4xl);
  }
  
  .pronunciation {
    font-size: var(--text-lg);
  }
  
  .audio-button {
    border-radius: 50% !important;
  }

  .pronunciation-audio .translate-button {
    font-size: 11px;
    padding: 0;
    margin: 0;
    margin-left: var(--spacing-xs);
    width: var(--audio-button-size);
    height: var(--audio-button-size);
    background: none !important;
    border: none !important;
    border-radius: 0;
    color: var(--svg-path);
    box-shadow: none !important;
  }

  .pronunciation-audio .translate-button svg {
    width: 80%;
    height: 80%;
  }
}

/* Large Screen Optimization */
@media (min-width: 1024px) {
  :root {
    --text-xs: 17px;
    --text-sm: 19px;
    --text-base: 22px;
    --text-lg: 26px;
    --text-xl: 28px;
    --text-2xl: 34px;
    --text-3xl: 42px;
    --text-4xl: 50px;
    --text-5xl: 64px;
    
    --spacing-base: 22px;
    --spacing-lg: 30px;
    --spacing-xl: 38px;
  }
  
  .card {
    max-width: 1280px;
  }
}

/* Mobile Border Handling */
.ios .card,
.android .card {
  border-radius: 0;
  margin: 0;
}

.ios *,
.android * {
  border-left-width: 0;
  border-right-width: 0;
  border-radius: 0;
}

/* iOS Specific Styles */
.ios .card {
  padding-bottom: calc(var(--spacing-lg) + env(safe-area-inset-bottom));
}

/* AnkiWeb Style Adaptation */
#quiz {
  --canvas: #fff;
}

#quiz #qa {
  margin-top: 0;
}

#quiz .card {
  padding: var(--spacing-base);
  margin: 0;
  max-width: none;
  box-shadow: none;
  border-radius: 0;
}

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

/* Accessibility (Reduced Motion) */
@media (prefers-reduced-motion: reduce) {
  .audio-button svg path {
    transition: none;
  }
}

@media print {
  .audio-button {
    display: none;
  }
}

/* Dark Mode CSS Variables */
:root.night-mode,
:root .night_mode,
:root .nightMode,
[data-bs-theme='dark'] {
  --fg: #e5e7eb;
  --fg-subtle: #d1d5db;
  --canvas: #2c2c2c;
  --canvas-elevated: #363636;
  --canvas-inset: #2c2c2c;
  --border: #494949;
  --border-subtle: #4b5563;
  
  --word-color: #f9fafb;
  --pos-bg: #1e40af;
  --pos-color: #dbeafe;
  --pronunciation-color: #e5e7eb;
  --audio-color: #d1d5db;
  --audio-hover-color: #f3f4f6;
  --definition-color: #e5e7eb;
  --example-color: #d1d5db;
  --example-highlight: #60a5fa;
  --grammar-color: #34d399;
  --hr-color: #374151;
  
  --button-bg: #404040;
  --button-hover-bg: #4b5563;
  --svg-path: #d1d5db;
}

.translate-button:hover {
  background: none !important;
  box-shadow: none !important;
  border: none !important;
}

.translate-button:disabled {
  opacity: 0.6;
  cursor: not-allowed !important;
}

.pronunciation-audio .translate-button svg {
  width: 80%;
  height: 80%;
}

.pronunciation-audio .translate-button:hover {
  color: var(--audio-hover-color);
}

.pronunciation-audio .translate-button:active {
  transform: none;
  box-shadow: none;
}

.pronunciation-audio .translate-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.translation {
  opacity: 0.75;
  line-height: var(--line-height-relaxed);
  margin-top: 0px;
  padding-top: 0px;
  padding-bottom: 0px;
  margin-bottom: 3px;
  font-weight: 500;
  font-family: "PingFang SC", "PingFang TC", "Noto Sans CJK SC", "Noto Sans SC", "Roboto", "Microsoft YaHei", "Microsoft JhengHei", "SimSun", "SimHei", "WenQuanYi Micro Hei", "WenQuanYi Zen Hei", "Source Han Sans SC", "Hiragino Sans GB", "Heiti SC", "STHeiti", serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  color: var(--fg);
}

.translation-definition {
  margin-top: 1px;
  margin-bottom: 3px;
  padding: 0;
  font-size: var(--text-sm);
  margin-left: 0;
  border-left: 3px solid var(--example-highlight);
  padding-left: 13px;
  opacity: 0.75;
  line-height: var(--line-height-relaxed);
}

.translation-example {
  font-size: var(--text-sm);
  margin-top: 1px;
  margin-left: 0;
  padding-left: var(--spacing-base);
  position: relative;
  line-height: var(--line-height-relaxed);
}

.translation-example > span:first-child {
  position: absolute;
  left: 0;
  margin-right: 0 !important;
}

.translation span {
  font-weight: 500;
  color: var(--example-highlight);
  font-family: "PingFang SC", "PingFang TC", "Noto Sans CJK SC", "Noto Sans SC", "Roboto", "Microsoft YaHei", "Microsoft JhengHei", "SimSun", "SimHei", "WenQuanYi Micro Hei", "WenQuanYi Zen Hei", "Source Han Sans SC", "Hiragino Sans GB", "Heiti SC", "STHeiti", serif;
}

:root.night-mode .translation-definition,
:root .night_mode .translation-definition,
:root .nightMode .translation-definition,
[data-bs-theme='dark'] .translation-definition {
  border-left-color: var(--example-highlight);
}

:root.night-mode .pronunciation-audio .translate-button:hover,
:root .night_mode .pronunciation-audio .translate-button:hover,
:root .nightMode .pronunciation-audio .translate-button:hover,
[data-bs-theme='dark'] .pronunciation-audio .translate-button:hover {
  color: var(--audio-hover-color);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.examples-section > .section-title {
  margin-bottom: 3px;
}