* { margin: 0; padding: 0; box-sizing: border-box; touch-action: manipulation; -ms-touch-action: manipulation; }
button, input, select, textarea { touch-action: manipulation; -webkit-touch-callout: none; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(79,195,247,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(2,136,209,0.05) 0%, transparent 60%);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; pointer-events: none; }

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

/* ===== 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;
}

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  z-index: 200;
  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;
}

.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: 1.5rem;
  font-size: 1.1rem;
}

.auth-box input {
  display: block;
  width: 260px;
  margin: 0 auto 1rem;
  padding: 1rem 1.2rem;
  font-size: 1.4rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
}

.auth-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.auth-box button {
  padding: 1rem 3rem;
  font-size: 1.2rem;
  font-weight: 600;
  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);
}

/* Cloudflare badge */
.cf-badge {
  margin-top: 2rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  opacity: 0.6;
  letter-spacing: 0.02em;
}

/* Shake animation for auth failure */
@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;
}

/* ===== Main Screen ===== */
#main-screen {
  padding: 1rem;
  padding-bottom: 2rem;
  max-width: 480px;
  margin: 0 auto;
}

/* ===== Top Bar (Header + Map) ===== */
.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding: 0;
}

.app-header {
  text-align: left;
  flex-shrink: 0;
  padding-top: 0;
}

.dkr-logo {
  font-size: 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.6rem;
  letter-spacing: 0.35em;
  color: var(--text-dim);
  margin-top: 2px;
}

.map-selected {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 0.5rem;
}

/* ===== Target Map ===== */
.target-map {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
  margin-top: 0.25rem;
}

.map-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.map-cell {
  width: 68px;
  height: 58px;
}

.map-btn {
  width: 68px;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.map-btn .map-icon { font-size: 1.1rem; }
.map-btn .map-label { font-size: 0.65rem; letter-spacing: 0.05em; }

.map-btn.active {
  background: linear-gradient(135deg, #1a4a7a, #2a6ab0);
  border-color: var(--accent);
  color: #fff;
  transform: scale(1.04);
  box-shadow: 0 0 20px var(--accent-glow), 0 0 40px rgba(79,195,247,0.15);
}

.castle-btn .map-icon { font-size: 1.2rem; }

/* ===== Section Header ===== */
.section-header {
  margin-bottom: 0.75rem;
}

.section-header h2 {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 600;
}

.section-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

/* ===== Big Add Button ===== */
.big-add-btn {
  display: block;
  width: 100%;
  padding: 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--green);
  border: 1px dashed rgba(102,255,204,0.4);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.big-add-btn:active {
  background: var(--surface2);
  border-color: var(--green);
}

/* ===== Player List ===== */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 1.5rem;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  transition: all 0.15s;
}

.player-card:active {
  transform: scale(1.02);
  box-shadow: 0 0 12px var(--accent-glow);
}

.player-card.inactive {
  opacity: 0.35;
}

.player-toggle {
  font-size: 1.1rem;
  width: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 0;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-label {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.player-card.inactive .player-toggle {
  opacity: 0.6;
}

.player-info {
  flex: 1;
  min-width: 0;
}

.player-name {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-time {
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 0;
}

.player-time:hover, .player-time:active {
  color: var(--green);
}

.player-time .no-time {
  color: var(--orange);
  font-weight: 600;
  font-style: normal;
}

.player-actions {
  display: flex;
  gap: 6px;
  align-items: stretch;
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 50px;
  padding: 4px 4px;
  white-space: nowrap;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.action-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.action-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.action-btn.buff-btn.active {
  border-color: var(--fire);
  background: rgba(255, 109, 58, 0.12);
  box-shadow: 0 0 10px var(--fire-glow);
}

.action-btn.buff-btn.active .action-label {
  color: var(--fire);
}

.buff-timer {
  font-size: 0.6rem;
  color: var(--fire);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.delete-action-btn:active {
  background: rgba(255, 109, 58, 0.15);
  border-color: var(--fire);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5,10,25,0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.modal-content h3 {
  margin-bottom: 1rem;
  color: var(--accent);
}

.modal-content label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.modal-content input {
  display: block;
  width: 100%;
  padding: 0.7rem;
  font-size: 1.1rem;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  margin-bottom: 0.75rem;
}

.modal-content input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 1rem;
}

.btn-primary, .btn-secondary {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
}
.btn-secondary { background: var(--surface2); color: var(--text-dim); }

.optional { font-size: 0.7rem; color: var(--text-dim); }

.time-inputs {
  display: flex;
  gap: 12px;
}

.time-input-group { flex: 1; }

.time-steppers {
  display: flex;
  gap: 4px;
}

.step-btn {
  flex: 1;
  padding: 0.5rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.step-btn:active {
  background: var(--accent2);
  border-color: var(--accent);
}

/* ===== Candidate List ===== */
.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 0.5rem;
}

.candidate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-size: 0.9rem;
}

.candidate-item:active {
  background: var(--surface2);
  border-color: var(--accent);
}

.candidate-tag {
  font-size: 0.65rem;
  background: var(--accent2);
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.candidate-add {
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ===== Manual Add ===== */
.manual-add {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--surface2);
}

.manual-add label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

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

.manual-add-row input {
  flex: 1;
  margin-bottom: 0;
}

.manual-add-row .btn-primary {
  flex-shrink: 0;
}

/* ===== FID Search Result ===== */
.fid-result {
  margin-top: 0.5rem;
}
.fid-found {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.fid-name {
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
}
.fid-info {
  color: var(--text-dim);
  font-size: 0.75rem;
  width: 100%;
}
.fid-found .btn-primary {
  flex-shrink: 0;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
}
.fid-error {
  color: var(--fire);
  font-size: 0.85rem;
  padding: 0.3rem 0;
}

/* ===== Calculate + Result ===== */
.lang-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 0.5rem;
}

.lang-btn {
  flex: 1;
  padding: 0.45rem 0;
  font-size: 0.8rem;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn.active {
  background: var(--surface2);
  color: var(--accent);
  border-color: var(--accent);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1rem;
}

.actions-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 0.4rem;
}

.calc-btn {
  flex: 1;
  padding: 0.9rem;
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #1565c0, var(--accent));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.1s;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.calc-btn:active { transform: scale(0.97); }

.result-area {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
}

.result-area pre {
  font-family: inherit;
  font-size: 1rem;
  white-space: pre-wrap;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.copy-btn {
  width: 100%;
  padding: 0.7rem;
  font-size: 1rem;
  background: linear-gradient(135deg, #00695c, #00897b);
  color: #fff;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.copy-btn.copied {
  background: var(--surface2);
  color: var(--accent);
  text-shadow: none;
}

/* ===== Reset ===== */
.reset-section {
  text-align: center;
  margin-top: 2rem;
  padding-bottom: 2rem;
}
.reset-btn {
  background: transparent;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
}
.reset-btn:active {
  background: rgba(255,255,255,0.05);
}
.logout-btn {
  background: transparent;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.logout-btn:active {
  background: rgba(255,255,255,0.05);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.empty-state p {
  margin-bottom: 1rem;
}

/* ===== Loading ===== */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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