:root {
  --bg: #0d0f14;
  --surface: #151922;
  --surface-2: #1d2330;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f3f5f9;
  --text-muted: #9aa4b8;
  --accent: #ff7a45;
  --accent-2: #ffb347;
  --accent-soft: rgba(255, 122, 69, 0.16);
  --danger: #f45b69;
  --danger-soft: rgba(244, 91, 105, 0.16);
  --success: #34d399;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% -10%, #1d2233 0%, var(--bg) 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.5;
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px rgba(255, 122, 69, 0.7);
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-btn.small {
  width: 34px;
  height: 34px;
  font-size: 0.9rem;
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

/* Cards */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: rgba(21, 25, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

/* Machine Header */
.machine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg);
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.mode-btn.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.mode-btn.is-disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.pool-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-pill {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
}

.status-pill strong {
  color: var(--accent-2);
}

.status-pill.muted strong {
  color: var(--text);
}

.mode-notice {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--accent-2);
  background: rgba(255, 179, 71, 0.1);
  border: 1px solid rgba(255, 179, 71, 0.22);
  border-radius: 10px;
  padding: 6px 10px;
  text-align: center;
}

/* Stages */
.stage {
  margin: 16px 0 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Wheel Stage */
.wheel-stage {
  min-height: 290px;
}

#wheelCanvas {
  width: min(76vw, 290px);
  height: min(76vw, 290px);
  display: block;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.48));
}

.wheel-pointer {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.55rem;
  color: var(--accent-2);
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.75);
  z-index: 3;
  transition: transform 0.06s ease;
  pointer-events: none;
}

.wheel-pointer.pointer-bump {
  transform: translateX(-50%) rotate(-14deg) scale(1.08);
}

.wheel-hub {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent-2);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* Slot Machine Stage */
.slot-stage {
  min-height: 198px;
}

.slot-window {
  width: 100%;
  height: 192px;
  background: #0b0d12;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 10px 24px rgba(0, 0, 0, 0.75);
}

.slot-window::before,
.slot-window::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 62px;
  z-index: 2;
  pointer-events: none;
}

.slot-window::before {
  top: 0;
  background: linear-gradient(to bottom, #0b0d12 12%, transparent);
}

.slot-window::after {
  bottom: 0;
  background: linear-gradient(to top, #0b0d12 12%, transparent);
}

.slot-highlight {
  position: absolute;
  top: 64px;
  left: 10px;
  right: 10px;
  height: 64px;
  border-radius: 12px;
  border: 1.5px solid rgba(255, 179, 71, 0.6);
  background: rgba(255, 122, 69, 0.09);
  box-shadow: 0 0 20px rgba(255, 122, 69, 0.14);
  z-index: 1;
  pointer-events: none;
}

.slot-track {
  will-change: transform;
}

.slot-item {
  height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  text-align: center;
}

.slot-item-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.slot-item-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Empty Stage */
.empty-stage {
  min-height: 192px;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 12px;
}

.empty-icon {
  font-size: 2.2rem;
  opacity: 0.85;
}

.empty-msg {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

/* Primary Spin Button */
.spin-btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 15px 20px;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #160c05;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(255, 122, 69, 0.36);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, opacity 0.15s ease;
}

.spin-btn:hover:not(:disabled) {
  filter: brightness(1.06);
}

.spin-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.spin-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Result Card */
.result-card {
  border-color: rgba(255, 179, 71, 0.35);
  background: linear-gradient(180deg, rgba(255, 122, 69, 0.08), rgba(21, 25, 34, 0.96) 55%);
  animation: popIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.result-meta {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.meta-badge {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.meta-badge.accent {
  background: var(--accent-soft);
  color: var(--accent-2);
}

.result-name {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.result-tags {
  margin: 4px 0 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.action-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease, background 0.15s ease;
}

.action-link:hover {
  border-color: var(--border-strong);
  background: #242b3b;
}

.action-link:active {
  transform: scale(0.97);
}

.result-footer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.btn-confirm {
  flex: 1;
  border: 1px solid rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.12);
  color: var(--success);
  font-weight: 700;
  font-size: 0.88rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-confirm:active {
  transform: scale(0.98);
}

.btn-ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}

/* Filters */
.filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.filter-toggle {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  cursor: pointer;
}

.filter-toggle[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

.chevron {
  display: inline-block;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.filter-count {
  font-size: 0.72rem;
  background: var(--accent-soft);
  color: var(--accent-2);
  padding: 1px 7px;
  border-radius: 999px;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 6px;
}

.text-btn:hover {
  color: var(--text);
}

.filter-panel {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.chip:active {
  transform: scale(0.95);
}

.chip.active {
  background: var(--accent-soft);
  border-color: rgba(255, 122, 69, 0.55);
  color: #ffd7ba;
  font-weight: 600;
}

.chip.exclude.active {
  background: var(--danger-soft);
  border-color: rgba(244, 91, 105, 0.55);
  color: #ffb8bf;
  text-decoration: line-through;
}

/* Footer */
.footer {
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  padding: 6px 0 10px;
}

.footer p {
  margin: 3px 0;
}

.footer a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-note {
  opacity: 0.7;
  font-size: 0.72rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

@media (min-width: 560px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 82dvh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

@media (min-width: 560px) {
  .modal-sheet {
    border-radius: 20px;
    padding-bottom: 18px;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
}

.quick-add {
  display: flex;
  gap: 8px;
}

.quick-add input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.quick-add input:focus {
  border-color: var(--accent);
}

.btn-add {
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  background: var(--accent);
  color: #160c05;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
}

.modal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.candidate-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.candidate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.86rem;
}

.candidate-row.is-hidden-item {
  opacity: 0.45;
}

.candidate-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.candidate-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.candidate-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.candidate-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.74rem;
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
}

.mini-btn.cool {
  border-color: rgba(96, 165, 250, 0.4);
  color: #93c5fd;
}

.mini-btn.del {
  color: #fda4af;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: #232a3a;
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
