/* Ninja Rooftop Dash — Midnight Edo Lacquer & Vermilion 16-Bit UI */
:root {
  --bg-deep: #070917;
  --bg-panel: rgba(13, 17, 36, 0.94);
  --bg-card: rgba(20, 26, 52, 0.92);
  --border-subtle: rgba(148, 163, 184, 0.22);
  --border-crimson: rgba(244, 63, 94, 0.48);
  --border-gold: rgba(245, 158, 11, 0.5);
  --crimson: #f43f5e;
  --crimson-dark: #be123c;
  --gold: #fbbf24;
  --cyan: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --parchment: #fef3c7;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  height: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 50% 15%, #1c1538 0%, #090c1d 55%, #050711 100%);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

/* Top HUD Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  background: rgba(8, 11, 24, 0.94);
  border-bottom: 1px solid rgba(244, 63, 94, 0.28);
  flex-shrink: 0;
  z-index: 10;
}

.hud-left, .hud-right, .hud-center {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(25, 32, 62, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.22);
  font-size: 12.5px;
  line-height: 1.1;
  white-space: nowrap;
}

.hud-lbl {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.hud-pill strong {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.hud-combo {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(244, 63, 94, 0.35));
  border-color: var(--gold);
  animation: pulseCombo 0.55s ease infinite alternate;
}

.hud-combo strong {
  color: var(--gold);
}

@keyframes pulseCombo {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.district-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fda4af;
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.36);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.daily-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fef08a;
  background: rgba(234, 179, 8, 0.2);
  border: 1px solid rgba(250, 204, 21, 0.5);
  padding: 3px 7px;
  border-radius: 999px;
}

.hud-hp {
  color: #fb7185;
  letter-spacing: 1px;
}

.hud-shields {
  color: #38bdf8;
  margin-left: 2px;
}

.hud-koku strong {
  color: var(--gold);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.85);
  color: #f8fafc;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.icon-btn:hover {
  background: #334155;
  border-color: var(--cyan);
}

/* Main Stage */
.stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  gap: 8px;
  width: 100%;
  overflow: hidden;
}

.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 1060px;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  width: min(100%, calc(100% * 16 / 9));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  border: 2px solid rgba(244, 63, 94, 0.42);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
  background: #0b0e24;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* In-Canvas Floating HUD Elements */
.challenge-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 700;
  color: #fde68a;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
}

.boss-hud {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 88%);
  background: rgba(10, 12, 26, 0.88);
  border: 1.5px solid rgba(244, 63, 94, 0.72);
  border-radius: 10px;
  padding: 6px 10px;
  pointer-events: none;
  z-index: 6;
  box-shadow: 0 6px 24px rgba(244, 63, 94, 0.3);
}

.boss-hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.boss-name {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fbbf24;
}

.boss-hint {
  font-size: 9.5px;
  font-weight: 700;
  color: #fda4af;
  letter-spacing: 0.04em;
}

.boss-bar-track {
  width: 100%;
  height: 9px;
  background: rgba(15, 23, 42, 0.95);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.boss-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #e11d48 0%, #f59e0b 100%);
  transition: width 0.14s ease-out;
}

/* Mobile / Touch Controls */
.touch-controls {
  display: none;
  width: 100%;
  max-width: 680px;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 6px;
  flex-shrink: 0;
}

.touch-left, .touch-right {
  display: flex;
  gap: 8px;
}

.touch-left {
  flex: 1.15;
}

.touch-right {
  flex: 0.95;
}

.touch-btn {
  flex: 1;
  min-height: 54px;
  border-radius: 12px;
  border: 1.5px solid rgba(148, 163, 184, 0.35);
  background: rgba(20, 28, 54, 0.92);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.38);
}

.touch-btn:active, .touch-btn.pressed {
  transform: scale(0.96);
}

.touch-jump {
  border-color: rgba(56, 189, 248, 0.65);
  background: linear-gradient(180deg, rgba(14, 116, 144, 0.45), rgba(15, 23, 42, 0.94));
}

.touch-slide {
  border-color: rgba(148, 163, 184, 0.5);
  background: linear-gradient(180deg, rgba(51, 65, 85, 0.55), rgba(15, 23, 42, 0.94));
}

.touch-slash {
  border-color: rgba(244, 63, 94, 0.8);
  background: linear-gradient(180deg, rgba(190, 18, 60, 0.68), rgba(30, 14, 34, 0.96));
}

.tb-key {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.tb-sub {
  font-size: 9.5px;
  font-weight: 700;
  color: #cbd5e1;
  letter-spacing: 0.03em;
}

/* Footer Bar (studio-bar.js dock) */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: rgba(7, 10, 22, 0.96);
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
  z-index: 15;
}

/* Fixed Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(5, 7, 18, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.card {
  width: 100%;
  max-width: 520px;
  max-height: min(90dvh, 720px);
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(20, 22, 46, 0.98) 0%, rgba(11, 14, 31, 0.99) 100%);
  border: 1.5px solid rgba(244, 63, 94, 0.45);
  border-radius: 16px;
  padding: 18px 18px 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.title-crest {
  text-align: center;
}

.crest-eyebrow {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--gold);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.36);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 6px;
}

.game-title {
  margin: 0;
  font-size: clamp(22px, 5vw, 31px);
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff7ed 0%, #fda4af 55%, #f43f5e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
}

.game-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.4;
}

.ov-challenge-box {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 12.5px;
  color: #fef08a;
  text-align: center;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.stat-cell {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 7px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-lbl {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.stat-cell strong {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}

.stat-koku strong {
  color: var(--gold);
}

.next-unlock {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.14), rgba(192, 132, 252, 0.14));
  border: 1px solid rgba(56, 189, 248, 0.38);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 12px;
  color: #e0f2fe;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.next-unlock strong {
  color: var(--gold);
}

.lb-submit-row {
  display: flex;
  gap: 7px;
}

.lb-submit-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  outline: none;
}

.lb-submit-row input:focus {
  border-color: var(--gold);
}

.lb-submit-msg {
  font-size: 12px;
  text-align: center;
  color: #6ee7b7;
  font-weight: 700;
}

.share-preview {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.4;
  background: rgba(8, 12, 28, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 10px;
  padding: 9px 11px;
  color: #fef3c7;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  min-width: 110px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  color: #fff;
  transition: transform 0.12s ease, filter 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.09);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #e11d48 0%, #f43f5e 100%);
  border-color: #fda4af;
  box-shadow: 0 6px 20px rgba(244, 63, 94, 0.35);
}

.btn-crimson {
  background: linear-gradient(135deg, #581c87 0%, #9333ea 100%);
  border-color: #d8b4fe;
}

.btn-gold {
  background: linear-gradient(135deg, #b45309 0%, #f59e0b 100%);
  border-color: #fde68a;
  color: #1c1917;
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.32);
  font-size: 12.5px;
  padding: 9px 10px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.meta-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  padding-top: 9px;
}

.meta-strip strong {
  color: #f8fafc;
}

/* Dojo & Leaderboard Modals */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
}

.modal-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.dojo-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.koku-badge {
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid var(--border-gold);
  color: var(--gold);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
}

.close-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.close-btn:hover {
  background: #334155;
  color: #fff;
}

.dojo-tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.85);
  color: #94a3b8;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.tab-btn.active {
  background: rgba(244, 63, 94, 0.24);
  border-color: var(--crimson);
  color: #fff;
}

.dojo-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dojo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.dojo-item.equipped {
  border-color: var(--gold);
  background: rgba(245, 158, 11, 0.1);
}

.dojo-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.dojo-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.24);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.dojo-meta {
  min-width: 0;
  flex: 1;
}

.dojo-name {
  font-size: 13.5px;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dojo-lvl {
  font-size: 10.5px;
  color: var(--cyan);
  font-weight: 800;
}

.dojo-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dojo-buy-btn {
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-gold);
  background: linear-gradient(135deg, #b45309, #f59e0b);
  color: #1c1917;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.dojo-buy-btn.equip-btn {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--cyan);
  color: #e0f2fe;
}

.dojo-buy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.clan-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  border: 1.5px solid #fff;
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 9px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 13px;
}

.lb-rank {
  width: 26px;
  font-weight: 900;
  color: var(--gold);
}

.lb-name {
  flex: 1;
  font-weight: 700;
  color: #f8fafc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-dist {
  font-size: 11.5px;
  color: var(--cyan);
  font-weight: 700;
}

.lb-score {
  font-weight: 900;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.lb-empty {
  text-align: center;
  padding: 20px 10px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Mobile & Touch Responsive Layout */
@media (max-width: 820px), (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
  .footer-hint {
    display: none;
  }
}

@media (max-width: 600px) {
  .hud-bar {
    padding: 5px 7px;
    gap: 4px;
  }
  .hud-center {
    display: none;
  }
  .hud-pill {
    padding: 3px 6px;
    font-size: 11.5px;
    gap: 3px;
  }
  .hud-lbl {
    font-size: 9px;
  }
  .icon-btn {
    width: 28px;
    height: 28px;
    font-size: 12.5px;
  }
  .stage-wrap {
    padding: 5px 6px;
    gap: 6px;
  }
  #game-canvas {
    border-radius: 9px;
  }
  .boss-hud {
    top: 6px;
    padding: 4px 8px;
  }
  .boss-hint {
    display: none;
  }
  .touch-btn {
    min-height: 50px;
    border-radius: 10px;
  }
  .tb-key {
    font-size: 12px;
  }
  .tb-sub {
    font-size: 9px;
  }
  .card {
    padding: 14px 13px 12px;
    gap: 9px;
  }
  .stats-grid {
    gap: 5px;
  }
  .stat-cell strong {
    font-size: 14.5px;
  }
  .action-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }
  .secondary-row #share-btn:not(.hidden) {
    grid-column: 1 / -1;
  }
  .btn {
    padding: 9px 6px;
    font-size: 11.5px;
    min-width: 0;
    width: 100%;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
  }
  .lb-submit-row {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 6px;
  }
  .lb-submit-row input {
    padding: 8px 9px;
    font-size: 12px;
  }
}
