:root {
  color-scheme: light;
  --accent: #2e8bf5;
  --ink: #14161a;
  --text: #4b5361;
  --muted: #a6adb8;
  --line: #e3e6eb;
  --surface: #fff;
  --canvas: #f7f8fa;
  font-family: Newsreader, Georgia, serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; background: var(--canvas); color: var(--ink); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { width: 0; height: 0; }
.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; }
.app-shell { display: flex; height: 100dvh; min-height: 0; background: var(--canvas); }
.loading-state, .fatal-error, .empty-detail { margin: auto; padding: 32px; color: var(--text); text-align: center; }
.fatal-error h1 { font-size: 26px; }
.fatal-error code { font-family: "JetBrains Mono", monospace; font-size: 0.9em; }

.sidebar { flex: 0 0 clamp(296px, 31vw, 392px); display: flex; min-width: 0; flex-direction: column; background: var(--surface); border-right: 1px solid #e7eaee; }
.sidebar-header { padding: 30px 24px 0; }
.brand-row h1 { margin: 0; font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.brand-row p { margin: 8px 0 0; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 9.5px; font-weight: 500; letter-spacing: 0.24em; text-transform: uppercase; color: var(--muted); }
.search-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.icon-button, .star-button { display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; background: transparent; cursor: pointer; }
.icon-button:hover, .star-button:hover { opacity: 0.6; }
.search-field { position: relative; flex: 1; }
.search-field input { width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; background: #fbfcfd; color: var(--ink); font-size: 16.5px; }
.search-field input:focus { border-color: #9fc8f7; box-shadow: 0 0 0 3px rgb(46 139 245 / 12%); }
.search-field input::-webkit-search-cancel-button { opacity: 0.55; }

.filters { display: flex; flex-wrap: wrap; gap: 7px; max-height: 116px; margin: 14px 0 8px; padding: 0 24px 8px; overflow: auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.pill { flex: 0 0 auto; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: #3c4451; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 12px; font-weight: 500; cursor: pointer; }
.pill:hover { border-color: #c9d0da; }
.pill.active { border-color: var(--accent); background: var(--accent); color: #fff; }

.term-list { flex: 1; display: flex; min-height: 0; flex-direction: column; gap: 4px; overflow-y: auto; padding: 2px 16px 32px; }
.term-card-wrap { position: relative; flex: 0 0 auto; overflow: hidden; border-radius: 12px; }
.term-card { position: relative; padding: 12px 14px 13px; border-left: 3px solid transparent; border-radius: 12px; background: var(--surface); cursor: pointer; touch-action: pan-y; }
.term-card:hover { background: #f4f6f9; }
.term-card.selected { border-left-color: var(--accent); background: #eef3f9; }
.term-card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.card-heading { display: flex; align-items: baseline; gap: 8px; padding-right: 28px; }
.card-heading h2 { margin: 0; font-size: 18.5px; font-weight: 700; letter-spacing: -0.01em; }
.card-heading span { overflow: hidden; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 9.5px; letter-spacing: 0.07em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.term-card p { display: -webkit-box; margin: 3px 0 0; padding-right: 54px; overflow: hidden; color: #5b6371; font-size: 14.5px; line-height: 1.4; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.term-card .star-button { position: absolute; top: 11px; right: 11px; }
.remove-small { position: absolute; right: 12px; bottom: 10px; display: none; padding: 0; border: 0; background: transparent; color: #b0b7c1; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 11px; cursor: pointer; }
.term-card:hover .remove-small, .remove-small:focus-visible { display: block; }
.remove-small:hover { color: #f45da0; }
.remove-action { position: absolute; inset: 0 0 0 auto; width: 96px; border: 0; border-radius: 12px; background: #f45da0; color: #fff; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 13px; cursor: pointer; }
.empty-list { padding: 32px 8px; color: #97a0ac; font-size: 15px; text-align: center; }

.detail { flex: 1; min-width: 0; overflow-y: auto; background: var(--canvas); }
.detail-inner { max-width: 872px; margin: 0 auto; padding: clamp(32px, 5vw, 56px) clamp(24px, 5vw, 56px) 120px; }
.detail-meta-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 10.5px; letter-spacing: 0.09em; text-transform: uppercase; }
.desktop-navigation { display: flex; gap: 8px; text-transform: none; letter-spacing: normal; }
.desktop-navigation button { max-width: 190px; overflow: hidden; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: #5b6371; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.desktop-navigation button:hover { border-color: #c9d0da; }
.desktop-title-row { display: flex; align-items: center; gap: 14px; }
.desktop-title-row h2 { margin: 0; font-size: clamp(42px, 5vw, 54px); font-weight: 700; line-height: 1.05; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.star-button.static { position: static; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 26px; padding: 22px 0 18px; border-bottom: 1px solid #e7eaee; }
.tabs .pill { padding: 6px 15px; font-size: 12.5px; }
.detail-content { animation: content-in 0.18s ease both; }
.content-section { margin-bottom: 34px; }
.content-section h3 { margin: 0 0 10px; font-size: 22px; letter-spacing: -0.01em; }
.content-section p { margin: 0 0 10px; color: var(--text); font-size: 18px; line-height: 1.55; text-wrap: pretty; }
.content-section.lead p { color: var(--ink); }
.content-section.practice p::before { content: "→ "; color: var(--accent); }
.content-section.warning p { color: #8a6a2f; }
.related-list { display: flex; flex-direction: column; gap: 9px; }
.related-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
.related-item:hover { border-color: #b9cbe0; }
.related-item strong { display: block; color: var(--ink); font-size: 17px; }
.related-item small { display: block; margin-top: 3px; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 11px; }
.related-item > span:last-child { flex: 0 0 auto; padding-top: 3px; color: var(--accent); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 11.5px; }
.empty-tab { max-width: 560px; padding: 24px; border: 1px dashed #d8dce3; border-radius: 14px; color: #7a8492; background: rgb(255 255 255 / 48%); }
.empty-tab strong { color: var(--ink); font-size: 19px; }
.empty-tab p { margin: 6px 0 0; font-size: 16px; line-height: 1.45; }
.mobile-detail-bar, .mobile-term-navigation { display: none; }

@keyframes content-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

@media (max-width: 767px) {
  body { overflow: hidden; }
  .app-shell { display: block; }
  .sidebar { width: 100%; height: 100%; max-width: 560px; margin: 0 auto; border: 0; background: var(--canvas); }
  .sidebar.mobile-hidden { display: none; }
  .sidebar-header { padding: calc(env(safe-area-inset-top, 0px) + 24px) 16px 0; }
  .brand-row { text-align: center; }
  .brand-row h1 { font-size: 27px; line-height: 1; }
  .brand-row p { margin-top: 8px; }
  .search-row { gap: 10px; margin-top: 20px; }
  .search-field input { padding: 9px 14px; background: var(--surface); font-size: 16px; text-align: center; }
  .filters { flex-wrap: nowrap; max-height: none; margin: 12px 0 8px; padding: 0 16px 8px; overflow-x: auto; }
  .filters .pill { font-size: 12.5px; }
  .term-list { gap: 11px; padding: 2px 16px calc(44px + env(safe-area-inset-bottom, 0px)); }
  .term-card-wrap { border-radius: 14px; }
  .term-card { min-height: 82px; padding: 13px 44px 14px 15px; border: 1px solid #eceef2; border-radius: 14px; box-shadow: 0 1px 2px rgb(16 24 40 / 4%); transition: transform 0.22s cubic-bezier(0.2,0.8,0.2,1); }
  .term-card.selected { border-color: #dce6f2; }
  .card-heading h2 { font-size: 21px; }
  .card-heading span { font-size: 10px; }
  .term-card p { margin-top: 4px; padding-right: 0; font-size: 15.5px; line-height: 1.42; }
  .remove-small { display: none !important; }
  .remove-action { border-radius: 14px; }

  .detail { display: none; width: 100%; height: 100%; max-width: 560px; margin: 0 auto; }
  .detail.mobile-visible { display: block; animation: content-in 0.22s ease both; }
  .detail-inner { min-height: 100%; padding: calc(env(safe-area-inset-top, 0px) + 16px) 0 calc(32px + env(safe-area-inset-bottom, 0px)); }
  .mobile-detail-bar { display: flex; align-items: center; padding: 4px 16px 2px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
  .mobile-detail-bar strong { flex: 1; font-family: Newsreader, Georgia, serif; font-size: 17px; text-align: center; }
  .back-button { width: 34px; padding: 0; border: 0; background: transparent; color: var(--ink); font-size: 28px; line-height: 1; cursor: pointer; }
  .mobile-detail-bar .star-button { width: 34px; justify-content: flex-end; }
  .detail-meta-row, .desktop-title-row { display: none; }
  .mobile-term-navigation { position: relative; display: flex; align-items: center; justify-content: center; height: 54px; overflow: hidden; }
  .mobile-term-navigation h2 { max-width: calc(100% - 184px); margin: 0; overflow: hidden; font-size: 27px; font-weight: 700; letter-spacing: -0.015em; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-term-navigation button { position: absolute; max-width: 88px; overflow: hidden; padding: 0; border: 0; background: transparent; color: #d8dce3; font-size: 22px; font-weight: 700; text-overflow: clip; white-space: nowrap; cursor: pointer; }
  .mobile-term-navigation button:first-child { left: -2px; text-align: left; }
  .mobile-term-navigation button:last-child { right: -2px; text-align: right; }
  .tabs { flex-wrap: nowrap; gap: 7px; margin: 0; padding: 8px 16px 12px; overflow-x: auto; border-bottom: 1px solid #eaeef0; white-space: nowrap; }
  .tabs .pill { padding: 5px 13px; }
  .detail-content { padding: 14px 16px 32px; }
  .content-section { margin-bottom: 20px; }
  .content-section h3 { margin-bottom: 5px; font-size: 19px; }
  .content-section p { margin-bottom: 7px; font-size: 16px; line-height: 1.45; }
  .related-item { padding: 12px 13px; }
  .empty-tab { padding: 18px; }
}

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