/* ===== Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; touch-action: manipulation; }
button, input, select, textarea { touch-action: manipulation; font-size: 16px; }
button { user-select: none; -webkit-user-select: none; }

:root {
  --bg: #0b1628;
  --surface: #142244;
  --surface2: #1e3560;
  --accent: #64d0ff;
  --accent-glow: rgba(100, 208, 255, 0.3);
  --accent2: #0299e8;
  --text: #f0f4fa;
  --text-dim: #9bb8d8;
  --green: #7affdd;
  --orange: #ffbb55;
  --red: #ff6b6b;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
html { height: -webkit-fill-available; }

.hidden { display: none !important; }

/* ===== Auth Screen ===== */
.screen { min-height: 100dvh; }

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 50% 30%, rgba(79,195,247,0.08) 0%, transparent 60%);
}

.auth-box {
  text-align: center;
  padding: 2rem;
  padding-bottom: 4rem;
}
.auth-box h1 {
  font-size: 2.4rem;
  margin-bottom: 0.3rem;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  letter-spacing: 0.1em;
}
.auth-box p {
  color: var(--text-dim);
  margin-bottom: 2rem;
  font-size: 1.3rem;
  letter-spacing: 0.15em;
}
.auth-box form {
  width: 280px;
  margin: 0 auto;
}
.auth-box input {
  display: block;
  width: 100%;
  margin: 0 0 0.8rem;
  padding: 1rem 1.2rem;
  font-size: 1.2rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
}
.auth-box input::placeholder {
  color: #ffffff;
  opacity: 0.35;
  font-weight: 700;
  letter-spacing: 0.3em;
}
.auth-box input:focus::placeholder { opacity: 0; }
.auth-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.auth-box button {
  display: block;
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-8px); }
  30%, 70% { transform: translateX(8px); }
}
.auth-box.shake { animation: shake 0.5s ease-in-out; }
.auth-box.shake input {
  border-color: #e94560 !important;
  box-shadow: 0 0 12px rgba(233, 69, 96, 0.4) !important;
}
.copyright {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  opacity: 0.85;
  letter-spacing: 0.12em;
  font-weight: 600;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ===== Main Screen ===== */
#main-screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
}

/* ===== Header ===== */
.app-header {
  padding: 1rem 1rem 0.3rem;
}
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.dkr-logo {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow), 0 0 48px rgba(100, 208, 255, 0.12);
  line-height: 1;
}
.dkr-sub {
  font-size: 0.75rem;
  letter-spacing: 0.35em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Help Button */
.help-btn {
  background: none;
  border: 1.5px solid var(--surface2);
  color: var(--text-dim);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  margin-top: 4px;
  transition: border-color 0.15s, color 0.15s;
}
.help-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  background: var(--bg);
  border-bottom: 1px solid var(--surface2);
  flex-shrink: 0;
  padding: 0 0.5rem;
  margin-top: 0.3rem;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.7rem 0;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== Tab Content ===== */
.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.8rem 1rem;
}
.tab-content.active { display: flex; flex-direction: column; }

/* Section Header (title + updated + reload) */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.section-header h2 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
}
.section-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Section Controls (inputs/buttons above lists) */
.section-controls {
  margin-bottom: 0.8rem;
  flex-shrink: 0;
}
.updated-at { font-size: 0.7rem; color: var(--text-dim); opacity: 0.6; }

.reload-btn {
  background: none;
  border: 1px solid var(--surface2);
  color: var(--text-dim);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.reload-btn:active { background: var(--surface); }

/* ===== Card List ===== */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ===== Press Animation (all interactive cards) ===== */
.member-card, .code-card, .log-card {
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}
.member-card:active, .code-card:active, .log-card:active {
  transform: scale(0.98);
  box-shadow: 0 0 12px rgba(100, 208, 255, 0.08);
}

/* ===== Member Card Wrapper (swipe support) ===== */
.member-card-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}
.swipe-action {
  position: absolute;
  right: 0;
  top: 0;
  height: 56px; /* match member-card height, not wrapper */
  width: 80px;
  background: var(--red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ===== Member Card ===== */
.member-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
  z-index: 1;
  will-change: transform;
}
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  flex-shrink: 0;
  object-fit: cover;
  border: 1.5px solid var(--surface2);
  transition: border-color 0.2s;
}
.member-card:active .member-avatar {
  border-color: var(--accent);
}
.member-info { flex: 1; min-width: 0; }
.member-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.member-meta {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}
.member-badges { display: flex; gap: 4px; flex-shrink: 0; }
.badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}
.badge-kid { background: var(--surface2); color: var(--text-dim); }
.badge-non372 { background: rgba(255,187,85,0.15); color: var(--orange); }
.badge-non372-dismissed { background: var(--surface2); color: var(--text-dim); opacity: 0.5; }

/* ===== Member Inline Detail (accordion) ===== */
.member-detail {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  padding: 12px 14px;
  border-radius: 0 0 var(--radius) var(--radius);
}
.member-detail.open {
  display: block;
}
.member-detail .player-detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.member-detail .player-detail-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--surface2); object-fit: cover;
}
.member-detail .player-detail-info h3 { font-size: 1rem; color: var(--text); }
.member-detail .player-detail-info .meta { font-size: 0.78rem; color: var(--text-dim); }

/* ===== Code Card ===== */
.code-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.code-name {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text);
  font-family: 'SF Mono', 'Menlo', monospace;
  letter-spacing: 0.5px;
}
.code-stats { display: flex; gap: 6px; font-size: 0.72rem; font-weight: 600; align-items: center; }
.code-stats span::before { opacity: 0.5; font-weight: 400; margin-right: 2px; }
.stat-ok::before { content: '✓'; }
.stat-dup::before { content: '–'; }
.stat-fail::before { content: '✗'; }
.stat-ok { color: var(--green); }
.stat-dup { color: var(--text-dim); }
.stat-fail { color: var(--red); }
.stat-na { color: var(--orange); }
.code-date { font-size: 0.7rem; color: var(--text-dim); margin-top: 3px; }
.code-recurring { font-size: 0.65rem; color: #a78bfa; margin-left: 6px; }

/* Code Results Accordion */
.code-results { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--surface2); }
.code-results.open { display: block; }
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 0.78rem;
}
.result-name {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.result-status { flex-shrink: 0; margin-left: 8px; font-weight: 700; }
.result-ok { color: var(--green); }
.result-dup { color: var(--text-dim); }
.result-err { color: var(--red); }
.result-na { color: var(--orange); }

/* ===== Search ===== */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 0.8rem;
  flex-shrink: 0;
}
.search-bar input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  outline: none;
}
.search-bar input:focus { border-color: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.search-bar button {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.7rem 1.2rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* Player Detail (search tab) — inline accordion */
.player-detail {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
}
/* Search result card wrapper for inline detail */
.search-card-wrapper {
  border-radius: var(--radius);
  overflow: hidden;
}
.search-detail {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  padding: 12px 14px;
}
.search-detail.open { display: block; }
.player-detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.player-detail-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--surface2); object-fit: cover;
}
.player-detail-info h3 { font-size: 1rem; color: var(--text); }
.player-detail-info .meta { font-size: 0.78rem; color: var(--text-dim); }
.timeline { margin-top: 8px; }
.timeline-item {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 6px 0;
  font-size: 0.78rem;
  border-left: 2px solid var(--surface2);
  padding-left: 12px;
  margin-left: 4px;
  align-items: flex-start;
}
.timeline-date { color: var(--text-dim); flex-shrink: 0; width: 80px; opacity: 0.7; }
.timeline-change { color: var(--text); }
.timeline-arrow { color: var(--text-dim); margin: 0 4px; }
.timeline-avatars {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  width: 100%;
  padding-left: 90px;
}
.timeline-av {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
  border: 1.5px solid var(--surface2);
}
.timeline-av-arrow {
  color: var(--text-dim);
  font-size: 0.7rem;
}

/* ===== Log Card ===== */
.log-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
}
.log-code {
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 3px;
}
.log-time { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 6px; }
.log-summary { display: flex; gap: 12px; font-size: 0.78rem; }

/* Log Results Accordion */
.log-results { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--surface2); }
.log-results.open { display: block; }

/* ===== Sort Toggle ===== */
.sort-toggle {
  background: none;
  border: 1px solid var(--surface2);
  color: var(--text-dim);
  border-radius: 6px;
  font-size: 0.7rem;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
}
.sort-toggle:active { background: var(--surface); }
.action-row {
  display: flex;
  gap: 6px;
}
.action-row input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.6rem 0.7rem;
  outline: none;
  font-size: 0.85rem;
}
.action-row input:focus { border-color: var(--accent); }
.btn-add {
  background: linear-gradient(135deg, #0a7e5a, #10b981);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-remove {
  background: linear-gradient(135deg, #8b2020, #c53030);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.action-status {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 6px;
  min-height: 1.2em;
}

/* ===== Dismiss Button ===== */
.dismiss-btn {
  background: none;
  border: 1px solid var(--surface2);
  color: var(--text-dim);
  border-radius: 4px;
  font-size: 0.65rem;
  padding: 2px 6px;
  cursor: pointer;
  flex-shrink: 0;
}
.dismiss-btn:active { background: var(--surface2); }

/* ===== Help Modal ===== */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.help-content {
  background: var(--surface);
  border-radius: 14px;
  padding: 1.5rem;
  max-width: 340px;
  width: 100%;
  border: 1px solid var(--surface2);
}
.help-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 1rem;
  text-align: center;
}
.help-section {
  margin-bottom: 0.8rem;
}
.help-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.help-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.help-close {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.7rem;
  background: var(--surface2);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.help-close:active { opacity: 0.8; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 4rem;
  left: 50%;
  transform: translateX(-50%) scale(0.82);
  z-index: 1300;
  background: rgba(4, 22, 14, 0.97);
  color: #3effa0;
  border: 2px solid #3effa0;
  border-radius: 16px;
  padding: 0.75rem 2rem;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  white-space: nowrap;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
.toast.error {
  background: rgba(30, 8, 8, 0.97);
  color: var(--red);
  border-color: var(--red);
}

/* ===== Empty / Loading ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  opacity: 0.6;
}
.inline-loading {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}
