/* Responsive polish layer: keep one page, adapt the same UI for desktop / tablet / mobile. */
html {
  background: #05070c;
  scroll-behavior: smooth;
}

body {
  overflow-x: hidden;
}

button,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

.tile,
.rank-item,
.etf-watch-item,
.detail-tab,
.ghost-button,
.segmented button {
  touch-action: manipulation;
}

.tile {
  text-align: left;
}

.sidebar,
.detail-panel {
  align-self: start;
}

@media (min-width: 1321px) {
  .sidebar,
  .detail-panel {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    overflow: auto;
  }

  .sidebar::-webkit-scrollbar,
  .detail-panel::-webkit-scrollbar {
    width: 6px;
  }

  .sidebar::-webkit-scrollbar-thumb,
  .detail-panel::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.2);
  }
}

@media (max-width: 1320px) and (min-width: 901px) {
  .app-shell {
    width: min(1180px, calc(100vw - 40px));
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .heatmap {
    grid-template-columns: repeat(18, minmax(0, 1fr));
  }

  .detail-panel {
    min-height: 360px;
  }
}

@media (max-width: 900px) {
  body {
    background:
      radial-gradient(circle at 10% -8%, rgba(96, 165, 250, 0.18), transparent 34%),
      linear-gradient(180deg, #070a10 0%, #07101f 44%, #05070c 100%);
  }

  .app-shell {
    width: min(100% - 28px, 760px);
    padding-bottom: 36px;
  }

  .topbar {
    gap: 16px;
    margin-bottom: 16px;
  }

  .subtitle {
    max-width: 56rem;
    line-height: 1.65;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-card {
    position: sticky;
    top: 0;
    z-index: 30;
    align-items: stretch;
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.96), rgba(12, 18, 30, 0.9));
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  }

  .heatmap-panel,
  .sidebar,
  .detail-panel {
    min-width: 0;
  }

  .heatmap-head {
    align-items: flex-start;
  }

  .heatmap {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    min-height: 520px;
  }

  .tile {
    min-height: 104px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: 100%;
    padding: 14px 12px 28px;
  }

  .topbar {
    display: grid;
    align-items: stretch;
    gap: 12px;
  }

  .eyebrow {
    margin-bottom: 6px;
    font-size: 10px;
    letter-spacing: 0.12em;
  }

  h1 {
    font-size: 34px;
    line-height: 1.05;
    letter-spacing: -0.045em;
  }

  h2 {
    font-size: 16px;
  }

  .subtitle {
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.7;
  }

  .market-card {
    width: 100%;
    justify-items: stretch;
    gap: 8px;
  }

  .market-status {
    width: 100%;
    min-width: 0;
    border-radius: 18px;
    padding: 12px 14px;
  }

  .market-actions {
    width: 100%;
    justify-content: space-between;
    gap: 6px;
    border-radius: 18px;
    overflow-x: auto;
  }

  .ghost-button,
  .switch-control,
  .refresh-countdown {
    flex: none;
  }

  .summary-grid {
    display: flex;
    gap: 10px;
    margin: 0 -12px 12px;
    padding: 0 12px 4px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .summary-grid::-webkit-scrollbar {
    display: none;
  }

  .summary-card {
    flex: 0 0 168px;
    min-height: 116px;
    padding: 15px;
    border-radius: 18px;
    scroll-snap-align: start;
  }

  .summary-value {
    font-size: 24px;
  }

  .summary-note {
    line-height: 1.55;
  }

  .control-card {
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 0 -4px 12px;
    padding: 12px;
    border-radius: 20px;
  }

  .control-group > span {
    margin-bottom: 6px;
    font-size: 11px;
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .segmented::-webkit-scrollbar {
    display: none;
  }

  .segmented button {
    flex: 1 0 auto;
    min-width: max-content;
    padding: 9px 12px;
    font-size: 13px;
  }

  .search-box input {
    height: 42px;
    border-radius: 16px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: auto;
  }

  .sidebar {
    order: 1;
  }

  .heatmap-panel {
    order: 2;
  }

  .detail-panel {
    order: 3;
  }

  .panel {
    border-radius: 20px;
  }

  .panel-head {
    padding: 14px;
  }

  .heatmap-head {
    display: grid;
    gap: 10px;
  }

  .legend {
    width: 100%;
    justify-content: space-between;
  }

  .legend-bar {
    flex: 1;
    width: auto;
    max-width: 180px;
  }

  .rank-lists {
    display: flex;
    gap: 10px;
    padding: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .rank-lists::-webkit-scrollbar {
    display: none;
  }

  .rank-block {
    flex: 0 0 86%;
    border-radius: 16px;
    scroll-snap-align: start;
  }

  .rank-title {
    padding: 11px 12px;
  }

  .rank-item,
  .etf-watch-item {
    padding: 11px 12px;
  }

  .rank-name {
    font-size: 13px;
  }

  .heatmap {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: auto;
    padding: 12px;
  }

  .tile {
    width: 100%;
    min-height: 116px;
    border-radius: 18px;
    padding: 14px;
  }

  .tile:hover,
  .tile.is-selected {
    transform: none;
  }

  .tile.is-selected {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.24), 0 12px 30px rgba(0, 0, 0, 0.28);
  }

  .tile-top {
    align-items: center;
  }

  .tile-name {
    font-size: 16px;
    line-height: 1.25;
  }

  .tile-badge {
    display: inline-flex;
    align-items: center;
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tile-change {
    margin-top: 8px;
    font-size: 31px;
  }

  .tile-meta {
    gap: 5px;
    font-size: 11px;
    line-height: 1.45;
  }

  .tile-small .tile-badge,
  .tile-small .tile-meta span:nth-child(n + 3) {
    display: block;
  }

  .detail-hero {
    padding: 18px;
  }

  .detail-hero h2 {
    font-size: 26px;
  }

  .detail-change {
    font-size: 36px;
  }

  .detail-tabs {
    display: flex;
    grid-template-columns: none;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .detail-tabs::-webkit-scrollbar {
    display: none;
  }

  .detail-tab {
    flex: 0 0 auto;
    min-width: 88px;
    padding: 9px 10px;
  }

  .metric-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
  }

  .metric {
    padding: 11px;
    border-radius: 14px;
  }

  .metric strong {
    font-size: 15px;
  }

  .detail-section {
    padding: 0 12px 14px;
  }

  .table-headline {
    display: grid;
    align-items: start;
    gap: 4px;
  }

  .stock-table {
    overflow-x: auto;
    border-radius: 14px;
  }

  .stock-row {
    min-width: 420px;
    grid-template-columns: 50px minmax(76px, 1fr) 60px 60px;
    padding: 10px;
  }

  .etf-card {
    align-items: flex-start;
    border-radius: 14px;
    padding: 12px;
  }

  .tooltip {
    display: none;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 10px;
  }

  h1 {
    font-size: 30px;
  }

  .summary-card {
    flex-basis: 156px;
  }

  .rank-block {
    flex-basis: 92%;
  }

  .metric-list {
    grid-template-columns: 1fr;
  }
}
