:root{
  color-scheme:dark;
  --bg:#000000;
  --surface:#0a0a0a;
  --surface2:#050505;
  --input:#0a0a0a;
  --input2:#0a0a0a;
  --text:#f5f5f5;
  --muted:rgba(245,245,245,.72);
  --muted2:rgba(245,245,245,.56);
  --border:rgba(255,255,255,.12);
  --border2:rgba(255,255,255,.18);
  --borderHover:rgba(255,255,255,.26);
  --shadow:0 18px 50px rgba(0,0,0,.55);
  --shadow-sm:0 1px 0 rgba(0,0,0,.35);
  --radius:18px;
  --radius-sm:12px;
  --radius-pill:999px;
  --space:14px;
  --space-sm:10px;
  --space-lg:20px;
  --maxw:1500px;
  --primary:#3b82f6;
  --primary-strong:#2563eb;
  --primary-text:#ffffff;
  --focus:rgba(59,130,246,.55);
  --focusRing:rgba(59,130,246,.14);
  --link:#93c5fd;
  --overlay:rgba(0,0,0,.62);
}

:root[data-theme="light"],
html[data-theme="light"],
body[data-theme="light"]{
  color-scheme:light;
  --bg:#f3f4f6;
  --surface:#ffffff;
  --surface2:#f8fafc;
  --input:#ffffff;
  --input2:#ffffff;
  --text:#1f2937;
  --muted:#6b7280;
  --muted2:#9ca3af;
  --border:#e5e7eb;
  --border2:#d1d5db;
  --borderHover:#9ca3af;
  --shadow:0 20px 25px -5px rgba(0,0,0,.12), 0 10px 10px -5px rgba(0,0,0,.06);
  --shadow-sm:0 1px 2px rgba(0,0,0,.06);
  --primary:#10b981;
  --primary-strong:#059669;
  --primary-text:#ffffff;
  --focus:rgba(16,185,129,.55);
  --focusRing:rgba(16,185,129,.18);
  --link:#059669;
  --overlay:rgba(0,0,0,.5);
}

@font-face{
  font-family:"TW-Kai-98_1";
  src:url("res/TW-Kai-98_1.ttf") format("truetype");
  font-weight:400;
  font-style:normal;
  font-display:block;
}

*{box-sizing:border-box}

html,body{height:100%}

body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:"TW-Kai-98_1";
  font-size:16px;
  line-height:1.65;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}

a{color:var(--link);text-decoration:none}
a:hover{text-decoration:underline;text-underline-offset:3px}

.wrap{
  max-width:var(--maxw);
  margin:0 auto;
  padding:22px;
}

.top{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  margin-bottom:16px;
}


.topTitleRow{
  display:flex;
  align-items:center;
  gap:12px;
  min-width:0;
}

.topTitleRow h1{flex:1;min-width:0}

.appTitle .titleEn{margin-left:6px}

.topBtns .copyright{
  flex-basis:100%;
  width:100%;
  text-align:center;
  font-size:12px;
  color:var(--muted2);
  padding-top:6px;
  line-height:1.2;
  user-select:none;
  pointer-events:none;
}

.themeToggle{
  display:grid;
  place-items:center;
}
.topLeft{display:flex;flex-direction:column;gap:6px;min-width:0}
.topRight{display:flex;flex-direction:column;align-items:flex-end;gap:12px}

h1{
  margin:0;
  font-size:22px;
  line-height:1.25;
  letter-spacing:.2px;
}

.sub{opacity:.75;font-size:13px}

.statusBox{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:6px;
  font-size:13px;
  color:var(--muted);
  text-align:right;
  line-height:1.35;
  min-height:34px;
}

.statusLine{min-height:18px;max-width:720px}

.topBtns{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}

.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:var(--shadow-sm);
}

h2{font-size:17px;margin:0 0 10px 0;letter-spacing:.2px}

.cardTop{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
.cardTop h2{margin:0}

.cardTopBtns{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end}

.collapseToggle{display:none}
.collapseToggle .chev{display:inline-block;transition:transform .18s ease}
.collapsibleCard.collapsed .collapseToggle .chev{transform:rotate(-90deg)}
.collapsibleCard.collapsed .cardTop{margin-bottom:0}
.collapsibleBody{display:block}
.collapsibleCard.collapsed .collapsibleBody{display:none}

.ta{
  width:100%;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--input);
  color:var(--text);
  padding:14px;
  resize:vertical;
  line-height:1.75;
  font-size:16px;
  box-shadow:inset 0 1px 0 rgba(18,24,38,.04);
}

.ta::placeholder{color:var(--muted2)}
#quickSendersText::placeholder,#quickReceiversText::placeholder,#quickCcsText::placeholder,#batchText::placeholder{font-size:12px}


.list{display:flex;flex-direction:column;gap:10px}

.entry{
  display:flex;
  gap:12px;
  align-items:flex-start;
  padding:12px;
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:var(--surface2);
}

.entryMain{flex:1;display:flex;flex-direction:column;gap:10px;min-width:0}

.entryHead{display:flex;align-items:center;justify-content:space-between;gap:10px}

.entryNo{
  font-size:12px;
  font-weight:650;
  letter-spacing:.2px;
  color:var(--text);
  padding:6px 10px;
  border:1px solid var(--border2);
  border-radius:var(--radius-pill);
  background:var(--surface2);
}

#receivers .cols,#senders .cols,#ccs .cols{grid-template-columns:1fr}
#receivers .entry,#senders .entry,#ccs .entry{background:var(--surface);border-color:var(--border)}
#receivers .entryNo,#senders .entryNo,#ccs .entryNo{background:var(--surface2)}
#receivers .entry.entryWarn,#senders .entry.entryWarn,#ccs .entry.entryWarn{background:rgba(255,105,180,.20);border-color:rgba(255,105,180,.35)}


.cols{
  display:grid;
  grid-template-columns:160px 1fr;
  gap:10px;
  align-items:start;
  padding:12px;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--surface);
}

.lab{display:flex;flex-direction:column;gap:6px;min-width:0}

.labt{font-size:12px;color:var(--muted2)}

.inp{
  width:100%;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--input2);
  color:var(--text);
  padding:12px;
  font-size:16px;
  min-height:44px;
  box-shadow:inset 0 1px 0 rgba(18,24,38,.04);
}

.inp::placeholder{color:var(--muted2)}

.ta:focus,.inp:focus{
  outline:none;
  border-color:var(--focus);
  box-shadow:0 0 0 4px var(--focusRing);
}

.row{display:flex;justify-content:flex-end;margin-top:12px}

.fontTop{margin-bottom:0}

.fontControls{display:flex;gap:12px;align-items:center;flex-wrap:wrap;justify-content:flex-end}

.lab.inline{flex-direction:row;align-items:center;gap:10px}
.lab.inline .labt{white-space:nowrap}
.lab.inline .inp{width:auto;min-width:240px}
.lab.inline .fileInp{min-width:180px;width:220px}

.btn{
  border:1px solid var(--border2);
  background:var(--surface);
  color:var(--text);
  border-radius:var(--radius);
  padding:12px 14px;
  cursor:pointer;
  min-height:44px;
  font-size:15px;
  touch-action:manipulation;
  box-shadow:var(--shadow-sm);
}

.btn:hover{background:var(--surface2);border-color:var(--borderHover)}
.btn:active{transform:translateY(1px)}

.btn.sm{padding:10px 12px;border-radius:var(--radius-sm);font-size:13px;min-height:40px}

.primary{
  background:var(--primary);
  border-color:rgba(0,0,0,0);
  color:var(--primary-text);
}

.primary:hover{filter:brightness(1.03)}
.primary:active{filter:brightness(.98)}

.icon{
  width:44px;
  height:44px;
  border-radius:var(--radius);
  border:1px solid var(--border2);
  background:var(--surface);
  color:var(--text);
  cursor:pointer;
  flex:0 0 auto;
  font-size:20px;
  line-height:1;
  box-shadow:var(--shadow-sm);
}

.icon:hover{background:var(--surface2);border-color:var(--borderHover)}
.icon:active{transform:translateY(1px)}

.actions{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:12px;flex-wrap:wrap}
.actionsBtns{display:flex;gap:8px;align-items:center;flex-wrap:wrap}

.msg{font-size:13px;color:var(--muted);min-height:18px}

.foot{opacity:.75;font-size:12px;margin-top:14px;display:flex;gap:16px;flex-wrap:wrap}

.tools{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
.toolsLeft{display:flex;gap:8px;align-items:center;flex-wrap:wrap}

.quick{
  border:1px dashed var(--borderHover);
  border-radius:var(--radius);
  padding:12px;
  margin-bottom:10px;
  background:var(--surface);
  }

.hidden{display:none}


.onboardingOverlay{
  position:fixed;
  inset:0;
  z-index:9999;
  display:flex;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.55);
  backdrop-filter:blur(10px);
  -webkit-backdrop-filter:blur(10px);
  padding:18px;
}

.onboardingOverlay.hidden{display:none}

.onboardingCard{
  width:min(560px, 100%);
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:22px;
  box-shadow:var(--shadow);
  padding:18px 18px 16px;
  text-align:center;
}

.onboardingTitle{
  font-size:18px;
  margin-bottom:10px;
  letter-spacing:.2px;
}

.onboardingMsg{
  font-size:14px;
  color:var(--muted);
  line-height:1.55;
  margin:0 auto 14px;
}

.onboardingCopyright{
  margin:10px 0 14px;
  font-size:12px;
  color:var(--muted2);
  line-height:1.3;
  user-select:none;
}

.onboardingSpinner{
  width:28px;
  height:28px;
  border-radius:999px;
  border:3px solid rgba(255,255,255,.22);
  border-top-color:rgba(255,255,255,.72);
  margin:12px auto 0;
  animation:spin 1s linear infinite;
}

@keyframes spin{to{transform:rotate(360deg)}}

.quickHead{font-size:12px;color:var(--muted2);margin-bottom:8px}
.quickBtns{display:flex;gap:10px;justify-content:flex-end;margin-top:10px;flex-wrap:wrap}

.modal{
  position:fixed;
  inset:0;
  background:var(--overlay);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:50;
}

.modal.hidden{display:none}

.modalBox{
  width:min(920px,100%);
  max-height:85vh;
  overflow:auto;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}

.modalTop{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:16px 16px 0 16px}
.modalTitle{font-size:15px;font-weight:650;letter-spacing:.2px}
.modalBody{padding:16px;display:flex;flex-direction:column;gap:14px}
.modalActions{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}
.modalActions .leftPush{margin-right:auto}

.modalTabs{display:flex;gap:8px;flex-wrap:wrap}
.tabBtn{border:1px solid var(--border);background:var(--surface2);color:var(--text);padding:8px 12px;border-radius:999px;
  font-size:13px;font-weight:650;cursor:pointer;user-select:none}
.tabBtn.active{background:var(--primary);color:var(--primary-text);border-color:rgba(0,0,0,0)}

.contentPre{white-space:pre-wrap;word-break:break-word;overflow:auto;max-height:60vh;padding:12px;border:1px solid var(--border);
  border-radius:var(--radius);background:var(--surface2);color:var(--text);font-size:14px;line-height:1.6}
.letterContentBox{width:min(820px,100%)}

.peoplePanel{border:1px solid var(--border);border-radius:var(--radius);padding:12px;background:var(--surface2);color:var(--text);font-size:13px;line-height:1.6}
.peopleDetails{border:1px solid var(--border);border-radius:var(--radius);background:var(--surface2);overflow:hidden;margin-bottom:12px}
.peopleDetails>summary{cursor:pointer;list-style:none;padding:10px 12px;font-size:13px;font-weight:650;display:flex;align-items:center;gap:8px;color:var(--text)}
.peopleDetails>summary::-webkit-details-marker{display:none}
.peopleDetails>summary:after{content:"▸";margin-left:auto;color:var(--muted2);display:inline-block;transform:scale(3);transform-origin:center;line-height:1}
.peopleDetails[open]>summary:after{content:"▾"}
.peopleDetails.alwaysOpen>summary{display:none}
.peopleDetails.alwaysOpen .peoplePanel{border-top:0}
.peopleDetails .peoplePanel{border:0;border-top:1px solid var(--border);border-radius:0;background:transparent;padding:12px;margin:0}
.peopleGroup{display:flex;flex-direction:column;gap:6px}
.peopleGroup+.peopleGroup{margin-top:10px}
.peopleTitle{font-size:12px;font-weight:650;color:var(--muted2)}
.peopleList{margin:0;padding-left:18px}
.peopleList li{line-height:1.5}

.modalSection{border:1px solid var(--border);border-radius:var(--radius);padding:12px;background:var(--surface);
  color:var(--muted2);margin-bottom:10px;letter-spacing:.2px}

.modalSectionTitle{font-size:13px;font-weight:650;color:var(--text);margin-bottom:8px}

.historyList{display:flex;flex-direction:column;gap:10px}

.historyItem{display:flex;gap:12px;align-items:flex-start;justify-content:space-between;padding:12px;border:1px solid var(--border);border-radius:var(--radius);background:var(--surface2);flex-wrap:wrap;}
.historyMain{flex:1;display:flex;flex-direction:column;gap:8px;min-width:0}
.historyTitleRow{display:flex;flex-direction:column;gap:4px}
.historyTitle{font-size:13px;font-weight:650}
.historyMeta{font-size:12px;color:var(--muted2)}
.historyBtns{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}

.historyItemActions{display:flex;flex-direction:column;gap:10px;align-items:flex-end;flex:0 0 auto;min-width:220px}
.historyItemActionsTop{display:flex;gap:8px;justify-content:flex-end;width:100%}
.historyItemActionsBottom{display:flex;gap:10px;justify-content:flex-end;width:100%}
.historyItemActionsBottom .btn{flex:1 1 0;min-width:96px}
.historyItemActionsBottom .btn:only-child{min-width:160px}
.historyItemActionsTop .btn{min-width:86px}

.btn.removeBtn{background:rgba(255,105,180,.20);border-color:rgba(255,105,180,.35)}
.btn.removeBtn:hover{background:rgba(255,105,180,.26);border-color:rgba(255,105,180,.45)}

.historyTagRow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.historyTagLabel{font-size:12px;color:var(--muted2);white-space:nowrap}
.historyTagInput{flex:1;min-width:220px;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--surface);
  color:var(--text);padding:10px 12px;font-size:14px;min-height:40px}
.historyTagInput::placeholder{opacity:.55}

.historyTagPill{display:inline-block;max-width:100%;padding:6px 10px;border-radius:999px;font-size:12px;font-weight:650;letter-spacing:.2px;
  border:1px solid var(--border);background:var(--surface);color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.historyTagPill.muted{background:var(--surface2);color:var(--muted2);border-color:var(--border2)}
.historyTagActionBtn{min-width:40px;display:inline-flex;align-items:center;justify-content:center}

.empty{font-size:12px;color:var(--muted2);padding:6px 2px}

.hintBox{width:min(760px,100%)}
.hintText{font-size:15px;line-height:1.8;color:var(--text)}
.hintBtns{display:flex;justify-content:flex-end;margin-top:12px}

.localFontsModal{align-items:center;justify-content:center}

.localFontsBox{
  position:relative;
  top:auto;
  left:auto;
  width:min(560px,calc(100% - 32px));
  max-height:calc(100vh - 96px);
  overflow:auto;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}

.localFontsPointer{
  position:fixed;
  top:12px;
  left:12px;
  pointer-events:none;
  width:120px;
  height:64px;
  border-top:2px solid var(--borderHover);
  border-left:2px solid var(--borderHover);
  border-top-left-radius:14px;
}

.localFontsPointer:after{
  content:"";
  position:absolute;
  top:-8px;
  left:-8px;
  width:0;
  height:0;
  border:10px solid transparent;
  border-right-color:var(--borderHover);
  transform:rotate(-45deg);
}

:focus-visible{outline:2px solid var(--focus);outline-offset:2px}

@media (max-width:980px){
  .grid{grid-template-columns:1fr}
  .cols{grid-template-columns:1fr}
}

@media (max-width:720px){
  .appTitle .titleZh,
  .appTitle .titleEn{display:block}
  .appTitle .titleEn{margin-left:0;opacity:.85}
  .wrap{padding:16px}
  .top{flex-direction:column;align-items:stretch}
  .topRight{align-items:stretch}
  .statusBox{align-items:flex-start;text-align:left}
  h1{font-size:20px}
  .fontControls{justify-content:flex-start}
  .lab.inline{width:100%;justify-content:space-between;gap:12px}
  .lab.inline .inp{width:100%;min-width:0}
  .lab.inline .fileInp{width:100%}

  .collapseToggle{display:inline-flex;align-items:center;justify-content:center}
  .collapsibleBody[hidden]{display:none}
}

@media (max-width:560px){
  .wrap{padding:14px;padding-bottom:96px}
  h1{font-size:18px}
  .card{padding:14px}
  .ta{padding:12px}

  .topBtns{
    position:fixed;
    left:0;
    right:0;
    bottom:0;
    gap:10px;
    padding:10px 12px calc(10px + env(safe-area-inset-bottom));
    background:var(--surface);
    background:color-mix(in srgb, var(--surface) 92%, transparent);
    border-top:1px solid var(--border);
    z-index:40;
  }

  #historyBtn{flex:0 0 auto;min-width:96px}
  #gen{flex:1}

  .modal{padding:0}
  .modalBox,.localFontsBox{
    width:100%;
    height:100%;
    max-height:none;
    border-radius:0;
  }

  .modalTop{
    padding:16px;
    position:sticky;
    top:0;
    background:var(--surface);
    border-bottom:1px solid var(--border);
    z-index:2;
  }

  .modalBody{padding:16px}
  .localFontsPointer{display:none}

  .historyItemActions{min-width:0;width:100%}
  .historyItemActionsBottom{width:100%}
}


/* Light mode readability for history items */
:root[data-theme="light"] .historyItem{
  background:#cdcdcd;
  border-color:#bdbdbd;
}
:root[data-theme="light"] .historyItem .historyTitle{
  color:#111827;
}
:root[data-theme="light"] .historyItem .historyMeta,
:root[data-theme="light"] .historyItem .historyTagLabel{
  color:#374151;
}
:root[data-theme="light"] .historyItem .historyTagPill{
  background:#e6e6e6;
  color:#374151;
}
:root[data-theme="light"] .historyItem .historyTagPill.muted{
  opacity:1;
}


.modalActions.historyActions{justify-content:space-between}
.modalActions.historyActions .modalActionsLeft{display:flex;gap:8px;align-items:center}
.modalActions.historyActions .modalActionsRight{display:flex;gap:8px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
