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

:root {
  /* ── App color palette ── */
  --bg:      #0d0d1a;
  --surface: #1a1a2e;
  --panel:   #16213e;
  --border:  #2a2a4a;
  --accent:  #7c4dff;
  --accent2: #e040fb;
  --text:    #e0e0f0;
  --muted:   #666688;
  --success: #4caf50;
  --danger:  #ef5350;
  --warn:    #ffd740;

  /* ── Ionic color system (dark purple M3 theme) ── */
  --ion-color-primary:                  #7c4dff;
  --ion-color-primary-rgb:              124, 77, 255;
  --ion-color-primary-contrast:         #ffffff;
  --ion-color-primary-contrast-rgb:     255, 255, 255;
  --ion-color-primary-shade:            #6d44e0;
  --ion-color-primary-tint:             #8a5fff;

  --ion-color-secondary:                #e040fb;
  --ion-color-secondary-rgb:            224, 64, 251;
  --ion-color-secondary-contrast:       #ffffff;
  --ion-color-secondary-contrast-rgb:   255, 255, 255;
  --ion-color-secondary-shade:          #c538dc;
  --ion-color-secondary-tint:           #e353fb;

  --ion-color-tertiary:                 #03dac6;
  --ion-color-tertiary-rgb:             3, 218, 198;
  --ion-color-tertiary-contrast:        #000000;
  --ion-color-tertiary-shade:           #03c0ae;
  --ion-color-tertiary-tint:            #1cdecc;

  --ion-color-success:                  #4caf50;
  --ion-color-success-rgb:              76, 175, 80;
  --ion-color-success-contrast:         #ffffff;
  --ion-color-success-shade:            #43a047;
  --ion-color-success-tint:             #5eb862;

  --ion-color-warning:                  #ffd740;
  --ion-color-warning-rgb:              255, 215, 64;
  --ion-color-warning-contrast:         #000000;
  --ion-color-warning-shade:            #e0bd38;
  --ion-color-warning-tint:             #ffdb53;

  --ion-color-danger:                   #ef5350;
  --ion-color-danger-rgb:               239, 83, 80;
  --ion-color-danger-contrast:          #ffffff;
  --ion-color-danger-shade:             #d24a47;
  --ion-color-danger-tint:              #f16462;

  --ion-color-medium:                   #666688;
  --ion-color-medium-rgb:               102, 102, 136;
  --ion-color-medium-contrast:          #ffffff;
  --ion-color-medium-shade:             #5a5a78;
  --ion-color-medium-tint:              #757594;

  --ion-color-light:                    #2a2a4a;
  --ion-color-light-rgb:                42, 42, 74;
  --ion-color-light-contrast:           #e0e0f0;
  --ion-color-light-shade:              #252540;
  --ion-color-light-tint:               #3f3f60;

  /* ── Ionic global background / text ── */
  --ion-background-color:               #0d0d1a;
  --ion-background-color-rgb:           13, 13, 26;
  --ion-text-color:                     #e0e0f0;
  --ion-text-color-rgb:                 224, 224, 240;

  /* ── Ionic surface tokens ── */
  --ion-card-background:                #1a1a2e;
  --ion-item-background:                #1e1e30;
  --ion-toolbar-background:             #16213e;
  --ion-toolbar-border-color:           #2a2a4a;
  --ion-border-color:                   #2a2a4a;
  --ion-tab-bar-background:             #16213e;

  color-scheme: dark;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

ion-app#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

hexman-landing,
hexman-help {
  display: block;
  height: 100%;
  overflow: hidden;
}

hexman-auth,
hexman-profile {
  display: block;
  height: 100%;
  overflow-y: auto;
}

/* ── Ionic component theme overrides ── */

ion-button {
  --border-radius: 8px;
  --padding-start: 14px;
  --padding-end: 14px;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  height: 40px;
}

ion-input {
  --border-color:            var(--border);
  --border-radius:           8px;
  --color:                   var(--text);
  --placeholder-color:       var(--muted);
  --highlight-color-focused: var(--accent);
  --background:              transparent;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
}

/* Segment → Material tab bar style */
ion-segment {
  --background: transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  width: 100%;
}

ion-segment-button {
  --background:         transparent;
  --background-checked: transparent;
  --color:              var(--muted);
  --color-checked:      var(--accent);
  --indicator-color:    var(--accent);
  --indicator-height:   2px;
  --border-radius:      0;
  --padding-top:        12px;
  --padding-bottom:     12px;
  min-height: 0;
  text-transform: none;
  letter-spacing: 0;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  font-weight: 500;
}

ion-list {
  background: transparent;
  padding: 0;
}

ion-item {
  --background:          var(--border);
  --color:               var(--text);
  --border-radius:       6px;
  --inner-border-width:  0;
  --min-height:          36px;
  font-size: 12px;
  margin-bottom: 4px;
  overflow: hidden;
  border-radius: 6px;
}

ion-radio {
  --color:         var(--muted);
  --color-checked: var(--accent);
}

/* Full-width inputs in auth / profile forms */
.auth-form ion-input { width: 100%; }
.auth-form ion-button { width: 100%; }

.username-hint {
  margin: -4px 0 4px;
  padding: 0 4px;
  font-size: 0.78rem;
  color: var(--ion-color-medium);
}
.username-hint--ok     { color: var(--ion-color-success); }
.username-hint--taken  { color: var(--ion-color-danger);  }
.username-hint--short  { color: var(--ion-color-medium);  }
.username-hint--checking { color: var(--ion-color-medium); }

/* === Material Icons utility === */
.mi {
  font-family: 'Material Icons Round';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}
.mi-sm { font-size: 14px; vertical-align: -2px; }


/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 8px;
  z-index: 9999;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  animation: fadeInUp .2s ease;
}
.toast-error { border-color: var(--danger); color: var(--danger); }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === Auth === */
.auth-container {
  width: 528px;
  max-width: calc(100% - 32px);
  margin: clamp(24px, 8vh, 80px) auto;
  padding: 32px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  font-family: "Girassol", serif;
  font-size: 28px;
  text-align: center;
  color: var(--accent);
  letter-spacing: 3px;
}

/* Both forms sit in the same grid cell so the container never shrinks
   smaller than the taller (Register) form. */
.auth-forms-area {
  display: grid;
  grid-template-areas: "form";
}

.auth-form {
  grid-area: form;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form.inactive {
  visibility: hidden;
  pointer-events: none;
}

.role-select {
  display: flex;
  gap: 20px;
  color: var(--text);
  align-items: center;
}

.role-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
}

.hidden { display: none !important; }

/* === Lobby / Maps page === */
.maps-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.maps-appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.maps-brand {
  font-family: "Girassol", serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 3px;
}

.maps-appbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-info { color: var(--muted); font-size: 13px; margin-right: 4px; }

.maps-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.maps-page-title {
  font-size: 24px;
  font-weight: 500;
  color: var(--text);
}

.action-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  user-select: none;
}
.action-card:hover {
  border-color: var(--accent);
  background: var(--panel);
  transform: translateY(-1px);
}
.action-card:active { transform: translateY(0); }

.action-card-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
  flex-shrink: 0;
}

.action-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.action-card-sub {
  font-size: 12px;
  color: var(--muted);
}

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

.map-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.map-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.map-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.map-card-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.map-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-status {
  font-size: 11px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
}
.status-waiting { background: #2a3a2a; color: var(--success); }
.status-active  { background: #3a1a3a; color: var(--accent2); }
.status-open    { background: #2a3a2a; color: var(--success); }
.status-closed  { background: #3a1a1a; color: var(--danger); }

.muted { color: var(--muted); }

.map-tier-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.tier-free { background: #1a2233; color: #6699cc; }
.tier-paid { background: #2a1a3a; color: var(--accent2); }

ion-fab-button {
  --border-radius: 14px;
}

.pixi-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.pixi-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* === Map (unified DM + player view) === */
.map-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === Game === */
.game-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.game-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}


/* === Modals === */

/* Glass blur backdrop (all screen sizes) */
ion-modal {
  --backdrop-opacity: 1;
}
ion-modal::part(backdrop) {
  background: rgba(13, 13, 26, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Compact card style on desktop */
@media (min-width: 600px) {
  ion-modal {
    --width: 440px;
    --height: 256px;
    --border-radius: 16px;
    --box-shadow:
      0 32px 80px rgba(0, 0, 0, 0.8),
      0 0 0 1px rgba(124, 77, 255, 0.15);
  }
}

/* Modal toolbar padding + Girassol title font */
ion-modal ion-toolbar {
  --padding-start: 16px;
  --padding-end: 16px;
}
ion-modal ion-title::part(native) {
  font-family: "Girassol", serif;
  letter-spacing: 2px;
  color: var(--accent);
}

/* Modal form body – flex column inside ion-content or directly in ion-modal */
.modal-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px 28px 32px;
  overflow-y: auto;
}

/* === Profile === */
.profile-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* === Subscription section === */
.subscription-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subscription-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.subscription-summary {
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 0;
  flex-wrap: wrap;
}

.slot-count {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  margin-right: 6px;
}

.slot-breakdown {
  font-size: 12px;
  color: var(--muted);
}

.subscription-cost {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.slot-adjuster {
  display: flex;
  align-items: center;
  gap: 16px;
}

.slot-adj-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.slot-adj-btn:hover:not(:disabled) {
  background: var(--panel);
  border-color: var(--accent);
}
.slot-adj-btn:disabled { opacity: 0.35; cursor: default; }

.slot-adj-value {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* === Slot indicator in lobby === */
.map-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.slot-indicator {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
}

.slot-indicator--full { color: var(--warn); }

/* No-slots modal body text */
.slot-modal-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}
.slot-modal-text strong { color: var(--accent); }

/* === Rename modal (NPC / player display name) === */
ion-modal.rename-modal {
  --height: 256px;
  --width: 440px;
  --border-radius: 16px;
}

@media (max-width: 480px) {
  ion-modal.rename-modal {
    --height: auto;
    --max-height: 60vh;
    --width: 100%;
    --border-radius: 16px 16px 0 0;
  }
}

/* Rename button row (optional Clear + Save) */
.rename-btn-row {
  display: flex;
  gap: 10px;
}
.rename-btn-row ion-button[expand="block"] {
  flex: 1;
}

/* === My Coin modal === */
ion-modal.coin-settings-modal {
  --height: 420px;
  --width: 440px;
  --border-radius: 16px;
}

@media (max-width: 480px) {
  ion-modal.coin-settings-modal {
    --height: auto;
    --max-height: 80vh;
    --width: 100%;
    --border-radius: 16px 16px 0 0;
  }
}

.cs-avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.cs-avatar-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  cursor: pointer;
  display: block;
}
.cs-avatar-wrap:hover .cs-avatar-circle { border-color: var(--accent); }

.cs-avatar-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.15s;
}

.cs-avatar-edit-icon {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  pointer-events: none;
}

.cs-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cs-avatar-initial {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  user-select: none;
}

.cs-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: -8px;
}

.cs-border-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cs-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--muted);
  flex-shrink: 0;
}

.cs-border-row input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  padding: 2px;
}

/* Danger button text inside ion-alert */
.alert-btn-danger  { color: var(--warn, #e74c3c) !important; }
.alert-btn-success { color: #2ecc71 !important; }

/* Leave demo alert — horizontal buttons: Cancel left, Home + Sign Up/In right */
.leave-demo-alert .alert-button-group {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0 12px 12px;
}
.leave-demo-alert .alert-button {
  flex: 0 0 auto;
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 8px;
}
.leave-demo-alert .alert-button:first-child {
  margin-right: auto;
}

/* === Embedded checkout modal === */
ion-modal.checkout-modal {
  --height: 100%;
  --width: 100%;
  --border-radius: 0;
}

@media (min-width: 600px) {
  ion-modal.checkout-modal {
    --width: 480px;
    --height: 88vh;
    --border-radius: 16px;
  }
}

.checkout-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px 24px;
}

#stripe-checkout-container { width: 100%; }


/* === Demo View === */
.demo-welcome-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 12px;
}

.demo-welcome-warning {
  border: 1.5px solid #c0392b;
  background: rgba(192, 57, 43, 0.12);
  border-radius: 8px;
  padding: 10px 14px;
  color: #e74c3c;
}

.demo-saving-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,13,26,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.demo-saving-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 48px;
}

.demo-saving-box p {
  color: var(--text);
  font-size: 15px;
}

ion-modal.demo-welcome-modal {
  --height: 510px;
  --width: 440px;
  --border-radius: 16px;
}

ion-modal.demo-auth-modal {
  --height: 520px;
  --width: 440px;
  --border-radius: 16px;
}

ion-modal.demo-noslots-modal {
  --height: 230px;
  --width: 440px;
  --border-radius: 16px;
}

@media (max-width: 480px) {
  ion-modal.demo-welcome-modal,
  ion-modal.demo-auth-modal,
  ion-modal.demo-noslots-modal {
    --height: auto;
    --max-height: 90vh;
    --width: 100%;
    --border-radius: 16px 16px 0 0;
  }
}
