:root {
  --bg: #f4f1ea;
  --ink: #1f2a2e;
  --accent: #d17b49;
  --accent-dark: #b46639;
  --card: #fff8ef;
  --muted: #6b6f72;
  --ok: #1f7a4f;
  --bad: #b33a3a;
  --shadow: 0 16px 40px rgba(31, 42, 46, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Serif SC", "Source Han Serif SC", "PingFang SC", "Songti SC", serif;
  color: var(--ink);
  background:
    radial-gradient(1000px 600px at 20% 10%, rgba(209, 123, 73, 0.18), transparent 55%),
    radial-gradient(900px 600px at 90% 90%, rgba(31, 122, 79, 0.15), transparent 60%),
    var(--bg);
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(32px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

.stats {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 248, 239, 0.92);
  border: 1px solid rgba(31, 42, 46, 0.12);
  box-shadow: 0 12px 28px rgba(31, 42, 46, 0.18);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 16px;
  font-size: clamp(12px, 2.4vw, 14px);
  font-weight: 600;
  letter-spacing: 0.04em;
  z-index: 10000;
  display: grid;
  gap: 4px;
}

.stats.hidden {
  display: none;
}

.stats-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.stats-current {
  padding-left: 18px;
}

.stats-total {
  display: none;
  color: var(--muted);
}

.stats.expanded .stats-total {
  display: flex;
}

.stats-toggle {
  border: none;
  background: transparent;
  width: 22px;
  height: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
}

.stats-toggle::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.2s ease;
}

.stats.expanded .stats-toggle::before {
  transform: translateY(2px) rotate(-135deg);
}

.stats-toggle:focus-visible {
  outline: 2px solid rgba(31, 42, 46, 0.35);
  border-radius: 6px;
}

.app {
  width: min(900px, 100%);
  display: grid;
  gap: 20px;
  position: relative;
}

.fav-area {
  position: absolute;
  bottom: clamp(8px, 1.6vw, 14px);
  right: clamp(8px, 1.6vw, 14px);
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 2;
}

.fav-source {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.75;
  white-space: nowrap;
}

.fav-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  color: rgba(107, 111, 114, 0.45);
  border-radius: 6px;
  display: grid;
  place-items: center;
  min-width: unset;
  transition: color 0.15s, transform 0.15s;
}

.fav-btn:hover:not(:disabled) {
  color: rgba(209, 123, 73, 0.7);
  transform: scale(1.15);
}

.fav-btn.active {
  color: rgba(209, 123, 73, 0.6);
}

.fav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.title {
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: 0.04em;
}


.card {
  background: var(--card);
  border-radius: 24px;
  padding: clamp(18px, 3vw, 32px);
  box-shadow: var(--shadow);
  display: grid;
  gap: clamp(12px, 2.2vw, 20px);
  border: 1px solid rgba(31, 42, 46, 0.08);
  text-align: center;
}

.word {
  font-size: clamp(30px, 8vw, 64px);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.phonetic {
  font-family: "Iowan Old Style", "Palatino", serif;
  color: var(--muted);
  font-size: clamp(14px, 2.6vw, 18px);
}

.controls {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 14px);
  font-size: clamp(12px, 2.2vw, 14px);
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: center;
}

.word-list-select {
  border-radius: 999px;
  padding: clamp(6px, 1.4vw, 10px) clamp(28px, 4vw, 36px);
  font-size: clamp(12px, 2.4vw, 14px);
  font-family: inherit;
  border: 1px solid rgba(31, 42, 46, 0.2);
  background: rgba(31, 42, 46, 0.04) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6f72' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  -webkit-appearance: none;
  appearance: none;
  color: var(--ink);
  cursor: pointer;
  width: auto;
  text-align: center;
  text-align-last: center;
}

.word-list-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.word-list-wrapper {
  position: relative;
  display: inline-block;
}

.word-list-btn {
  white-space: nowrap;
}

.word-list-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid rgba(31, 42, 46, 0.15);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(31, 42, 46, 0.14);
  padding: 4px 0;
  min-width: max-content;
  z-index: 1000;
  font-family: inherit;
  font-size: clamp(12px, 2.4vw, 14px);
}

.word-list-popup.hidden {
  display: none;
}

.wl-popup-group-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.8em;
  padding: 5px 20px 3px;
  border-top: 1px solid rgba(31, 42, 46, 0.08);
  user-select: none;
  pointer-events: none;
}

.wl-popup-group:first-child .wl-popup-group-label {
  border-top: none;
}

.wl-popup-option {
  text-align: center;
  padding: 6px 24px;
  cursor: pointer;
  color: var(--ink);
}

.wl-popup-option:hover {
  background: rgba(31, 42, 46, 0.06);
}

.wl-popup-option.selected {
  color: var(--accent);
  font-weight: 500;
}

.wl-popup-option-custom {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.wl-popup-option-text {
  flex: 1;
  padding: 6px 6px 6px 24px;
  cursor: pointer;
  text-align: center;
}

.wl-popup-edit-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 6px 14px 6px 4px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  line-height: 1;
  min-width: unset;
  opacity: 0.6;
  white-space: nowrap;
}

.wl-popup-edit-btn:hover {
  opacity: 1;
}

.mic-toggle {
  border-radius: 999px;
  padding: clamp(6px, 1.4vw, 10px) clamp(12px, 3.2vw, 18px);
  font-size: clamp(12px, 2.4vw, 14px);
  border: 1px solid rgba(31, 42, 46, 0.2);
  background: transparent;
  color: var(--ink);
}

.mic-toggle.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 20px rgba(209, 123, 73, 0.25);
  border-color: transparent;
}

.help-toggle {
  border-radius: 999px;
  padding: clamp(6px, 1.4vw, 10px) clamp(12px, 3.2vw, 18px);
  font-size: clamp(12px, 2.4vw, 14px);
  border: 1px solid rgba(31, 42, 46, 0.2);
  background: transparent;
  color: var(--ink);
}

.help-toggle.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 20px rgba(209, 123, 73, 0.25);
  border-color: transparent;
}

.status {
  font-size: clamp(11px, 2.1vw, 13px);
  padding: clamp(8px, 2vw, 12px) clamp(10px, 2.4vw, 16px);
  border-radius: 12px;
  background: rgba(31, 42, 46, 0.06);
}
.status.hidden {
  display: none;
}

.status.ok {
  background: rgba(31, 122, 79, 0.12);
  color: var(--ok);
}

.status.bad {
  background: rgba(179, 58, 58, 0.12);
  color: var(--bad);
}

.meaning {
  font-size: clamp(20px, 6vw, 36px);
  font-weight: 700;
  min-height: 28px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(8px, 2.4vw, 14px);
  justify-content: center;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-list button {
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 999px;
  background: rgba(31, 42, 46, 0.04);
  border: 1px dashed rgba(31, 42, 46, 0.2);
}

.file-list button.active {
  border-style: solid;
  background: rgba(31, 42, 46, 0.08);
}

button {
  border: none;
  border-radius: 999px;
  padding: clamp(10px, 2.8vw, 14px) clamp(16px, 4.2vw, 22px);
  font-size: clamp(13px, 2.8vw, 16px);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 20px rgba(209, 123, 73, 0.25);
}

.primary:hover:not(:disabled) {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.ghost {
  background: transparent;
  border: 1px solid rgba(31, 42, 46, 0.15);
}

.tips {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.footer {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 600px) {
  .card {
    padding: 20px;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Invisible full-screen 2x3 touch areas for touch optimization.
   These cover the viewport but forward touches that land on the .app element.
   No visible styles or animations. */
#touch-overlay{
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none; /* container itself doesn't block; children will be positioned and enabled */
}
#touch-overlay .touch-area{
  position: fixed;
  pointer-events: none; /* dynamically enabled when area has size and does not intersect .app */
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* no visual outline, no hover/focus styles */
#touch-overlay .touch-area:focus{outline: none;}

#touch-overlay.help-on .touch-area{
  background: rgba(209, 123, 73, 0.22);
  border: 1px solid rgba(31, 42, 46, 0.2);
  backdrop-filter: blur(1px);
}

#touch-overlay.help-on .touch-area::after{
  content: attr(data-label);
  position: absolute;
  inset: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(12px, 3vw, 18px);
  font-weight: 700;
  color: #1f2a2e;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 10px;
  text-align: center;
}

#touch-overlay.help-on .touch-area[data-zone="tl"],
#touch-overlay.help-on .touch-area[data-zone="tr"]{
  background: rgba(64, 125, 209, 0.22);
}

#touch-overlay.help-on .touch-area[data-zone="lm"],
#touch-overlay.help-on .touch-area[data-zone="rm"]{
  background: rgba(65, 169, 118, 0.22);
}

#touch-overlay.help-on .touch-area[data-zone="bm"]{
  background: rgba(209, 123, 73, 0.24);
}

#touch-overlay.help-on .touch-area[data-zone="bl"],
#touch-overlay.help-on .touch-area[data-zone="br"]{
  background: rgba(216, 84, 103, 0.22);
}

/* ===== IMPORT MODAL ===== */
.import-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(31, 42, 46, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: import-overlay-in 0.2s ease;
}

.import-modal-overlay.hidden {
  display: none;
}

@keyframes import-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.import-modal-body {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: min(680px, 100%);
  max-height: 92svh;
  max-height: 92vh;
  overflow-y: auto;
  padding: 0 0 calc(clamp(16px, 4vw, 28px) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0;
  box-shadow: 0 -8px 40px rgba(31, 42, 46, 0.18);
  animation: import-sheet-in 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.import-modal-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: clamp(12px, 3vw, 20px) clamp(16px, 4vw, 28px);
}

@keyframes import-sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.import-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: clamp(14px, 3vw, 22px) clamp(16px, 4vw, 28px) clamp(10px, 2vw, 16px);
  border-bottom: 1px solid rgba(31, 42, 46, 0.08);
  border-radius: 24px 24px 0 0;
}

.import-title {
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

.import-close {
  border: none;
  background: rgba(31, 42, 46, 0.08);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  min-width: unset;
}

.import-close:hover {
  background: rgba(31, 42, 46, 0.14);
}

.import-step {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.import-tabs {
  display: flex;
  gap: 8px;
  background: rgba(31, 42, 46, 0.05);
  padding: 4px;
  border-radius: 12px;
}

.import-tab {
  flex: 1;
  border: none;
  border-radius: 9px;
  background: transparent;
  padding: 8px 12px;
  font-size: clamp(12px, 2.4vw, 14px);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-width: unset;
}

.import-tab.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(31, 42, 46, 0.1);
}

.import-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.import-tab-panel.hidden {
  display: none;
}

.import-hint {
  font-size: clamp(11px, 2.2vw, 13px);
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.import-hint code {
  background: rgba(31, 42, 46, 0.07);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 0.95em;
}

.import-textarea {
  width: 100%;
  min-height: 180px;
  border: 1.5px solid rgba(31, 42, 46, 0.15);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: clamp(13px, 2.6vw, 15px);
  font-family: inherit;
  color: var(--ink);
  background: rgba(31, 42, 46, 0.03);
  resize: vertical;
  outline: none;
  box-sizing: border-box;
  line-height: 1.7;
}

.import-textarea:focus {
  border-color: var(--accent);
  background: #fff;
}

/* Photo dropzone */
.photo-dropzone {
  border: 2px dashed rgba(31, 42, 46, 0.2);
  border-radius: 16px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

.photo-dropzone:hover {
  border-color: var(--accent);
}

.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  pointer-events: none;
  padding: 20px;
  text-align: center;
}

.photo-icon {
  font-size: 40px;
  line-height: 1;
}

.photo-placeholder p {
  margin: 0;
  font-size: clamp(13px, 2.6vw, 15px);
}

.photo-preview {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 12px;
  display: block;
}

.photo-preview.hidden {
  display: none;
}

.photo-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.photo-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.ocr-hint-network {
  background: rgba(209, 123, 73, 0.1);
  border-radius: 10px;
  padding: 8px 12px;
}

.ocr-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ocr-progress.hidden {
  display: none;
}

.ocr-progress-bar {
  height: 6px;
  background: rgba(31, 42, 46, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.ocr-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

#ocrProgressText {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.import-step-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding-top: 4px;
}

/* Step 2 - Edit word list */
.import-edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.parsed-count {
  font-size: clamp(12px, 2.4vw, 14px);
  color: var(--muted);
  font-weight: 600;
}

.import-add-btn {
  font-size: 13px;
  padding: 6px 14px;
  border: 1.5px solid rgba(31, 42, 46, 0.15);
}

.import-word-table-wrap {
  max-height: 280px;
  overflow-y: auto;
  border: 1.5px solid rgba(31, 42, 46, 0.1);
  border-radius: 14px;
}

.import-word-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(12px, 2.4vw, 14px);
}

.import-word-table thead {
  position: sticky;
  top: 0;
  background: rgba(244, 241, 234, 0.97);
  z-index: 1;
}

.import-word-table th {
  padding: 8px 10px;
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid rgba(31, 42, 46, 0.1);
}

.import-word-table td {
  padding: 4px 6px;
  border-bottom: 1px solid rgba(31, 42, 46, 0.06);
  vertical-align: middle;
}

.import-word-table tr:last-child td {
  border-bottom: none;
}

.import-word-table tr:hover td {
  background: rgba(209, 123, 73, 0.04);
}

.word-cell-input {
  border: none;
  background: transparent;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  color: var(--ink);
  padding: 4px 4px;
  border-radius: 6px;
  outline: none;
  min-width: 0;
  box-sizing: border-box;
}

.word-cell-input:focus {
  background: rgba(209, 123, 73, 0.08);
  outline: 1.5px solid var(--accent);
}

.word-del-btn {
  border: none;
  background: transparent;
  color: var(--bad);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
  opacity: 0.5;
  min-width: unset;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
}

.word-del-btn:hover {
  opacity: 1;
  background: rgba(179, 58, 58, 0.08);
}

.import-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.import-label {
  font-size: clamp(12px, 2.4vw, 14px);
  color: var(--muted);
  white-space: nowrap;
}

.import-name-input {
  flex: 1;
  min-width: 140px;
  border: 1.5px solid rgba(31, 42, 46, 0.15);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: clamp(13px, 2.6vw, 15px);
  font-family: inherit;
  color: var(--ink);
  background: rgba(31, 42, 46, 0.03);
  outline: none;
}

.import-name-input:focus {
  border-color: var(--accent);
  background: #fff;
}

/* Saved lists section */
.saved-lists-section {
  border-top: 1px solid rgba(31, 42, 46, 0.1);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.saved-lists-section.hidden {
  display: none;
}

.saved-lists-header {
  font-size: clamp(12px, 2.4vw, 14px);
  color: var(--muted);
  font-weight: 600;
}

.saved-lists-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.saved-list-item {
  display: flex;
  align-items: center;
  gap: 0;
  background: rgba(31, 42, 46, 0.05);
  border: 1px solid rgba(31, 42, 46, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.saved-list-name {
  padding: 6px 12px 6px 14px;
  font-size: clamp(12px, 2.4vw, 13px);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.saved-list-name:hover {
  color: var(--accent);
}

.saved-list-edit {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  min-width: unset;
  opacity: 0.7;
}

.saved-list-edit:hover {
  opacity: 1;
}

.saved-list-del {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px 6px 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  min-width: unset;
  opacity: 0.6;
}

.saved-list-del:hover {
  opacity: 1;
  color: var(--bad);
}

/* Custom confirm dialog */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 30000;
  background: rgba(31, 42, 46, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: import-overlay-in 0.15s ease;
}

.confirm-overlay.hidden {
  display: none;
}

.confirm-box {
  background: var(--card);
  border-radius: 18px;
  padding: 24px 24px 18px;
  width: min(320px, 100%);
  box-shadow: 0 8px 40px rgba(31, 42, 46, 0.2);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: confirm-in 0.18s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes confirm-in {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.confirm-msg {
  margin: 0;
  font-size: clamp(14px, 3vw, 16px);
  color: var(--ink);
  line-height: 1.5;
  text-align: center;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== BROWSE MODE BUTTON ===== */
.browse-area {
  position: absolute;
  bottom: clamp(8px, 1.6vw, 14px);
  left: clamp(8px, 1.6vw, 14px);
  z-index: 2;
}

.browse-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 17px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  color: rgba(107, 111, 114, 0.45);
  border-radius: 6px;
  display: grid;
  place-items: center;
  min-width: unset;
  transition: color 0.15s, transform 0.15s;
}

.browse-btn:hover {
  color: rgba(209, 123, 73, 0.7);
  transform: scale(1.15);
}

/* ===== BROWSE MODE PANEL ===== */
.browse-overlay {
  position: fixed;
  inset: 0;
  z-index: 22000;
  background: rgba(31, 42, 46, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  animation: import-overlay-in 0.2s ease;
}

.browse-overlay.hidden {
  display: none;
}

.browse-panel {
  background: var(--card);
  border-radius: 20px;
  width: min(1200px, 100%);
  height: calc(100svh - 20px);
  height: calc(100vh - 20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(31, 42, 46, 0.22);
  animation: browse-panel-in 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes browse-panel-in {
  from { transform: scale(0.97); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.browse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(12px, 2.5vw, 18px) clamp(14px, 3vw, 22px);
  border-bottom: 1px solid rgba(31, 42, 46, 0.08);
  flex-shrink: 0;
  gap: 12px;
}

.browse-title {
  font-size: clamp(13px, 2.8vw, 17px);
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browse-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Segmented layout toggle */
.browse-layout-toggle {
  display: flex;
  background: rgba(31, 42, 46, 0.07);
  border-radius: 999px;
  padding: 3px;
  gap: 0;
}

.browse-toggle-btn {
  border: none;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: clamp(11px, 2vw, 13px);
  font-family: inherit;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-width: unset;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  line-height: 1.4;
}

.browse-toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(209, 123, 73, 0.3);
}

/* Standalone toggle button (e.g. 中文, 自动) — always has a border */
#browseCnToggle,
#browseAutoBtn {
  border: 1px solid rgba(31, 42, 46, 0.2);
}

#browseCnToggle.active,
#browseAutoBtn.active {
  border-color: transparent;
}

.browse-close-btn {
  border: 1px solid rgba(31, 42, 46, 0.2);
  background: transparent;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  min-width: unset;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.browse-close-btn:hover {
  background: rgba(31, 42, 46, 0.08);
  border-color: rgba(31, 42, 46, 0.35);
}

.browse-body {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  padding: 8px 12px;
  display: grid;
  gap: 4px;
}

/* List mode: 2 columns via grid (JS sets template) */
.browse-body.list-mode {
  gap: 1px 12px;
  padding: 4px 12px;
}

.browse-body.list-mode .browse-word-item {
  flex-direction: row;
  align-items: center;
  gap: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(31, 42, 46, 0.055);
  border-radius: 0;
  padding: 0 4px;
  overflow: hidden;
}

.browse-body.list-mode .browse-word-item:hover {
  background: rgba(209, 123, 73, 0.05);
  border-bottom-color: rgba(31, 42, 46, 0.055);
}

.browse-body.list-mode .browse-en-line {
  flex: 0 0 auto;
  max-width: 54%;
  min-width: 0;
  overflow: hidden;
}

.browse-body.list-mode .browse-word-en {
  font-size: var(--browse-list-fs, 13px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.browse-body.list-mode .browse-word-cn {
  flex: 1;
  font-size: var(--browse-list-fs-cn, 12px);
  line-height: 1.2;
  padding-left: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browse-word-item {
  background: rgba(31, 42, 46, 0.03);
  border: 1px solid rgba(31, 42, 46, 0.07);
  border-radius: 9px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  transition: background 0.12s, border-color 0.12s;
}

.browse-word-item:hover {
  background: rgba(209, 123, 73, 0.06);
  border-color: rgba(209, 123, 73, 0.18);
}

.browse-word-item.browse-active {
  background: rgba(209, 123, 73, 0.13);
  border-color: rgba(209, 123, 73, 0.40);
}

/* Override list-mode's transparent background for active item */
.browse-body.list-mode .browse-word-item.browse-active {
  background: rgba(209, 123, 73, 0.13);
  border-bottom-color: rgba(209, 123, 73, 0.40);
}

.browse-en-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.browse-word-num {
  font-size: 9px;
  color: var(--muted);
  opacity: 0.45;
  line-height: 1;
  flex-shrink: 0;
  width: 2.8em;
  text-align: right;
  padding-right: 3px;
  font-variant-numeric: tabular-nums;
}

.browse-word-en {
  font-size: clamp(12px, 2.3vw, 14px);
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.35;
}

.browse-word-cn {
  font-size: clamp(10px, 1.9vw, 12px);
  color: var(--muted);
  line-height: 1.3;
  word-break: break-word;
}

.browse-body.cn-hidden .browse-word-cn {
  visibility: hidden;
}

.browse-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: clamp(8px, 1.8vw, 14px) 20px;
  border-top: 1px solid rgba(31, 42, 46, 0.08);
  flex-shrink: 0;
}

.browse-footer-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding-top: 12px;
}

.browse-page-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(31, 42, 46, 0.15);
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
}

.browse-page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #dfaa82;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.browse-page-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #dfaa82;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.browse-page-slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(31, 42, 46, 0.15);
}

.browse-nav-btn {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(31, 42, 46, 0.2);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-width: unset;
  transition: background 0.15s;
  align-self: flex-start;
  margin-top: -1px;
}

.browse-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.browse-nav-btn:hover:not(:disabled) {
  background: rgba(31, 42, 46, 0.06);
}

.browse-page-info {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  text-align: center;
}
