/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d0f14;
  --bg2: #151820;
  --bg3: #1e2230;
  --border: #2a2f42;
  --text: #e8eaf0;
  --text2: #8892aa;
  --accent: #4f9eff;
  --my-team: #ed1c24;
  --danger: #ff4d6d;
  --warning: #ffb347;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

html {
  font-size: 14px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== ALERT BANNER ===== */
.alert-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(90deg, #ff1744, #ff6d00);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  animation: alertPulse 1s ease-in-out infinite alternate;
  box-shadow: 0 2px 20px rgba(255, 23, 68, 0.5);
}

.alert-banner.hidden {
  display: none;
}

.alert-icon {
  font-size: 1.4rem;
}

.alert-dismiss {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
}

@keyframes alertPulse {
  from {
    opacity: 1;
  }

  to {
    opacity: 0.8;
  }
}

/* ===== HEADER ===== */
.header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 2rem;
}

.logo-title {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--text);
}

.logo-sub {
  font-size: 0.8rem;
  color: var(--text2);
}

.my-team-badge {
  background: var(--my-team);
  color: #000;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}

.nav {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.nav-btn.active,
.nav-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-update {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text2);
}

.fetch-url {
  font-size: 0.7rem;
  color: var(--accent);
  background: rgba(79, 158, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(79, 158, 255, 0.2);
}

.update-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  display: inline-block;
  transition: background 0.3s;
}

.update-dot.active {
  background: var(--my-team);
  box-shadow: 0 0 8px var(--my-team);
  animation: blink 2s infinite;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

.load-btn {
  background: linear-gradient(135deg, #4f9eff, #7c5cff);
  border: none;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.load-btn:hover {
  opacity: 0.85;
}

.secondary-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 12px;
  font-weight: normal;
}

.secondary-btn:hover {
  background: var(--bg2);
  color: var(--text);
  border-color: var(--text2);
}

/* ===== PAGES ===== */
.page {
  display: none;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.page.active {
  display: block;
}

/* ===== SECTION HEADER ===== */
.section-header {
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}

/* ===== DASHBOARD LAYOUT ===== */
.dashboard-layout {
  display: grid;
  grid-template-columns: auto 320px;
  gap: 24px;
}

/* ===== MAP ===== */
.map-section {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}

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

.time-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.time-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.latest-btn {
  width: auto;
  padding: 0 10px;
  font-size: 0.8rem;
}

.play-btn {
  width: auto;
  padding: 0 10px;
  font-size: 0.8rem;
  background: var(--bg3);
}

.play-btn.playing {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.play-speed-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 6px;
  border-radius: 6px;
  height: 30px;
  font-size: 0.78rem;
  cursor: pointer;
}

.time-picker-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 8px;
  border-radius: 6px;
  height: 30px;
  font-size: 0.78rem;
  cursor: pointer;
}

.time-picker-input::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
}

.time-display {
  font-size: 0.82rem;
  color: var(--text2);
  min-width: 140px;
  text-align: center;
}

.map-container {
  position: relative;
  display: inline-block;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(10, 80px);
  grid-template-rows: repeat(10, 80px);
  gap: 3px;
  background: var(--bg);
  padding: 3px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.map-cell {
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.map-cell:hover {
  transform: scale(1.08);
  box-shadow: 0 0 16px rgba(79, 158, 255, 0.6);
  z-index: 10;
}

.map-cell.my-territory {
  box-shadow: 0 0 10px rgba(0, 212, 170, 0.5);
  border: 2px solid var(--my-team);
}

.map-cell.under-attack {
  animation: attackFlash 0.8s ease-in-out infinite alternate;
}

@keyframes attackFlash {
  from {
    box-shadow: 0 0 8px rgba(255, 77, 109, 0.3);
  }

  to {
    box-shadow: 0 0 20px rgba(255, 77, 109, 0.9), inset 0 0 10px rgba(255, 0, 0, 0.2);
  }
}

.cell-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  line-height: 1.1;
}

.cell-pct {
  font-size: 0.55rem;
  color: rgba(255, 255, 255, 0.7);
}

.cell-coord {
  font-size: 0.5rem;
  color: rgba(255, 255, 255, 0.5);
  position: absolute;
  top: 3px;
  left: 4px;
}

/* Dark text for white background (South team) */
.dark-text .cell-label,
.dark-text .cell-pct {
  color: #000 !important;
  text-shadow: none !important;
}
.dark-text .cell-coord {
  color: rgba(0, 0, 0, 0.6) !important;
}

.cell-init {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 0.7rem;
  color: #ffd700;
  text-shadow: 0 1px 2px #000;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 4px;
  border-radius: 4px;
}

.initial-base {
  box-shadow: inset 0 0 12px rgba(255, 215, 0, 0.4);
  border: 1px solid rgba(255, 215, 0, 0.8) !important;
}

.map-labels-x {
  display: flex;
  gap: 3px;
  padding: 0 3px;
}

.map-labels-x span,
.map-labels-y span {
  width: 80px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text2);
}

.map-labels-y {
  position: absolute;
  left: -24px;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 3px 0;
}

.map-labels-y span {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* ===== STATS ===== */
.stats-section {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.stats-section>div {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  margin-bottom: 0;
}

.team-stats {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}

.team-bar-item {
  margin-bottom: 10px;
}

.team-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.team-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.team-px {
  font-size: 0.75rem;
  color: var(--text2);
}

.bar-track {
  background: var(--bg3);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease;
}

.my-areas {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
}

.my-area-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  background: var(--bg3);
  font-size: 0.82rem;
  transition: background 0.2s;
  cursor: pointer;
}

.my-area-item:hover {
  background: rgba(79, 158, 255, 0.1);
}

.my-area-item.defending {
  border-left: 3px solid var(--danger);
}

.area-coord {
  font-weight: 700;
  color: var(--my-team);
}

.area-pct {
  color: var(--text2);
}

.alert-log {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  max-height: 180px;
  overflow-y: auto;
  flex: 1;
}

.alert-entry {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: rgba(255, 77, 109, 0.1);
  border-left: 4px solid var(--danger);
  font-size: 0.85rem;
  transition: transform 0.2s, background 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alert-entry:hover {
  transform: translateX(4px);
  background: rgba(255, 77, 109, 0.2);
}

.alert-entry.dark-text {
  color: #000;
}

.alert-entry.dark-text .alert-time {
  color: rgba(0, 0, 0, 0.6);
}

.alert-entry .alert-time {
  color: var(--text2);
  font-size: 0.72rem;
  align-self: flex-end;
}

.no-data {
  color: var(--text2);
  font-size: 0.82rem;
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  width: 1000px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: var(--bg3);
  border: none;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
}

.modal-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.breakdown-item {
  background: var(--bg3);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.8rem;
}

.breakdown-team {
  font-weight: 700;
}

.breakdown-val {
  color: var(--text2);
  font-size: 0.75rem;
}

/* Help Modal Specific */
.help-content {
  max-width: 800px;
}

.help-body {
  color: var(--text2);
  font-size: 0.9rem;
  line-height: 1.6;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 12px;
}

.help-body h4 {
  color: var(--text);
  font-size: 1rem;
  margin: 16px 0 8px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.help-body h4:first-child {
  margin-top: 0;
}

.help-body ul {
  list-style: none;
  margin-bottom: 20px;
  padding-left: 8px;
}

.help-body li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 8px;
}

.help-body li::before {
  content: "•";
  color: var(--accent);
  position: absolute;
  left: 0;
  font-weight: bold;
}

.help-body b {
  color: var(--text);
}

.help-body code {
  background: var(--bg3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  color: var(--accent);
}

/* ===== GRAPH PAGE ===== */
.graph-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.graph-controls {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.area-grid-picker {
  display: grid;
  grid-template-columns: repeat(10, 28px);
  gap: 3px;
}

.picker-cell {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg3);
  border: 1px solid var(--border);
  font-size: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  transition: all 0.15s;
}

.picker-cell:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.picker-cell.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

label {
  font-size: 0.82rem;
  color: var(--text2);
  margin-bottom: 6px;
  display: block;
}

.team-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.team-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.team-checkbox input {
  accent-color: var(--accent);
}

.team-checkbox span {
  font-size: 0.82rem;
}

.team-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  width: 100%;
  font-size: 0.82rem;
}

.graph-main {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  position: relative;
  min-height: 400px;
}

/* ===== ALL AREAS OVERVIEW ===== */
.all-areas-section {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}

.all-areas-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
}

.area-overview-cell {
  background: var(--bg3);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.area-overview-cell:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.area-overview-cell.my-territory {
  border-color: var(--my-team);
}

.aoc-coord {
  font-size: 0.6rem;
  color: var(--text2);
  margin-bottom: 4px;
}

.aoc-bar {
  height: 60px;
  display: flex;
  flex-direction: column-reverse;
  border-radius: 4px;
  overflow: hidden;
}

.aoc-bar-seg {
  width: 100%;
  transition: height 0.5s;
}

.aoc-leader {
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 4px;
}

.aoc-pct {
  font-size: 0.55rem;
  color: var(--text2);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg3);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .graph-layout {
    grid-template-columns: 1fr;
  }

  .map-grid {
    grid-template-columns: repeat(10, 50px);
    grid-template-rows: repeat(10, 50px);
  }

  .map-labels-x span {
    width: 50px;
  }

  .map-labels-y span {
    height: 50px;
  }

  .all-areas-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 600px) {

  /* Header adjustments */
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 16px;
  }

  .nav {
    justify-content: center;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-btn {
    font-size: 0.75rem;
    padding: 6px 10px;
    white-space: nowrap;
  }

  .header-right {
    flex-direction: column;
    align-items: stretch;
  }

  .last-update {
    justify-content: center;
    margin-bottom: 8px;
  }

  .load-btn {
    width: 50%;
  }

  /* Map adjustments */
  .map-section {
    padding: 12px;
  }

  .time-selector {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .map-grid {
    grid-template-columns: repeat(10, 32px);
    grid-template-rows: repeat(10, 32px);
  }

  .map-labels-x span {
    width: 32px;
    font-size: 0.6rem;
  }

  .map-labels-y span {
    height: 32px;
    font-size: 0.6rem;
  }

  .cell-label {
    font-size: 0.5rem;
  }

  .cell-pct,
  .cell-coord {
    display: none;
  }

  /* Hide extra details on tiny screens */
  .cell-init {
    font-size: 0.5rem;
    padding: 1px 2px;
  }

  /* Stats & Graphs */
  .page {
    padding: 12px;
  }

  .all-areas-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .modal-content {
    width: 95%;
    padding: 16px;
  }

  .area-grid-picker {
    grid-template-columns: repeat(10, 24px);
  }

  .picker-cell {
    width: 24px;
    height: 24px;
    font-size: 0.45rem;
  }
}

@media (max-width: 400px) {

  /* Ultra-small screens */
  .logo-title {
    font-size: 1rem;
  }

  .map-grid {
    grid-template-columns: repeat(10, 28px);
    grid-template-rows: repeat(10, 28px);
  }

  .map-labels-x span {
    width: 28px;
  }

  .map-labels-y span {
    height: 28px;
  }

  .cell-label {
    display: none;
  }

  /* On very small screens just show colors */
  .all-areas-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}