:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #182230;
  --muted: #5f6f82;
  --border: #dbe4ee;
  --primary: #0b6efd;
  --primary-dark: #0858ca;
  --primary-soft: #e7f1ff;
  --success: #1f9d55;
  --warning: #f59f00;
  --danger: #dc3545;
  --ad-bg: #fff8e6;
  --ad-border: #f0d48a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.04);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 180px);
  color: var(--text);
  min-height: 100vh;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 12px auto;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(219, 228, 238, 0.7);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Ad banners */
.ad-banner {
  background: var(--ad-bg);
  border-bottom: 1px solid var(--ad-border);
  padding: 8px 12px;
}
.ad-bottom {
  border-bottom: 0;
  border-top: 1px solid var(--ad-border);
}
.ad-label {
  font-size: 11px;
  font-weight: 700;
  color: #8a6a00;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.ad-content {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-placeholder {
  width: min(100%, 728px);
  min-height: 50px;
  border: 1px dashed #d4b106;
  background: #fffdf5;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  color: #6b5600;
}
.ad-placeholder p { margin: 2px 0 0; font-size: 12px; color: #8a7420; }
.ad-badge {
  background: #f59f00;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #4dabf7);
  color: white; display: grid; place-items: center;
  font-size: 22px; font-weight: 800;
  box-shadow: 0 8px 20px rgba(11, 110, 253, 0.3);
}
.brand h1 { margin: 0; font-size: 1.5rem; line-height: 1.1; }
.brand-sub { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.header-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.status-pill {
  font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px;
  background: #e8f7ee; color: #18794e;
}
.status-pill.offline { background: #fdebec; color: #b42318; }

/* Tabs */
.tab-nav {
  display: flex; gap: 8px; padding: 0 20px 16px; overflow-x: auto;
}
.tab-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 10px 14px; border-radius: 10px; font-weight: 600; white-space: nowrap;
}
.tab-btn.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.tab-btn:hover:not(.active) { background: var(--surface-alt); color: var(--text); }

/* Main */
.main-content { padding: 0 20px 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 16px;
}
.panel-header h2 { margin: 0 0 4px; font-size: 1.3rem; }
.panel-header p, .muted { margin: 0; color: var(--muted); }
.muted { font-size: 0.88rem; }

/* Cards & layout */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,24,40,0.02);
}
.card-header {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h3 { margin: 0; font-size: 1rem; }
.count-badge {
  background: var(--primary-soft); color: var(--primary-dark);
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
}
.content-grid {
  display: grid; grid-template-columns: 1.7fr 1fr; gap: 16px; margin-top: 16px;
}
.modules-grid { margin-top: 0; }

/* Search */
.search-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.search-row { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 0.85rem; font-weight: 600; color: #334155; }
.field input, .field select {
  width: 100%; padding: 12px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text);
}
.field input:focus, .field select:focus {
  outline: 2px solid rgba(11,110,253,0.15); border-color: var(--primary);
}
.search-meta {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 12px;
  font-size: 0.88rem; color: var(--muted);
}

/* Results */
.results-list, .history-list, .module-list { padding: 12px; }
.result-item, .history-item, .module-item {
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #fff;
}
.result-item + .result-item, .history-item + .history-item, .module-item + .module-item { margin-top: 10px; }
.result-item { cursor: pointer; transition: border-color .15s, transform .15s; }
.result-item:hover { border-color: #9ec5fe; transform: translateY(-1px); }
.result-item.selected { border-color: var(--primary); background: #f7fbff; }
.result-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.result-lemma { font-size: 1.02rem; font-weight: 700; margin: 0; }
.result-meta { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.result-def { margin: 8px 0 0; color: #334155; font-size: 0.92rem; line-height: 1.5; }
.module-tag {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: #eef4ff; color: #3b5bdb; white-space: nowrap;
}
.empty-state { padding: 24px 12px; text-align: center; color: var(--muted); }
.empty-state.small { padding: 12px; font-size: 0.9rem; }

/* Detail */
.detail-card { padding: 20px; min-height: 280px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.detail-head h3 { margin: 0; font-size: 2rem; line-height: 1.1; }
.detail-pron { color: var(--muted); margin-top: 6px; font-size: 0.95rem; }
.sense { padding: 14px 0; border-top: 1px solid var(--border); }
.sense:first-of-type { border-top: 0; padding-top: 0; }
.sense-title { font-weight: 700; color: #243b53; margin-bottom: 6px; font-size: 0.92rem; }
.sense p { margin: 0; line-height: 1.65; }
.example {
  margin-top: 10px; padding: 10px 12px; background: #f8fafc; border-radius: 10px;
  color: #475569; font-size: 0.92rem;
}
.relations { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.rel-chip {
  padding: 5px 10px; border-radius: 999px; background: #f1f5f9; color: #334155;
  font-size: 12px; font-weight: 500;
}
.detail-etymology {
  margin: 12px 0 16px; padding: 10px 12px; background: #fff8e6; border: 1px solid #f0d48a;
  border-radius: 10px; color: #6b5600; font-size: 0.92rem; line-height: 1.5;
}
.detail-examples { margin-top: 14px; color: #334155; font-size: 0.92rem; }
.detail-examples ul { margin: 8px 0 0 18px; padding: 0; }
.detail-examples li { margin: 6px 0; line-height: 1.5; }

/* Modules */
.module-item { display: flex; flex-direction: column; gap: 10px; }
.module-top { display: flex; justify-content: space-between; gap: 12px; }
.module-name { font-weight: 700; margin: 0; }
.module-info { font-size: 0.84rem; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.module-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.module-status { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: #eef2f7; color: #475569;
}
.pill.active { background: #e8f7ee; color: #18794e; }
.pill.update { background: #fff4db; color: #9a6700; }
.pill.required { background: #fdebec; color: #b42318; }

/* Buttons */
.primary-btn, .ghost-btn, .danger-btn {
  border-radius: 10px; padding: 10px 14px; font-weight: 600; border: 1px solid transparent;
}
.primary-btn { background: var(--primary); color: #fff; }
.primary-btn:hover:not(:disabled) { background: var(--primary-dark); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ghost-btn { background: #fff; color: var(--text); border-color: var(--border); }
.ghost-btn:hover { background: var(--surface-alt); }
.ghost-btn.small { padding: 6px 10px; font-size: 0.82rem; }
.danger-btn { background: #fff; color: var(--danger); border-color: #f1c0c4; }
.danger-btn:hover { background: #fff5f5; }

.notice {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 0.92rem;
  background: #eef6ff; color: #0b5394; border: 1px solid #cfe2ff;
}
.notice.warn { background: #fff8e6; color: #8a6100; border-color: #ffe69c; }
.notice.error { background: #fdebec; color: #b42318; border-color: #f5c2c7; }
.hidden { display: none !important; }

.history-item { cursor: pointer; padding: 10px 12px; }
.history-item:hover { background: #f8fafc; }
.history-query { font-weight: 600; font-size: 0.92rem; }
.history-time { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px; background: #1f2937; color: #fff; border-radius: 12px;
  font-size: 0.9rem; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .content-grid, .search-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .app-shell { width: calc(100% - 12px); margin: 6px auto; border-radius: 16px; }
  .app-header, .tab-nav, .main-content { padding-left: 14px; padding-right: 14px; }
  .app-header { flex-direction: column; align-items: stretch; }
  .header-status { justify-content: flex-start; }
  .panel-header { flex-direction: column; align-items: stretch; }
  .detail-head h3 { font-size: 1.6rem; }
  .search-meta { flex-direction: column; }
}