/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* ── Variables ── */
:root {
  --black:   #000;
  --bg:      #0d0d0d;
  --bg2:     #141414;
  --bg3:     #1c1c1c;
  --line:    #2a2a2a;
  --line2:   #333;
  --dim:     #555;
  --muted:   #888;
  --sub:     #bbb;
  --text:    #e8e8e8;
  --white:   #fff;
  --radius:  10px;
  --r-sm:    6px;
  --header:  52px;
  --input-h: 64px;
  --drawer:  220px;
}

/* ── Body ── */
body {
  font-family: -apple-system, 'SF Pro Text', 'Segoe UI', 'PingFang SC', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Overlay ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 90;
}
.hidden { display: none !important; }

/* ── Settings Panel ── */
.settings-panel {
  position: fixed; top: 0; right: 0;
  width: min(360px, 100vw);
  height: 100dvh;
  background: var(--bg2);
  border-left: 1px solid var(--line);
  z-index: 100;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 4px;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.sp-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .9rem; font-weight: 600; color: var(--white);
  margin-bottom: 16px;
}
.sp-section { margin-bottom: 16px; }
.sp-row { display: flex; justify-content: space-between; align-items: center; }
.sp-label {
  font-size: .72rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 6px;
}
.sp-section input,
.sp-section select {
  width: 100%;
  background: var(--bg3); border: 1px solid var(--line2);
  border-radius: var(--r-sm); padding: 9px 12px;
  color: var(--text); font-size: .9rem; outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}
.sp-section input:focus,
.sp-section select:focus { border-color: var(--white); }
.sp-section select { cursor: pointer; }
.sp-save {
  margin-top: 8px; padding: 11px;
  background: var(--white); color: var(--black);
  border: none; border-radius: var(--r-sm);
  font-size: .9rem; font-weight: 700; cursor: pointer;
  transition: opacity .15s;
}
.sp-save:hover { opacity: .85; }

/* Toggle */
.toggle { display: flex; align-items: center; cursor: pointer; }
.toggle input { display: none; }
.toggle-track {
  width: 40px; height: 22px;
  background: var(--line2); border-radius: 11px;
  position: relative; transition: background .2s;
}
.toggle-track::after {
  content: ''; position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: var(--muted); border-radius: 50%;
  transition: transform .2s, background .2s;
}
.toggle input:checked + .toggle-track { background: var(--white); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); background: var(--black); }

/* ── Header ── */
header {
  height: var(--header);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  position: relative; z-index: 10;
}
.logo {
  font-size: 1.25rem; font-weight: 800;
  color: var(--white); letter-spacing: -.02em;
}
.header-right { display: flex; gap: 6px; }

/* ── Buttons ── */
.icon-btn {
  background: none; border: none;
  color: var(--muted); font-size: 1rem; cursor: pointer;
  padding: 6px 8px; border-radius: var(--r-sm);
  transition: color .15s, background .15s;
  line-height: 1;
}
.icon-btn:hover { color: var(--white); background: var(--bg3); }
.icon-btn.dim { font-size: .9rem; }

/* ── App Body ── */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── History Drawer ── */
.history-drawer {
  width: var(--drawer);
  min-width: var(--drawer);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 14px 10px;
  overflow: hidden;
  transition: width .2s;
}
.drawer-title {
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--dim); margin-bottom: 10px; padding: 0 4px;
}
#historyList {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.h-item {
  padding: 7px 8px; border-radius: var(--r-sm);
  font-size: .82rem; color: var(--muted); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .12s, background .12s;
}
.h-item:hover { color: var(--white); background: var(--bg3); }
.list-cmd {
  margin-top: 10px;
  background: none; border: 1px solid var(--line2);
  border-radius: var(--r-sm); padding: 8px;
  color: var(--dim); font-size: .78rem;
  font-family: monospace; cursor: pointer;
  transition: color .15s, border-color .15s;
  text-align: left;
}
.list-cmd:hover { color: var(--white); border-color: var(--muted); }
.dim-text { font-size: .82rem; color: var(--dim); padding: 4px; }

/* ── Content ── */
.content {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

/* ── Output ── */
.output {
  flex: 1; overflow-y: auto;
  padding: 28px 24px 16px;
}

/* ── Welcome ── */
.welcome { padding: 40px 0 20px; }
.welcome-title {
  font-size: 2rem; font-weight: 800;
  color: var(--white); letter-spacing: -.04em;
  margin-bottom: 4px;
}
.welcome-sub { font-size: .9rem; color: var(--muted); margin-bottom: 28px; }
.welcome-tips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.tip {
  font-size: .8rem; color: var(--sub);
  background: var(--bg3); border: 1px solid var(--line);
  border-radius: 20px; padding: 4px 12px;
}
.tip code {
  background: none; color: var(--white);
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: .8rem;
}

/* ── Input Bar ── */
.input-bar {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}
textarea {
  flex: 1;
  background: var(--bg3); border: 1px solid var(--line2);
  border-radius: var(--radius); color: var(--text);
  font-size: .95rem; font-family: inherit;
  padding: 12px 14px; resize: none; outline: none;
  line-height: 1.5; max-height: 160px;
  transition: border-color .15s;
  overflow-y: auto;
}
textarea:focus { border-color: var(--white); }
textarea::placeholder { color: var(--dim); }
.send-btn {
  width: 42px; height: 42px; flex-shrink: 0;
  background: var(--white); border: none;
  border-radius: var(--r-sm); color: var(--black);
  font-size: 1.1rem; font-weight: 700; cursor: pointer;
  transition: opacity .15s; display: flex;
  align-items: center; justify-content: center;
}
.send-btn:hover { opacity: .8; }
.send-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ── Result ── */
.result { animation: fadeUp .2s ease; max-width: 760px; }
@keyframes fadeUp { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }

.r-word {
  font-size: 2.2rem; font-weight: 800;
  color: var(--white); letter-spacing: -.03em;
  margin-bottom: 6px;
}
.r-meta {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; margin-bottom: 20px;
}
.r-ipa {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .9rem; color: var(--sub);
}
.r-pos {
  font-size: .8rem; color: var(--muted);
  border: 1px solid var(--line2); border-radius: 4px;
  padding: 2px 8px; font-style: italic;
}
.r-meaning {
  font-size: 1rem; color: var(--white); font-weight: 500;
}

.speak-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.speak-pill {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg3); border: 1px solid var(--line2);
  border-radius: 20px; padding: 5px 12px;
  font-size: .82rem; color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.speak-pill:hover { color: var(--white); border-color: var(--muted); }

.block { margin-bottom: 22px; }
.block-title {
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--dim); margin-bottom: 10px;
}

/* Forms grid */
.forms-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.form-chip {
  background: var(--bg3); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 12px;
  min-width: 120px;
}
.fc-label { font-size: .68rem; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.fc-val { font-size: .9rem; color: var(--text); margin-top: 2px; }
.fc-ipa { font-size: .78rem; color: var(--muted); font-family: monospace; }

/* Root */
.root-line {
  font-size: .88rem; color: var(--sub);
  background: var(--bg3); border-left: 2px solid var(--line2);
  padding: 10px 14px; border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* Examples */
.ex-list { display: flex; flex-direction: column; gap: 8px; }
.ex-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.ex-en { font-size: .92rem; color: var(--text); line-height: 1.6; }
.ex-cn { font-size: .82rem; color: var(--muted); margin-top: 3px; }

/* Correction */
.fix-old { color: var(--dim); text-decoration: line-through; font-size: .88rem; }
.fix-new { color: var(--white); font-size: .95rem; font-weight: 600; margin-top: 4px; }
.fix-note { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* Grammar */
.gram-original {
  font-size: .9rem; color: var(--muted);
  padding: 12px 14px; border: 1px solid var(--line);
  border-radius: var(--r-sm); margin-bottom: 14px;
}
.gram-error {
  border: 1px solid #3a2a2a; background: #1a1111;
  border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 8px;
}
.gram-ok {
  border: 1px solid #1a3a1a; background: #0d1a0d;
  border-radius: var(--r-sm); padding: 12px 14px;
}
.g-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); margin-bottom: 6px; }
.g-text { font-size: .9rem; color: var(--text); }
.g-expl { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* Translation */
.trans-source {
  font-size: .82rem; color: var(--dim); margin-bottom: 14px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.trans-result {
  font-size: 1.05rem; color: var(--white);
  line-height: 1.8; padding: 14px 0;
}
.trans-option {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 14px; margin-bottom: 8px;
}
.t-num { font-size: .7rem; color: var(--dim); text-transform: uppercase; letter-spacing: .1em; margin-bottom: 6px; }
.t-text { font-size: .95rem; color: var(--white); line-height: 1.7; }
.t-style { font-size: .75rem; color: var(--muted); margin-top: 4px; }

/* Compare */
.cmp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.cmp-card {
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px;
}
.cmp-word { font-size: 1.1rem; font-weight: 700; color: var(--white); margin-bottom: 4px; }
.cmp-meaning { font-size: .82rem; color: var(--muted); margin-bottom: 8px; }
.cmp-usage { font-size: .82rem; color: var(--sub); line-height: 1.6; }
.cmp-diff {
  border-left: 2px solid var(--white);
  padding: 10px 14px; margin-bottom: 16px;
  font-size: .88rem; color: var(--sub); line-height: 1.6;
}

/* Slang */
.slang-box {
  border: 1px dashed var(--line2); border-radius: var(--r-sm);
  padding: 12px 14px;
}
.slang-meaning { font-size: .9rem; color: var(--white); margin-bottom: 4px; }
.slang-ex { font-size: .82rem; color: var(--muted); font-style: italic; }

/* Images */
.img-row { display: flex; gap: 8px; flex-wrap: wrap; }
.img-row img {
  width: 110px; height: 80px; object-fit: cover;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  filter: grayscale(20%);
}

/* Loading */
.loading-dots {
  display: flex; gap: 5px; padding: 20px 0;
}
.loading-dots span {
  width: 6px; height: 6px; background: var(--muted);
  border-radius: 50%; animation: blink 1s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.2} 40%{opacity:1} }

/* ── Word List Modal ── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 200;
}
.wl-modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: min(880px, 96vw); max-height: 80dvh;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); z-index: 201;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.wl-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  font-size: .9rem; font-weight: 600; color: var(--white);
  flex-shrink: 0;
}
#listContent { overflow-y: auto; padding: 16px 20px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th {
  text-align: left; padding: 8px 12px;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dim); border-bottom: 1px solid var(--line);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--sub); }
td:first-child { color: var(--white); font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg3); }
code { font-family: 'SF Mono','Fira Code',monospace; font-size: .85em; }

/* ── Word List Toolbar ── */
.wl-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.wl-count { font-size: .72rem; color: var(--dim); }
.wl-clear {
  background: none; border: 1px solid var(--line2);
  border-radius: var(--r-sm); padding: 4px 10px;
  color: var(--dim); font-size: .75rem; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.wl-clear:hover { color: #c97; border-color: #c97; }

/* Word list: type icon */
.type-icon { margin-right: 5px; }

/* Example cell: truncate long text */
.ex-cell { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Action cell */
.act-cell { white-space: nowrap; display: flex; gap: 6px; align-items: center; padding: 8px 10px; }
.act-speak {
  padding: 3px 8px !important; font-size: .75rem !important;
  border-radius: 12px !important;
}
.act-retrans {
  background: none; border: 1px solid var(--line2);
  border-radius: var(--r-sm); padding: 3px 10px;
  color: var(--muted); font-size: .8rem; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.act-retrans:hover { color: var(--white); border-color: var(--white); background: var(--bg3); }

/* Focused row in word list (keyboard nav) */
tr:focus {
  outline: none;
  background: var(--bg3) !important;
}
tr:focus td { background: var(--bg3); }

/* ── Error debug (API 报错详情) ── */
.error-box .err-details {
  font-size: 0.8rem; font-family: ui-monospace, monospace;
  background: var(--bg3); border: 1px solid var(--line2);
  border-radius: var(--r-sm); padding: 10px 12px;
  margin-top: 8px; max-height: 240px; overflow: auto;
  white-space: pre-wrap; word-break: break-all; color: var(--sub);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 2px; }

/* ── Mobile ── */
@media (max-width: 640px) {
  .history-drawer { display: none !important; }
  .output { padding: 16px 14px 10px; }
  .input-bar { padding: 10px 12px; }
  .welcome-title { font-size: 1.5rem; }
  .r-word { font-size: 1.6rem; }
  .cmp-grid { grid-template-columns: 1fr; }
  .settings-panel { width: 100vw; }
}

/* ── Resize smooth ── */
* { transition-property: none; }
.settings-panel, .icon-btn, .send-btn, .sp-save,
.speak-pill, .h-item, .list-cmd, textarea,
.sp-section input, .sp-section select,
.toggle-track, .toggle-track::after { transition-property: all; }
