:root {
  --bg: #f7f6f3;
  --card: #ffffff;
  --ink: #3b3a37;
  --muted: #9a9892;
  --accent: #ea580c;
  --accent-soft: #fff2e6;
  --border: #e8e6e1;
  --mark: #ffd9a8;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.layout {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

.side {
  flex: none;
  position: sticky;
  top: 0;
  width: 340px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem 1.25rem;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-anchor: none;
}

.brand {
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand .subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.site-logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: clamp(64px, 9vh, 104px);
  margin: 0 auto 0.6rem;
  border-radius: 10px;
}

.dir-toggle {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.2rem;
  margin-top: 0.7rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.dir-btn {
  padding: 0.22rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.dir-btn:hover {
  color: var(--ink);
}

.dir-btn.active {
  color: #ffffff;
  background: #c2410c;
}

.search-wrap { position: relative; }

.search-box {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  font-family: "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  text-align: left;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  outline: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box::placeholder {
  color: var(--muted);
  opacity: 0.45;
}

.search-box::-webkit-input-placeholder {
  color: var(--muted);
  opacity: 0.45;
}

.search-box:-moz-placeholder {
  color: var(--muted);
  opacity: 0.45;
}

.search-box::-moz-placeholder {
  color: var(--muted);
  opacity: 0.45;
}

.search-box:-ms-input-placeholder {
  color: var(--muted);
  opacity: 0.45;
}

.search-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.summary-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.summary-results h3 {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.summary {
  margin: 0;
  padding: 0.35rem 0.6rem;
  border-radius: 7px;
  font-size: 0.88rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.45;
  animation: rise-in 0.45s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  transition: background 0.2s ease;
}

.summary:nth-child(even) {
  background: #f2f0eb;
}

.summary:hover {
  background: #ece9e2;
}

.summary:active {
  transform: translateY(0.5px);
}

.summary:hover .thai-lemma { color: var(--accent); }

.summary .thai-lemma {
  font-weight: 600;
  font-size: 0.9rem;
}

.summary .roman-lemma {
  color: var(--muted);
  font-size: 0.82em;
}

.summary-source {
  margin-left: auto;
  flex: none;
  text-align: right;
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.welcome-info {
  margin-top: 0.6rem;
  text-align: center;
  color: #c2410c;
  font-family: "Athiti", "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
}

.count {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.footer-credit {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.6;
  text-align: center;
}

.footer-list {
  margin: 0.1rem 0 0;
  padding-left: 0;
  list-style-position: inside;
  text-align: center;
}

.footer-list li {
  line-height: 1.7;
}

.footer-copy {
  margin: 0.3rem 0 0;
  font-size: 0.78rem;
  line-height: 1.6;
}

.link-btn {
  padding: 0;
  font: inherit;
  color: #c2410c;
  background: none;
  border: none;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.footer-credit a {
  color: #c2410c;
  text-decoration: none;
}

.footer-credit a:hover {
  text-decoration: underline;
}

.main-pane {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 1.5rem;
}

.main-pane #results {
  max-width: 820px;
  margin: 0 auto;
}

.entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  animation: rise-in 0.55s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.entry:hover {
  transform: translateY(-2px);
  border-color: #f3c6a1;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.entry .head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.entry .head .sources {
  margin-left: auto;
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.thai-lemma {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--ink);
}

.roman-lemma {
  font-size: 1.05rem;
  color: var(--muted);
}

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.sources {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.source {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #c2410c;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
}

.source-btn {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  color: #ffffff;
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border: none;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.source-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(109, 40, 217, 0.4);
  filter: brightness(1.08);
}

.source-btn:active {
  transform: translateY(0) scale(0.96);
  filter: brightness(0.96);
}

.root-btn {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  color: #ffffff;
  background: linear-gradient(135deg, #0d9488, #0f766e);
  border: none;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.root-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.4);
  filter: brightness(1.08);
}

.root-btn:active {
  transform: translateY(0) scale(0.96);
  filter: brightness(0.96);
}

.meaning-line {
  font-size: 1.02rem;
  color: var(--ink);
  margin: 0.15rem 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 3.5rem 0;
  animation: rise-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 3.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  animation: rise-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.spinner {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

/* ------------------------------ help panel ---------------------------- */

.help h2 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.help-intro {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.help-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.help-title {
  font-weight: 700;
  font-size: 1.02rem;
  margin-bottom: 0.4rem;
}

.help-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.2rem 0;
}

.help-example {
  flex: none;
  min-width: 7.5rem;
  font-family: ui-monospace, "Consolas", "Courier New", monospace;
  font-size: 0.82rem;
  color: #6d28d9;
  background: #f3e8ff;
  border: 1px solid #e9d5ff;
  border-radius: 6px;
  padding: 0.05rem 0.5rem;
  text-align: center;
}

.help-desc {
  color: var(--muted);
  font-size: 0.9rem;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.9rem;
}

.help-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  background: #faf9f7;
}

.help-cell .help-example {
  align-self: center;
  min-width: 0;
  width: fit-content;
}

.help-cell .help-desc {
  font-size: 0.82rem;
  line-height: 1.4;
}

.help-img {
  display: block;
  width: 70%;
  margin: 0 auto;
  opacity: 0.8;
  border-radius: 12px;
  border: 0px solid var(--border);
}

/* ------------------------------ modal -------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 27, 22, 0.5);
  backdrop-filter: blur(3px);
  padding: 1.25rem;
  animation: overlay-in 0.3s ease-out;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: min(720px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  animation: modal-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-in {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.1rem 1.4rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.modal-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
}

.modal-source {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #6d28d9;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-close {
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.modal-close:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.modal-body {
  overflow-y: auto;
  padding: 1.25rem 1.4rem 1.5rem;
}

.d-sec {
  margin-bottom: 1.1rem;
}

.d-sec-title {
  margin: 0 0 0.55rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #5b21b6;
  border-bottom: 2px solid #ede9fe;
  padding-bottom: 0.35rem;
}

.d-text {
  margin: 0.25rem 0;
  font-size: 1rem;
  color: var(--ink);
  white-space: pre-wrap;
}

.d-text b { color: var(--ink); }

.d-chip {
  display: inline-block;
  margin: 0.15rem 0.25rem 0.15rem 0;
  padding: 0.15rem 0.6rem;
  font-size: 0.82rem;
  color: #5b21b6;
  background: #f3e8ff;
  border: 1px solid #e9d5ff;
  border-radius: 999px;
}

.d-chip.d-link {
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.d-chip.d-link:hover {
  background: #e9d5ff;
  transform: translateY(-1px);
}

.d-comp {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed #ece9e4;
  font-size: 0.95rem;
}

.d-comp .d-part { font-weight: 700; color: var(--ink); }
.d-comp .d-role { color: #6d28d9; }
.d-comp .d-note { color: var(--muted); }

.d-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed #ece9e4;
  font-size: 0.95rem;
}

.d-chain .d-abbr { font-weight: 700; color: #6d28d9; }
.d-chain .d-note { color: var(--ink); }

.d-table {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.d-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  padding: 0.35rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  align-items: baseline;
}

.d-cell.d-case { color: #6d28d9; font-weight: 600; }
.d-cell.d-form { font-weight: 700; color: var(--ink); }
.d-cell.d-gloss { color: var(--muted); }

.d-incomplete {
  margin: 0.75rem 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  color: #b45309;
  background: var(--accent-soft);
  border: 1px solid #fcd9a8;
  border-radius: 8px;
}

.d-credit {
  margin-top: 1.25rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  font-family: "Athiti", "Niramit", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.d-credit a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.d-credit a:hover { text-decoration: underline; }

.dict-card {
  padding: 0.9rem 1rem;
  margin-bottom: 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.dict-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.2rem;
}

.dict-desc {
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.55;
}

.dict-link {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.dict-link:hover { text-decoration: underline; }

.root-card {
  padding: 0.9rem 1rem;
  margin-bottom: 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.root-card .d-text:first-child {
  margin-top: 0.15rem;
}

.root-card .d-text:last-child {
  margin-bottom: 0;
}

.root-cat {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #0f766e;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  margin-bottom: 0.4rem;
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }

  .side {
    position: static;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 1rem;
    gap: 0.85rem;
  }

  .summary-results {
    flex: none;
    max-height: 38vh;
  }

  .main-pane {
    padding: 1rem;
  }

  .thai-lemma { font-size: 1.3rem; }
  .entry { padding: 1rem; }

  .help-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .entry,
  .summary,
  .empty,
  .loading,
  .spinner,
  .modal,
  .modal-overlay {
    animation: none;
  }

  .entry,
  .source-btn,
  .root-btn,
  .summary {
    transition: none;
  }
}