:root {
  --bg: #0b1220;
  --bg2: #152033;
  --bg3: #243044;
  --card: #152033;
  --text: #f4f7fb;
  --muted: #93a0b5;
  --accent: #2ee6c7;
  --accent-ink: #06231e;
  --vi: #5eead4;
  --th: #fbbf24;
  --en: #c4b5fd;
  --danger: #fb7185;
  --ok: #34d399;
  --border: #2a3a52;
  --radius: 16px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Noto Sans Thai",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background:
    radial-gradient(900px 420px at 10% -10%, #134e4a55, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100%;
  font-size: 16px;
  line-height: 1.45;
}
body { padding-bottom: calc(12px + var(--safe-bottom)); }
button, input, textarea { font: inherit; color: inherit; }
button {
  min-height: var(--tap);
  border: none; border-radius: 12px;
  padding: 0 16px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary { background: var(--bg3); color: var(--text); }
button.danger { background: var(--danger); color: #1a0a0e; }
button.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  min-height: 40px;
}
input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0d1726;
  outline: none;
}
input:focus { border-color: var(--accent); }

.app { max-width: 560px; margin: 0 auto; padding: 12px 14px calc(104px + var(--safe-bottom)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 12px; padding-top: 6px;
}
.topbar h1 { font-size: 1.35rem; margin: 0; letter-spacing: 0.02em; }
.lede { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.user-line {
  font-size: 0.8rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 220px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.hint { color: var(--muted); font-size: 0.85rem; margin: 12px 0 0; }

.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 0.82rem; color: var(--muted);
  margin-bottom: 6px;
}
.row { display: flex; gap: 8px; }
.row.actions { margin-top: 4px; }
.row.actions button { flex: 1; }

.hidden { display: none !important; }
.msg {
  padding: 10px 12px; border-radius: 10px; margin-bottom: 10px;
  font-size: 0.9rem;
}
.msg.error { background: #7f1d1d55; color: #fecaca; }
.msg.ok { background: #064e3b66; color: #a7f3d0; }
.msg.info { background: #134e4a66; color: #ccfbf1; }

.segments {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 10px;
}
.segments button {
  min-height: 40px;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 0 4px;
  font-size: 0.92rem;
}
.segments button.active { background: var(--accent); color: var(--accent-ink); }

.cat-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  margin: 0 -2px 2px;
  scrollbar-width: none;
}
.cat-row::-webkit-scrollbar { display: none; }
.cat-row button {
  flex: 0 0 auto;
  min-height: 36px;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 650;
}
.cat-row button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.cat-count {
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  opacity: 0.72;
}

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}
.hide-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 0.92rem; font-weight: 650;
}
.hide-toggle input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.stats { color: var(--muted); font-size: 0.8rem; text-align: right; }

.search-bar { margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
}
.item.vi { box-shadow: inset 3px 0 0 var(--vi); }
.item.th { box-shadow: inset 3px 0 0 var(--th); }
.item.en { box-shadow: inset 3px 0 0 var(--en); }
.item.flash { border-color: var(--accent); box-shadow: 0 0 0 2px #2ee6c788; }
.item-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.cn, .target, .lang-text, .phonetic, .lang-ph, .lang-roman, .lang-hint { overflow-wrap: anywhere; }
.cn { font-size: 1.05rem; font-weight: 750; }
.badge {
  font-size: 0.72rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 8px; white-space: nowrap;
}
.badge.mine { color: var(--accent); border-color: #115e59; }
.target {
  margin-top: 6px;
  font-size: 1.28rem;
  font-weight: 750;
  letter-spacing: 0.01em;
}
.item.vi .target { color: var(--vi); }
.item.th .target { color: var(--th); }
.item.en .target { color: var(--en); }
.phonetic { color: var(--muted); font-size: 0.92rem; margin-top: 2px; }
.lang-roman {
  margin-top: 3px;
  font-weight: 500;
  font-size: 0.84rem;
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: #9aabbf;
}
.lang-hint {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}
.hint-label {
  display: inline-block;
  margin-right: 6px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: #8aa0b8;
}
.actions-line {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px;
}

.lang-row {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid #223049;
}
.lang-tag {
  font-size: 0.78rem; font-weight: 800; color: var(--muted);
}
.lang-tag.vi { color: var(--vi); }
.lang-tag.th { color: var(--th); }
.lang-tag.en { color: var(--en); }
.lang-main { min-width: 0; }
.lang-text {
  font-size: 1.22rem;
  font-weight: 750;
  line-height: 1.25;
  color: var(--text);
  word-break: break-word;
}
.lang-ph { color: var(--muted); font-size: 0.82rem; }
.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (max-width: 380px) {
  .field-pair { grid-template-columns: 1fr; }
}
.lang-actions { display: flex; gap: 6px; }

.icon-btn, .know {
  min-height: 36px; min-width: 36px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--bg3);
  color: var(--text);
  font-weight: 700;
  font-size: 0.82rem;
}
.icon-btn { width: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.know.on { background: #065f46; color: #d1fae5; }
.icon-btn svg { width: 18px; height: 18px; display: block; }
.linkish {
  min-height: 32px;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-size: 0.82rem;
}

.empty {
  text-align: center; color: var(--muted);
  padding: 36px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty button { margin-top: 12px; }

.auth-wrap {
  min-height: 70vh; display: flex; flex-direction: column;
  justify-content: center;
}
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs button { flex: 1; background: var(--bg3); color: var(--muted); }
.tabs button.active { background: var(--accent); color: var(--accent-ink); }

.fab {
  position: fixed;
  right: max(18px, calc((100vw - 560px) / 2 + 18px));
  bottom: calc(18px + var(--safe-bottom));
  z-index: 20;
  width: 56px;
  height: 56px;
  min-height: 56px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  line-height: 1;
  box-shadow: 0 8px 20px #00000055;
}

.modal-backdrop {
  position: fixed; inset: 0; background: #000a;
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal {
  width: 100%; max-width: 560px;
  max-height: 92vh; overflow: auto;
  background: #121c2e;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  border: 1px solid var(--border);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.dup-box {
  background: #7f1d1d44;
  border: 1px solid #fb718566;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.dup-box p { margin: 0 0 10px; color: #fecaca; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 28px));
  background: #1f2937; color: #e5e7eb;
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 80;
  box-shadow: 0 10px 30px #0008;
  font-size: 0.92rem;
}

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid #06231e55; border-top-color: #06231e;
  border-radius: 50%; animation: spin 0.7s linear infinite;
  vertical-align: -3px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 20px; max-height: 86vh; }
}
