/* ─── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg:          #f5f2eb;
  --surface:     #edeae0;
  --border:      #c8c4b4;
  --text:        #1a1a18;
  --text-muted:  #6b6860;
  --accent:      #8b2020;        /* ink-red for links and accents        */
  --accent-dim:  #b85c5c;        /* visited / muted accent               */
  --mark-bg:     #f0d080;        /* warm highlight for Chinese tokens    */
  --mark-text:   #1a1a18;
  --input-bg:    #faf8f3;

  --font-cjk:    "PingFang SC", "PingFang TC", "Hiragino Sans GB", "Hiragino Sans CNS", "Heiti SC", "Noto Sans CJK SC", "Noto Serif CJK SC", "STSong", serif;
  --font-latin:  "Georgia", "Times New Roman", serif;
  --font-ui:     "Helvetica Neue", "Arial", sans-serif;
}

/* ─── Reset / Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-latin);
  min-height: 100vh;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 999;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
  padding-top: env(safe-area-inset-top, 0);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

html {
  scroll-padding-top: calc(1rem + env(safe-area-inset-top, 0));
}

/* ─── Search bar ──────────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#search {
  width: 100%;
  padding: 0.55rem 3.4rem 0.55rem 0.75rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-cjk);
  font-size: 1.05rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  /* remove Safari default search styling */
  -webkit-appearance: none;
  appearance: none;
}

#search::placeholder {
  color: var(--text-muted);
  font-family: var(--font-cjk);
  font-size: 0.95rem;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(139,32,32,0.12);
}

/* remove the "×" clear button Safari adds */
#search::-webkit-search-cancel-button {
  display: none;
  width: 0;
  height: 0;
  opacity: 0;
}

#clear-search {
  position: absolute;
  right: 0.4rem;
  top: 45%;
  transform: translateY(-50%);
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

#clear-search:hover {
  color: var(--accent);
}



/* ─── Hint / compteur ─────────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

#result-count {
  position: absolute;
  right: 2.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
}

.search-wrapper {
  position: relative;
}

/* ─── Main / Results ──────────────────────────────────────────────────────── */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

#status {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 2rem 0;
}

/* ─── Result list ─────────────────────────────────────────────────────────── */
#results {
  list-style: none;
  padding: 0;
}

#results li {
  border-bottom: 1px solid rgba(26, 26, 24, 0.10); /* light rule between results */
  display: flex;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#results li:last-child {
  border-bottom: none;
}

#results li.example-item {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
  white-space: normal;
}

#results li.example-item > .example-stems,
#results li.example-item > .example-chinese,
#results li.example-item > .example-french {
  display: block;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#results li.example-item > .example-stems::-webkit-scrollbar,
#results li.example-item > .example-chinese::-webkit-scrollbar,
#results li.example-item > .example-french::-webkit-scrollbar {
  display: none;
}
#results li::-webkit-scrollbar {
  display: none;
}

#results li.word-item::before,
#results li.example-item::before {
  display: none;
}

#results li.separator {
  list-style: none;
  border-top: none;
  margin: 0;
  padding: 0;
}

#results li.separator hr {
  display: none;
}

#results li.word-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  white-space: nowrap;
  overflow-x: auto;
}


#results li a {
  display: inline-block;
  flex: 0 0 auto;
  min-width: max-content;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-cjk);
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
  text-decoration: none;
  padding: 0.5rem 0 0.5rem 0;
  vertical-align: middle;
  transition: color 0.1s;
}

#results li a::-webkit-scrollbar {
  display: none;
}

#results li a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.18s ease;
}

#results li a:hover {
  color: var(--accent-dim);
  background: none;
  text-decoration: none;
}

#results li a:visited {
  color: var(--accent-dim);
}

#results li.word-item .word-definition,
#results li.example-item .example-french {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.example-item {
  padding: 0;
}
.example-stems {
  font-family: var(--font-cjk);
  font-size: 0.92rem;
}
.example-stems a {
  color: var(--accent);
  text-decoration: none;
  margin-right: 0.6rem;
}
.example-stems a:hover {
  text-decoration: underline;
}
.example-chinese {
  font-family: var(--font-cjk);
  font-size: 1rem;
  margin-bottom: 0.4rem;
  margin-left: 1rem;
}
.example-french {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-left: 1rem;
}


#results li.empty a,
#results li.empty {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-style: italic;
  padding: 1rem 0;
}

/* ─── Chinese highlight ───────────────────────────────────────────────────── */
mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 2px;
  padding: 0 1px;
  font-style: normal;
}

/* ─── Loading state ───────────────────────────────────────────────────────── */
body.loading header::after {
  content: '';
  display: block;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  margin-top: 6px;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .header-inner { padding: 0.75rem 1rem 0.6rem; }
  main           { padding: 0.75rem 1rem 3rem; }
  h1             { font-size: 1.2rem; }
  #search        { font-size: 1rem; }
  #results li a  { font-size: 0.92rem; }
}

/* ─── Dark mode (honours OS preference) ──────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #1a1a18;
    --surface:    #242420;
    --border:     #3a3a35;
    --text:       #e8e4d8;
    --text-muted: #8a8678;
    --accent:     #c96060;
    --accent-dim: #8a5050;
    --mark-bg:    #6b5010;
    --mark-text:  #f0e0b0;
    --input-bg:   #222220;
  }

  body {
    background-image: repeating-linear-gradient(
      0deg,
      transparent,
      transparent 24px,
      rgba(255,255,255,0.012) 24px,
      rgba(255,255,255,0.012) 25px
    );
  }
}
