:root {
  --bg: #161221;
  --bg2: #1f1930;
  --bg3: #2a2240;
  --line: #3a3155;
  --text: #efeaff;
  --dim: #a79fc4;
  --accent: #a78bfa;
  --accent-strong: #7c4dff;
  --red: #ff6b6b;
  --green: #4ade80;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  gap: 10px;
}
.topbar-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
select#languageSelect {
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 8px; font-size: 14px; max-width: 46vw;
}
.iconbtn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; font-size: 15px; cursor: pointer;
}
.iconbtn:hover { background: var(--line); }

/* ---------- Layout ---------- */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 360px; min-width: 300px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; background: var(--bg2); min-height: 0;
}
.detail { flex: 1; min-width: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.detail-content { max-width: 780px; margin: 0 auto; padding: 20px 18px calc(env(safe-area-inset-bottom) + 30px); }
.back { display: none; }

/* ---------- Tabs & panels ---------- */
.tabs { display: flex; gap: 6px; padding: 10px 14px 4px; }
.tab {
  flex: 1; padding: 7px 0; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--dim); font-size: 14px; cursor: pointer;
}
.tab.active { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
.panel { padding: 10px 14px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.panel-title { font-size: 13px; font-weight: 600; color: var(--dim); }
input, textarea {
  width: 100%; background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
  font-size: 15px; font-family: inherit; resize: vertical;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
button.primary {
  background: var(--accent-strong); color: #fff; border: none; border-radius: 8px;
  padding: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
}
button.primary:disabled { opacity: 0.55; cursor: default; }
button.primary:not(:disabled):hover { filter: brightness(1.1); }
.error { color: var(--red); font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.error:empty, .saved:empty { display: none; }
.saved { color: var(--green); font-size: 13px; }
.hint { color: var(--dim); font-size: 12.5px; line-height: 1.45; }

/* ---------- List ---------- */
.listwrap { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px 0 0; }
.search { width: calc(100% - 28px); margin: 0 14px 6px; }
.count { color: var(--dim); font-size: 12px; padding: 0 14px 6px; }
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 8px calc(env(safe-area-inset-bottom) + 10px); }
.letterbar {
  background: rgba(167, 139, 250, 0.22); color: var(--text);
  text-align: center; font-weight: 700; font-size: 14px;
  border-radius: 7px; padding: 4px 0; margin: 8px 6px 4px;
}
.row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin: 2px 6px; border-radius: 9px; cursor: pointer;
}
.row:hover { background: var(--bg3); }
.row.selected { background: var(--accent-strong); }
.row.selected .row-sub { color: rgba(255,255,255,0.75); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; }
.row-sub { color: var(--dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-del { background: none; border: none; color: var(--dim); font-size: 15px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.row-del:hover { color: var(--red); background: rgba(255,107,107,0.12); }
.empty { color: var(--dim); text-align: center; padding: 40px 20px; font-size: 14px; line-height: 1.5; }
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; }

/* ---------- Detail content ---------- */
.word-title { font-size: 32px; font-weight: 800; margin: 4px 0 2px; word-break: break-word; }
.word-meta { color: var(--dim); font-size: 13px; margin-bottom: 14px; }
.rtl { direction: rtl; text-align: right; }
.sectionbox {
  background: rgba(255,255,255,0.045); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 16px;
}
.sectionbox h3 {
  margin: 0 0 10px; font-size: 12px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--dim); font-weight: 700;
}
.rich { line-height: 1.55; font-size: 15px; white-space: normal; }
.rich b { font-weight: 700; }
.example { display: flex; gap: 10px; margin: 12px 0; }
.exnum {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.08); color: var(--dim);
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.excol { flex: 1; min-width: 0; }
.sentence { margin: 0 0 5px; line-height: 1.65; font-size: 16.5px; }
.sentence.bigscript { font-size: 20px; line-height: 1.8; }
.translation { color: var(--dim); font-size: 14px; line-height: 1.5; }
.w { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.w:hover, .w:active { background: rgba(167,139,250,0.28); }
.taphint { color: var(--dim); font-size: 12px; margin: 0 0 6px; }
.pairline { display: flex; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; margin-bottom: 8px; }
.pairline .arrow { color: var(--dim); font-weight: 400; }
.pairline .tint { color: var(--accent); }

/* Pronunciation */
.pron-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.pron-row input { flex: 1; }
.pron-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pron-buttons button {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; cursor: pointer;
}
.pron-buttons button.rec { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.pron-buttons button.danger { color: var(--red); }
.recdot { color: var(--red); font-size: 13px; animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Comparison table */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.cmp { border-collapse: collapse; min-width: 100%; }
table.cmp th, table.cmp td {
  text-align: left; vertical-align: top; padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.45;
  min-width: 130px; max-width: 240px;
}
table.cmp th { color: var(--text); font-weight: 700; }
table.cmp td.aspect { color: var(--dim); font-weight: 600; min-width: 110px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 14px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 16px;
  width: min(680px, 100%); max-height: min(86dvh, 900px);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 9px; }
.modal-foot { padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid var(--line); }
.modal-foot button { width: 100%; }
.preview { margin-top: 4px; }
.preview .word-title { font-size: 24px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--dim); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); }
.check input { width: auto; }
hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; width: 100%; }
.row-buttons { display: flex; gap: 8px; }
.row-buttons button {
  flex: 1; background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px; font-size: 14px; cursor: pointer;
}
.lg-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.spin::after { content: "…"; animation: pulse 1s infinite; }

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .sidebar { width: 100%; min-width: 0; border-right: none; }
  .detail {
    position: fixed; inset: 0; background: var(--bg); z-index: 20;
    transform: translateX(100%); transition: transform 0.22s ease;
    padding-top: env(safe-area-inset-top);
  }
  .app.show-detail .detail { transform: translateX(0); }
  .back {
    display: block; background: none; border: none; color: var(--accent);
    font-size: 16px; padding: 12px 14px 0; cursor: pointer; text-align: left;
  }
  select#languageSelect { max-width: 34vw; }
}

/* ================= Cloud version additions ================= */

/* ---------- Auth screen ---------- */
.auth {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 700px at 70% -10%, #2a2240 0%, var(--bg) 55%);
  padding: 18px;
}
.auth-card {
  width: min(400px, 100%);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 24px calc(env(safe-area-inset-bottom) + 24px);
  display: flex; flex-direction: column; gap: 10px; text-align: center;
}
.auth-logo { width: 64px; height: 64px; border-radius: 15px; margin: 0 auto; }
.auth-card h1 { margin: 4px 0 0; font-size: 24px; }
.auth-sub { color: var(--dim); font-size: 13.5px; line-height: 1.5; margin: 0 0 6px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #1a1a1a; border: none; border-radius: 9px;
  padding: 11px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.google-btn:hover { filter: brightness(0.95); }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 12px; margin: 4px 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.auth-buttons { display: flex; gap: 8px; }
.auth-buttons button { flex: 1; }
.auth-buttons button:not(.primary) {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px; font-size: 15px; cursor: pointer;
}
.auth-msg { color: var(--accent); font-size: 13px; min-height: 18px; white-space: pre-wrap; }
.loading-dot {
  width: 34px; height: 34px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spinround 0.9s linear infinite;
}
@keyframes spinround { to { transform: rotate(360deg); } }

/* ---------- Account box in Settings ---------- */
.account-box {
  background: rgba(255,255,255,0.045); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; }
.account-row span:first-child { overflow: hidden; text-overflow: ellipsis; }
.badge {
  flex: none; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--line); color: var(--dim);
}
.badge.premium { background: rgba(250, 204, 21, 0.16); border-color: #b8860b; color: #fbd75b; }
button.gold {
  background: linear-gradient(135deg, #f6c453, #e0972f); color: #2a1c00;
  border: none; border-radius: 8px; padding: 9px; font-size: 14px; font-weight: 700; cursor: pointer;
}
button.gold:hover { filter: brightness(1.06); }
#migrateBtn {
  background: var(--bg3); border: 1px dashed var(--accent); color: var(--accent);
  border-radius: 8px; padding: 9px; font-size: 13.5px; cursor: pointer;
}

/* ---------- Paywall ---------- */
.pay-reason { font-size: 14.5px; line-height: 1.5; }
.pay-price { display: flex; align-items: baseline; gap: 10px; margin: 2px 0; }
.pay-price span:first-child { font-size: 34px; font-weight: 800; color: #fbd75b; }
.pay-once { color: var(--dim); font-size: 13px; }
.pay-perks { margin: 0 0 4px; padding-left: 20px; color: var(--text); font-size: 14px; line-height: 1.7; }
button.primary.alt { background: #2563eb; }

/* ---------- Sharing ---------- */
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; }
.share-row button { flex: none; padding: 9px 16px; }
.row-del.view { color: var(--accent); font-size: 13px; border: 1px solid var(--line); }

/* ---------- Shared glossary viewer ---------- */
.modal.wide { width: min(820px, 100%); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--bg3); border: 1px solid var(--line); color: var(--dim);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
.sv-list .row { margin: 2px 0; }

/* Keep the quick look-up modal above the shared viewer */
.modal-backdrop.ontop { z-index: 60; }
