/* Pixel-art retro theme, built to match the "1M" crown logo: chunky black
   borders, gold accents, a blocky pixel-style display font for headings,
   readable body text everywhere else. The homepage is a fullscreen
   landscape "app" (map fills the screen, no page scroll); every other
   page stays a normal, scrollable page. */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: #fdf6e3;
  color: #111111;
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  touch-action: manipulation; /* blocks double-tap-to-zoom on mobile */
}

.pixel-font { font-family: 'Press Start 2P', Georgia, serif; letter-spacing: 0.02em; }

a { color: #0000cc; text-decoration: underline; }
a:visited { color: #551a8b; }
a:hover { color: #a67c00; }

#page-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 12px 40px;
}

/* On the homepage only: fullscreen landscape "app" layout, no page
   scroll — header, map, and footer all fit within one viewport. */
body.is-home { overflow: hidden; height: 100dvh; }
body.is-home #page-wrap {
  max-width: none;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 8px;
}
body.is-home #site-header { flex-shrink: 0; padding: 4px 0; margin-bottom: 2px; }
body.is-home #content { flex: 1; min-height: 0; display: flex; }
body.is-home #page-home { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.is-home .tagline { flex-shrink: 0; margin: 0 0 4px; font-size: 10.5px; }
body.is-home #map-area { flex: 1; min-height: 0; }
body.is-home #grid-wrap { height: 100%; }
body.is-home #grid-canvas { height: 100%; aspect-ratio: unset; }
body.is-home .small-note { flex-shrink: 0; margin: 3px 0; font-size: 9.5px; }
body.is-home #site-footer { flex-shrink: 0; margin-top: 3px; padding-top: 4px; }

/* ============================== HEADER ================================= */
#site-header {
  padding: 10px 0;
  border-bottom: 4px solid #111;
  margin-bottom: 16px;
}
.header-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  flex-shrink: 0;
  display: block;
  line-height: 0;
}
.logo img {
  height: 48px;
  width: auto;
  display: block;
  image-rendering: pixelated;
}
body.is-home .logo img { height: 36px; }

#hamburger-btn {
  display: none;
  font-size: 20px;
  background: #ffcc00;
  border: 2px solid #111;
  padding: 4px 10px;
  cursor: pointer;
  margin-left: auto;
}

/* Nav rendered as a continuous, joined button strip (segmented control),
   not pipe-separated text links. */
#site-nav {
  display: flex;
  flex: 1;
  justify-content: center;
  border: 2px solid #111;
}
#site-nav a {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  font-size: 11.5px;
  text-decoration: none;
  color: #333;
  border-right: 2px solid #111;
  white-space: nowrap;
}
#site-nav a:last-child { border-right: none; }
#site-nav a:hover { background: #f2f2f2; }
#site-nav a.active { background: #ffcc00; color: #111; font-weight: bold; }

#header-pct-pill {
  flex-shrink: 0;
  background: #111;
  color: #ffcc00;
  font-weight: bold;
  font-size: 12px;
  padding: 6px 12px;
  border: 2px solid #111;
}

/* ============================== CONTENT ================================= */
#content { min-height: 300px; }
.hidden { display: none !important; }

.tagline { font-size: 12.5px; color: #444; margin: 0 0 14px; text-align: center; font-style: italic; }

/* ============================ MAP AREA =================================== */
#map-area {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
#grid-wrap {
  flex: 1;
  min-width: 0;
  border: 4px solid #111;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.25);
  line-height: 0; /* kill inline canvas gap */
  position: relative;
}
#grid-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: #e8dcc0;
  cursor: crosshair;
  touch-action: pan-y; /* only vertical page scroll — no horizontal drag hijack */
}

/* Toolbar lives beside the map (vertical column) on wide screens. */
#map-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  width: 128px;
}
.toolbar-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border: 1px solid #999;
  padding: 4px;
  background: #f5f5f5;
}
.toolbar-group button {
  font-size: 12px;
  padding: 6px 8px;
  cursor: pointer;
  background: #fff;
  border: 1px solid #ccc;
  width: 100%;
}
.toolbar-group button.active { background: #0066cc; color: #fff; border-color: #0066cc; }

.small-note { font-size: 11px; color: #666; text-align: center; margin: 10px 0; }

/* ===================== SELECTION NOTIFICATION ============================ */
#selection-notification {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 150;
  width: 280px;
  background: #ffffe0;
  border: 2px solid #333;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  padding: 12px 14px;
}
#selection-close {
  position: absolute; top: 4px; right: 8px;
  background: none; border: none; font-size: 18px; cursor: pointer; color: #666;
}
#selection-notification strong { display: block; font-size: 12.5px; margin-bottom: 8px; padding-right: 16px; }
.selection-actions { display: flex; gap: 6px; }
.selection-actions button { flex: 1; padding: 7px 8px; font-size: 12px; }

/* ============================ CMS PAGES ================================= */
#page-cms h2, #page-pixel-list h2, #page-stats h2 { font-family: Georgia, serif; border-bottom: 1px solid #ccc; padding-bottom: 4px; }
#cms-content p { margin: 8px 0; }
#cms-content h3 { font-family: Georgia, serif; font-size: 15px; margin: 18px 0 4px; }

#pixel-list-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
#pixel-list-table th, #pixel-list-table td { border: 1px solid #ccc; padding: 5px 8px; text-align: left; }
#profile-orders-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
#profile-orders-table th, #profile-orders-table td { border: 1px solid #ccc; padding: 5px 8px; text-align: left; }
#profile-orders-table th { background: #eee; }
#profile-orders-table .col-title { max-width: 90px; }
#profile-orders-table td:nth-child(4) { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#profile-orders-table .btn-edit-order { background: #ffcc00; color: #111; border: 1px solid #333; padding: 3px 9px; font-size: 11px; cursor: pointer; }
#profile-orders-table .muted-cell { color: #999; font-style: italic; }
#profile-data-section button { padding: 4px 10px; font-size: 11px; }
#referral-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 10px 0 20px; }
#referral-table th, #referral-table td { border: 1px solid #ccc; padding: 5px 8px; text-align: left; }
#referral-table th { background: #eee; }
#pixel-list-table th { background: #eee; }

/* ============================ STATISTICI PAGE ============================= */
#stats-numbers { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 24px; }
.stat-box { flex: 1; min-width: 130px; border: 1px solid #999; background: #f7f7f7; padding: 10px 8px; text-align: center; overflow: hidden; }
.stat-label { display: block; font-size: 10.5px; text-transform: uppercase; color: #777; letter-spacing: 0.04em; white-space: nowrap; }
.stat-value {
  display: block;
  font-weight: bold;
  margin-top: 2px;
  /* Scales down automatically so long numbers (1.000.000) never overflow
     the box, on any screen width, without needing a fixed media-query size. */
  font-size: clamp(13px, 4.2vw, 22px);
  white-space: nowrap;
}
#chart-history { width: 100%; height: auto; border: 1px solid #ccc; background: #fff; margin-bottom: 24px; }

/* "Battle bar": animated sold-vs-free bar instead of a static donut.
   Widths are set inline via JS (percentages) and transition smoothly
   whenever the numbers refresh. */
#battle-bar {
  display: flex;
  height: 54px;
  border: 2px solid #222;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  margin-bottom: 26px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
#battle-sold, #battle-free {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  white-space: nowrap;
  overflow: hidden;
}
#battle-sold {
  width: 0%;
  background: linear-gradient(135deg, #ff3b3b, #a80000);
  background-size: 200% 200%;
  animation: battle-shimmer 3s ease-in-out infinite;
}
#battle-free {
  flex: 1;
  background: linear-gradient(135deg, #2fbf5f, #0a7a34);
  background-size: 200% 200%;
  animation: battle-shimmer 3s ease-in-out infinite reverse;
}
@keyframes battle-shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
/* Pulsing "clash" line at the boundary between the two sides */
#battle-clash {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--battle-split, 0%);
  width: 4px;
  margin-left: -2px;
  background: #fff;
  box-shadow: 0 0 12px 3px rgba(255,255,255,0.9);
  animation: battle-pulse 1.1s ease-in-out infinite;
  transition: left 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes battle-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

#top-table-wrap { max-height: 480px; overflow-y: auto; border: 1px solid #ccc; }
#top-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#top-table th, #top-table td { border-bottom: 1px solid #eee; padding: 6px 8px; text-align: left; }
#top-table th { background: #eee; position: sticky; top: 0; z-index: 1; }
#top-table tr:nth-child(even) { background: #fafafa; }

/* ============================== FOOTER =================================== */
#site-footer { text-align: center; font-size: 11px; color: #888; margin-top: 30px; border-top: 3px solid #111; padding-top: 10px; }
#site-footer a { color: #888; }
.footer-legal-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px 14px; margin: 0 0 6px; }
.footer-legal-links a { text-decoration: underline; }
#footer-content { margin: 0; }
.account-btn {
  display: inline-block;
  background: #ffcc00;
  color: #111 !important;
  font-weight: bold;
  text-decoration: none !important;
  padding: 4px 12px;
  border: 2px solid #111;
  margin: -2px 0;
}
.account-btn:hover { background: #ffd633; }

/* =============================== TOOLTIP =================================== */
#tooltip {
  position: absolute;
  z-index: 50;
  display: flex;
  gap: 8px;
  padding: 8px;
  background: #ffffe0;
  border: 1px solid #999;
  max-width: 220px;
  pointer-events: none;
  font-size: 11px;
}
#tooltip img { width: 40px; height: 40px; object-fit: cover; border: 1px solid #ccc; flex-shrink: 0; }
#tooltip-title { font-weight: bold; }
.tooltip-disclaimer { font-size: 9px; color: #999; margin-top: 4px; }

/* =============================== MODALS =================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
  overflow-y: auto;
}
.modal {
  width: 100%; max-width: 400px; max-height: 90vh; overflow-y: auto;
  background: #fff; border: 2px solid #333; padding: 18px; position: relative;
}
.modal-wide { max-width: 520px; }
.modal h2 { font-family: Georgia, serif; margin-top: 0; font-size: 18px; border-bottom: 1px solid #ccc; padding-bottom: 6px; }
.modal-close { position: absolute; top: 10px; right: 10px; background: none; border: none; font-size: 20px; cursor: pointer; color: #666; }

form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
form label { font-size: 12px; font-weight: bold; display: flex; flex-direction: column; gap: 3px; }
form input[type=text], form input[type=email], form input[type=url], form input[type=number],
form input[type=password], form select, form textarea {
  font-family: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid #999;
}
form textarea { font-family: monospace; font-size: 12px; }

form button, #savelink-copy {
  background: #ffcc00; border: 1px solid #333; padding: 8px 14px; font-weight: bold; font-size: 13px; cursor: pointer;
}
form button:hover { background: #ffd633; }
form button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error { background: #ffe0e0; border: 1px solid #cc0000; color: #900; padding: 8px 10px; font-size: 12px; }

#buyer-type-fieldset { border: 1px solid #ccc; padding: 8px 10px; }
#buyer-type-fieldset legend { font-size: 11px; font-weight: bold; padding: 0 4px; }
label.inline { flex-direction: row !important; align-items: center; gap: 6px !important; font-weight: normal !important; display: inline-flex !important; margin-right: 14px; }
label.inline input { width: auto; }
.consent-row {
  display: block !important;
  font-size: 12px;
  line-height: 1.5;
  margin: 4px 0;
}
.consent-row input {
  margin-right: 6px;
  vertical-align: middle;
}
#pj-fields { display: flex; flex-direction: column; gap: 8px; border-left: 3px solid #ffcc00; padding-left: 10px; }

#upload-preview img, #manage-current-preview img, #admin-upload-preview img {
  max-width: 100%; max-height: 120px; margin-top: 6px; border: 1px solid #ccc;
}

.save-link-box { display: flex; gap: 6px; margin-top: 10px; }
.save-link-box input { flex: 1; padding: 6px 8px; border: 1px solid #999; font-size: 12px; }

/* Admin */
.admin-tabs { display: flex; gap: 6px; margin: 10px 0; }
.admin-tab-btn { flex: 1; padding: 6px; border: 1px solid #999; background: #eee; font-size: 12px; cursor: pointer; }
.admin-tab-btn.active { background: #333; color: #fff; }
#admin-list { list-style: none; padding: 0; margin: 10px 0 0; max-height: 260px; overflow-y: auto; }
#admin-list li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border: 1px solid #ddd; font-size: 11px; margin-bottom: 4px; }
#admin-list button { background: #cc0000; color: #fff; border: none; padding: 3px 8px; font-size: 10px; cursor: pointer; }
#admin-page-content { min-height: 200px; }
#admin-referral-table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-top: 10px; }
#admin-referral-table th, #admin-referral-table td { border: 1px solid #ccc; padding: 5px 7px; text-align: left; word-break: break-all; }
#admin-referral-table th { background: #eee; }
#admin-referral-table button { background: #cc0000; color: #fff; border: none; padding: 3px 8px; font-size: 10px; cursor: pointer; }

/* =============================== TOASTS ==================================== */
#toast-container {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.toast {
  padding: 8px 14px; font-size: 12px; font-weight: bold; color: #111;
  background: #ffffe0; border: 1px solid #999;
}
.toast.error { border-color: #cc0000; color: #900; background: #ffe0e0; }
.toast.success { border-color: #2a7; color: #063; background: #e0ffe8; }

/* ============================ RESPONSIVE ================================== */
@media (max-width: 760px) {
  .header-bar { position: relative; }
  #hamburger-btn { display: block; order: 1; }
  .logo { order: 2; flex: 1; text-align: center; }
  .logo img { height: 34px; margin: 0 auto; }
  body.is-home .logo img { height: 26px; }
  #header-pct-pill { order: 3; }
  #site-nav {
    display: none;
    position: absolute;
    left: 12px; right: 12px; top: 100%;
    flex-direction: column;
    background: #fff;
    z-index: 60;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    order: 4;
  }
  #site-nav.open { display: flex; }
  #site-nav a { border-right: none; border-bottom: 1px solid #eee; padding: 10px; }

  /* Toolbar drops below the map and becomes a horizontal row on narrow
     screens — there's no room for a side column next to the grid. */
  #map-area { flex-direction: column; }
  #map-toolbar { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .toolbar-group { flex-direction: row; flex: 1; }

  #selection-notification { left: 10px; right: 10px; width: auto; top: auto; bottom: 10px; }

  body { font-size: 12.5px; }

  /* On mobile the fullscreen home layout stacks the toolbar under a
     shorter map (there isn't room for a wide landscape map AND a
     horizontal toolbar row AND the footer in one viewport), but it still
     avoids page scroll — same principle as desktop, tuned proportions. */
  body.is-home #map-area { flex-direction: column; gap: 4px; }
  body.is-home #grid-wrap { flex: 1; min-height: 0; height: auto; }
  body.is-home #map-toolbar { flex-shrink: 0; }
  body.is-home .toolbar-group button { padding: 4px 6px; font-size: 10.5px; }
  body.is-home #site-footer { font-size: 9px; }
  body.is-home .footer-legal-links { gap: 6px 10px; }
}

