:root {
  --primary: #264653;
  --secondary: #2a9d8f;
  --accent: #e76f51;
  --highlight: #e9c46a;
  --bg: #f4f1de;
  --card-bg: #ffffff;
  --shadow-card: 0 8px 24px rgba(38, 70, 83, 0.08);
}
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    sans-serif;
  background-color: var(--bg);
  margin: 0;
  padding-bottom: 140px;
  color: var(--primary);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  user-select: none;
}
body.ftu-active {
  overflow: hidden;
}
#ftuOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 3000;
  opacity: 0;
  transition: opacity 0.3s ease-out;
}
#ftuHighlight {
  position: absolute;
  border: 2px solid var(--highlight);
  border-radius: 12px;
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 3001;
  transition: all 0.3s ease-out;
  opacity: 0;
}
#ftuTip {
  position: absolute;
  background: white;
  color: var(--primary);
  padding: 12px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 3002;
  max-width: 80%;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: all 0.35s ease-out;
}
#ftuTip::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  margin-left: -6px;
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: white transparent transparent;
}
#ftuTip.tip-bottom::after {
  bottom: auto;
  top: -6px;
  border-width: 0 6px 6px;
  border-color: transparent transparent white;
}
header {
  padding: 20px 20px 10px;
  text-align: center;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top, 20px);
}
header h1 {
  margin: 0 0 15px;
  font-size: 1.8rem;
  font-weight: 800;
  font-family: "Georgia", serif;
}
.black-feather {
  filter: brightness(0);
  opacity: 0.8;
}
.search-container {
  position: relative;
  max-width: 90%;
  margin: 0 auto 10px;
}
.search-input {
  width: 100%;
  padding: 12px 20px 12px 40px;
  border-radius: 25px;
  border: 2px solid rgba(42, 157, 143, 0.2);
  background: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  color: var(--primary);
  outline: none;
  box-sizing: border-box;
  transition: 0.3s;
}
.search-input:focus {
  border-color: var(--secondary);
  background: white;
  box-shadow: 0 4px 12px rgba(42, 157, 143, 0.15);
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--secondary);
  opacity: 0.7;
}
.category-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 5px 20px 15px;
  scrollbar-width: none;
}
.category-nav::-webkit-scrollbar {
  display: none;
}
.chip {
  background: rgba(42, 157, 143, 0.1);
  color: var(--secondary);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: 0.2s;
  border: 1px solid transparent;
}
.chip:active,
.chip.active {
  background: var(--secondary);
  color: white;
}
.unit-title {
  margin: 25px 25px 10px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 1.1rem;
  scroll-margin-top: 140px;
}
.unit-counter {
  font-size: 0.85rem;
  color: var(--secondary);
  opacity: 0.8;
}
.scroll-wrapper {
  position: relative;
  width: 100%;
}
.card-container {
  display: flex;
  overflow-x: auto;
  gap: 16px;
  padding: 5px 25px 35px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  min-height: 180px;
}
.card-container::-webkit-scrollbar {
  display: none;
}
.card {
  min-width: 78vw;
  background: var(--card-bg);
  border-radius: 24px;
  padding: 25px;
  box-shadow: var(--shadow-card);
  scroll-snap-align: center;
  position: relative;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.02);
  transition: transform 0.3s;
  overflow: hidden;
}
.card::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  height: 6px;
  background: rgba(255, 255, 255, 0.6);
  width: 0%;
  opacity: 0;
  transition:
    width 0.1s linear,
    opacity 0.2s;
}
.card.playing::after {
  opacity: 1;
  width: 90%;
  transition: width var(--duration, 2s) linear;
}
.card.playing.finished::after {
  width: 100% !important;
  transition: width 0.1s ease-out;
}
.card.playing {
  background: var(--secondary);
  transform: scale(1.02);
  box-shadow: 0 15px 30px rgba(42, 157, 143, 0.3);
}
.card.playing h2,
.card.playing p,
.card.playing .action-icon {
  color: white !important;
  stroke: white !important;
}
.card.playing .note-area {
  color: rgba(255, 255, 255, 0.9);
  border-top-color: rgba(255, 255, 255, 0.3);
}
.card.playing .star {
  color: rgba(255, 255, 255, 0.3);
  stroke: white;
}
.card.playing .star.active {
  color: var(--highlight);
  stroke: var(--highlight);
  fill: var(--highlight);
}
.card h2 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--secondary);
  font-weight: 700;
  letter-spacing: 1px;
}
.card p {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.25;
  color: #333;
}
.card-actions {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 12px;
  z-index: 10;
  align-items: center;
}
.action-icon {
  width: 26px;
  height: 26px;
  color: #d0d0d0;
  cursor: pointer;
  transition: 0.2s;
  stroke-width: 2;
  fill: none;
  stroke: currentColor;
}
.star.active {
  color: var(--highlight);
  stroke: var(--highlight);
  fill: var(--highlight);
  transform: scale(1.1);
}
.star-wrapper:hover .star {
  stroke: var(--highlight) !important;
  transform: scale(1.2) !important;
  filter: drop-shadow(0 0 5px rgba(233, 196, 106, 0.8));
}
.action-icon.eye-icon:hover {
  color: var(--primary) !important;
  transform: scale(1.15) !important;
  stroke-width: 2.5;
}
.action-icon.trash-icon:hover {
  color: var(--accent) !important;
  stroke: var(--accent) !important;
  transform: scale(1.15) !important;
  stroke-width: 2.5;
}
.note-area {
  margin-top: 20px;
  font-size: 0.9rem;
  color: #888;
  border-top: 1px dashed #eee;
  padding-top: 12px;
  min-height: 1rem;
  font-style: italic;
  white-space: pre-wrap;
}
.note-area:empty::before {
  content: "✍️ 点击写笔记...";
  opacity: 0.6;
}
.empty-search {
  text-align: center;
  padding: 40px;
  color: #888;
  display: none;
}
.bottom-bar {
  position: fixed;
  bottom: calc(30px + env(safe-area-inset-bottom, 20px));
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  height: 64px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(15px);
  border-radius: 50px;
  display: flex;
  gap: 30px;
  align-items: center;
  justify-content: center;
  padding: 0 35px;
  box-shadow: 0 12px 32px rgba(231, 111, 81, 0.25);
  z-index: 1000;
  border: 1px solid rgba(255, 255, 255, 0.8);
}
.nav-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  width: 48px;
}
.nav-icon {
  width: 28px;
  height: 28px;
  stroke: #94a3b8;
  stroke-width: 2.2;
  fill: none;
  transition: 0.3s;
  display: block;
}
.nav-btn:hover .nav-icon {
  stroke: var(--secondary);
}
.play-btn {
  background: var(--accent);
  color: white;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 10px 25px rgba(231, 111, 81, 0.4);
  cursor: pointer;
  margin-top: -35px;
  transition: 0.2s;
  flex-shrink: 0;
}
.play-btn:active {
  transform: scale(0.95);
}
.play-btn.playing {
  background: #d62828;
  transform: scale(1.1);
  box-shadow: 0 0 0 6px rgba(214, 40, 40, 0.15);
}
.play-btn svg {
  width: 24px;
  height: 24px;
  fill: white;
  stroke: none;
  margin-left: 3px;
}
.play-btn.playing svg {
  margin-left: 0;
}
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(38, 70, 83, 0.6);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: center;
}
.modal-overlay.open {
  display: flex;
}
.modal-card {
  background: #fff;
  width: 90%;
  max-width: 450px;
  border-radius: 32px;
  padding: 30px;
  box-sizing: border-box;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title {
  margin: 0 0 20px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
}
.modal-title svg {
  width: 24px;
  height: 24px;
  stroke: var(--secondary);
  stroke-width: 2.2;
  fill: none;
}
.input-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--secondary);
  margin-bottom: 8px;
  font-weight: 700;
}
.input-group input,
.input-group textarea,
.input-group select {
  width: 100%;
  padding: 14px;
  border: 2px solid #eee;
  background: #f9f9f9;
  border-radius: 16px;
  font-size: 16px;
  color: var(--primary);
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
}
.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  transition: 0.2s;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--secondary);
  color: white;
}
.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-ghost {
  background: transparent;
  color: #888;
  border: 1px solid #eee;
}
.btn-danger {
  background: #ffeeee;
  color: #d62828;
  border: 1px solid #ffcccc;
  margin-top: 10px;
}
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}
.toggle-switch {
  position: relative;
  width: 50px;
  height: 28px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #eee;
  border-radius: 34px;
  transition: 0.4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 50%;
  transition: 0.4s;
}
input:checked + .slider {
  background-color: var(--secondary);
}
input:checked + .slider:before {
  transform: translateX(22px);
}
.app-footer {
  text-align: center;
  padding: 30px 20px;
  color: var(--secondary);
  opacity: 0.6;
  margin-top: 20px;
  font-size: 0.85rem;
  border-top: 1px dashed #eee;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
#toast {
  visibility: hidden;
  min-width: 200px;
  background-color: rgba(38, 70, 83, 0.95);
  color: #fff;
  text-align: center;
  border-radius: 50px;
  padding: 12px 24px;
  position: fixed;
  z-index: 3000;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition:
    opacity 0.3s,
    bottom 0.3s;
  font-weight: 600;
}
#toast.show {
  visibility: visible;
  opacity: 1;
  bottom: 110px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 分類管理列表 (v38+) */
.cat-list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}
.cat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background-color: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #eee;
  transition: 0.2s;
}
.cat-item:hover {
  background-color: #f1f3f5;
}
.cat-name {
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--primary);
}
.cat-actions {
  display: flex;
  gap: 8px;
}
.cat-btn {
  border: none;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}
.cat-btn.edit {
  color: var(--secondary);
  border-color: var(--secondary);
}
.cat-btn.delete {
  color: var(--accent);
  border-color: var(--accent);
  background: #fff5f5;
}
.cat-btn:active {
  transform: scale(0.95);
}

/* 卡片讀取中 (v45+) */
.card.loading {
  animation: pulse-loading 1.5s infinite ease-in-out;
  pointer-events: none;
  opacity: 0.8;
}
@keyframes pulse-loading {
  0% {
    box-shadow: 0 0 0 0 rgba(42, 157, 143, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(42, 157, 143, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(42, 157, 143, 0);
  }
}
.card.playing {
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* --- 排序按鈕樣式 (v47 New) --- */
.cat-btn.move {
  color: var(--primary);
  border-color: #ccc;
  background: #fdfdfd;
  padding: 5px 8px; /* 稍微窄一點，省空間 */
  font-weight: bold;
}
.cat-btn.move:active {
  background: #eee;
  transform: scale(0.95);
}
/* 讓按鈕群組靠右對齊，並保持整齊 */
.cat-actions {
  display: flex;
  gap: 5px;
}
