body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  color: #222;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #ffffff;
  border-bottom: 1px solid #ddd;
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 18px;
  margin: 0;
}

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

button {
  border: 0;
  border-radius: 8px;
  padding: 9px 12px;
  background: #222;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}

button.secondary {
  background: #666;
}

button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.status {
  padding: 8px 16px;
  color: #555;
  font-size: 13px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: min(380px, 100%);
  background: #fff;
  padding: 24px;
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.15);
}

.login-card h2 { margin: 0 0 16px; font-size: 20px; }

.login-card input {
  box-sizing: border-box;
  width: 100%;
  padding: 12px;
  border: 1px solid #bbb;
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 10px;
}

.login-card button { width: 100%; }
.login-message { min-height: 1.5em; color: #b42318; font-size: 13px; margin-top: 10px; }

.filter-bar {
  padding: 0 16px 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.grid-size-control {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.grid-size-control button {
  padding: 6px 8px;
}

.filter-button.active { background: #b77900; }

.favorite-level-control {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid #d7b56d;
  border-radius: 8px;
  background: rgba(255,255,255,.92);
}

.favorite-star {
  min-width: 0;
  border-radius: 0;
  padding: 7px 5px;
  background: transparent;
  color: #8a5a00;
  font-size: 20px;
  line-height: 1;
}

.favorite-star + .favorite-star {
  border-left: 1px solid rgba(215,181,109,.55);
}

.favorite-star.active {
  color: #b77900;
}

.favorite-star:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid #222;
  outline-offset: -2px;
}

.card-favorite {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 2;
}

.modal-favorite-host {
  display: flex;
  align-items: center;
}

.grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 5px rgba(0,0,0,.12);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-height: 260px;
}

.thumb {
  width: 100%;
  height: 180px;
  background: #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.username {
  font-weight: 700;
  word-break: break-all;
}

.missing { color: #c0392b; }
.small { font-size: 12px; color: #666; }

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99;
  padding: 16px;
  touch-action: pan-y pinch-zoom;
  overscroll-behavior: contain;
}

.modal {
  background: #fff;
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
}

.modal-header {
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.modal-content { padding: 12px; }

.main-image {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  background: #eee;
  border-radius: 10px;
  -webkit-user-drag: none;
  user-select: none;
  touch-action: pan-y pinch-zoom;
}

.media-wrap { position: relative; }

.media-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  background: rgba(0,0,0,.58);
  font-size: 24px;
}

.media-prev { left: 10px; }
.media-next { right: 10px; }

.media-count {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  color: #fff;
  background: rgba(0,0,0,.62);
  font-size: 12px;
}

.multi-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(0,0,0,.65);
  font-size: 12px;
}

.thumb { position: relative; }

.body-text {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14px;
  margin-top: 12px;
}

a {
  color: #1a5fd0;
  text-decoration: none;
}

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

.app-heading { min-width: 0; }

.build-number {
  margin-top: 2px;
  color: #777;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 640px) {
  header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 4px 8px;
    padding: 7px 8px;
  }

  .app-heading {
    display: contents;
  }

  header h1 {
    grid-column: 1 / -1;
    grid-row: 1;
    font-size: 14px;
    line-height: 1.15;
    white-space: nowrap;
  }

  .build-number {
    grid-column: 1;
    grid-row: 2;
    margin: 0;
    font-size: 9px;
  }

  .actions {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
  }

  .actions button {
    min-width: 0;
    min-height: 28px;
    padding: 5px 4px;
    border-radius: 6px;
    overflow: hidden;
    font-size: 9px;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status {
    padding: 6px 8px 4px;
    font-size: 10px;
  }

  .filter-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 5px 6px;
    padding: 0 8px 6px;
    overflow: visible;
  }

  .hashtag-filter-label {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }

  .hashtag-filter {
    grid-column: 2;
    grid-row: 1;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    height: 32px;
    padding: 0 28px 0 9px;
    border: 1px solid #999;
    border-radius: 7px;
    background: #fff;
    font-size: 12px;
  }

  .filter-bar button {
    grid-row: 2;
    min-width: 0;
    min-height: 32px;
    padding: 5px 3px;
    border-radius: 7px;
    font-size: 10px;
    white-space: nowrap;
  }

  #allFilter { grid-column: 1; }
  #level0Filter { grid-column: 2; }
  #level1Filter { grid-column: 3; }
  #level2Filter { grid-column: 4; }
  #level3Filter { grid-column: 5; }

  .filter-bar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .hashtag-filter-label {
    grid-column: 1;
  }

  .hashtag-filter {
    grid-column: 2 / 6;
  }

  .grid-size-control {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-content: flex-end;
  }

  .grid-size-control button {
    min-height: 28px;
    padding: 4px 8px;
    font-size: 9px;
  }

  .filter-bar .small {
    grid-column: 1 / -1;
    grid-row: 4;
    font-size: 9px;
    white-space: nowrap;
  }

  .grid {
    gap: 5px;
    padding: 5px;
  }

  .grid.grid-large { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.grid-medium { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.grid-small { grid-template-columns: repeat(5, minmax(0, 1fr)); }

  .card {
    min-width: 0;
    min-height: 0;
    border-radius: 7px;
  }

  .thumb {
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .thumb img { object-fit: cover; }

  .card-body {
    min-width: 0;
    padding: 5px;
    gap: 2px;
  }

  .username {
    overflow: hidden;
    font-size: 9px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card-body .small {
    overflow: hidden;
    font-size: 7px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .favorite-star {
    padding: 4px 2px;
    font-size: 11px;
  }

  .card-favorite {
    left: 4px;
    top: 4px;
  }

  .multi-badge {
    top: 4px;
    right: 4px;
    padding: 2px 4px;
    font-size: 7px;
  }
}
