/* Responsive country picker + mobile interaction layer. */
#country-picker {
  flex-shrink: 0;
  background: var(--off);
  border-bottom: var(--border);
}

#country-search-wrap {
  padding: 7px 9px;
  border-bottom: 1px solid var(--off2);
  background: var(--white);
}

#country-search {
  width: 100%;
  height: 32px;
  padding: 5px 9px;
  border: 1px solid #c9c8c2;
  border-radius: 3px;
  background: var(--white);
  color: var(--black);
  font-family: "Syne", sans-serif;
  font-size: 10px;
  outline: none;
}

#country-search:focus {
  border-color: var(--black);
  box-shadow: 0 0 0 1px var(--black);
}

#country-search::-webkit-search-cancel-button {
  cursor: pointer;
}

#countries-container {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  max-height: 178px;
}

.country-btn {
  width: 100%;
  min-width: 0;
  min-height: 56px;
  padding: 6px 2px;
  border: 0;
  border-right: 1px solid var(--off2);
  border-bottom: 1px solid var(--off2);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  color: var(--black);
}

.country-btn:nth-child(4n) {
  border-right: 0;
}

.country-btn.active {
  background: var(--white);
  box-shadow: inset 0 -3px 0 var(--red);
}

.country-btn:hover:not(.active) {
  background: var(--off2);
}

.country-btn .fi,
.country-flag-image {
  display: block;
  width: 31px;
  height: 21px;
  object-fit: cover;
  flex: 0 0 auto;
}

.country-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1;
}

.country-empty {
  grid-column: 1 / -1;
  padding: 13px 8px;
  text-align: center;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
}

#logos-container {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  padding: 10px;
}

.logo-item {
  min-width: 0;
  min-height: 52px;
  padding: 6px;
}

@media (max-width: 720px), (hover: none) and (pointer: coarse) {
  :root {
    --mobile-step-w: 110px;
    --mobile-logo-size: 52px;
  }

  html, body {
    width: 100%;
    min-height: 100%;
    overscroll-behavior: none;
  }

  body {
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  #workspace {
    min-width: 0;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  #canvas-toolbar {
    height: max(48px, env(safe-area-inset-top) + 48px);
    padding-top: env(safe-area-inset-top);
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    gap: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .toolbar-left {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
  }

  #journey-title {
    font-size: 14px;
    font-weight: 700;
    width: 100%;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    line-height: 1.2;
  }

  .toolbar-right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 5px;
  }

  .toolbar-right .btn-text {
    display: none !important;
  }

  .toolbar-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
  }

  #sidebar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .logos-header {
    padding: 10px 14px;
  }

  .logos-search-wrap {
    padding: 8px 12px;
  }

  #logo-search {
    height: 36px;
    font-size: 12px;
  }

  #logos-container {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 10px 12px 80px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .logo-item {
    min-height: 80px;
    padding: 6px 4px 5px;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }

  .logo-item-visual {
    min-height: 44px;
  }

  .logo-item-visual img {
    max-height: 44px;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: high-quality;
  }

  .logo-item-caption {
    font-size: 9px;
    line-height: 1.1;
    margin-top: 3px;
  }

  #canvas-paper {
    padding: 14px;
    align-items: flex-end;
    justify-content: flex-start;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  .staircase-wrapper {
    width: max-content;
    min-width: max-content;
    min-height: 280px;
    padding: 120px 28px 60px;
    gap: 0;
    flex-shrink: 0;
  }

  .step {
    width: var(--mobile-step-w);
    min-width: var(--mobile-step-w);
  }

  .step-content {
    padding-bottom: 8px;
    gap: 5px;
  }

  .step-logos {
    gap: 4px;
    padding: 0 4px;
  }

  .step-logo,
  .step-unknown {
    width: var(--mobile-logo-size);
    height: var(--mobile-logo-size);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: high-quality;
  }

  .date-input {
    width: calc(100% - 8px);
    min-width: 0;
    max-width: calc(100% - 8px);
    font-size: 10px;
    line-height: 1.35;
    padding: 4px 2px;
  }

  .step-actions {
    display: flex !important;
    width: 100%;
    gap: 3px;
    padding: 3px;
    margin-top: 2px;
    background: rgba(250, 250, 248, 0.96);
    border: 1px solid #ddd;
    border-radius: 4px;
  }

  .step-btn {
    min-width: 28px;
    min-height: 30px;
    padding: 4px 6px;
    font-size: 9px;
    border-radius: 2px;
  }
}

@media (max-width: 360px) {
  #logos-container {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 8px 70px 8px;
  }
  .logo-item { min-height: 75px; }
  .logo-item-caption { font-size: 8.5px; }
}
