:root {
  --v2-gutter: 10px;
  --v2-sidebar: clamp(340px, 32.65vw, 480px);
}

html,
body {
  height: 100%;
  overflow: hidden;
}

button,
input,
select,
textarea {
  letter-spacing: 0;
}

button {
  line-height: 1;
}

body {
  background: var(--page);
}

html.modal-open,
body.modal-open {
  overflow: hidden !important;
  overscroll-behavior: none;
}

dialog {
  overscroll-behavior: contain;
}

.welcome-dialog {
  inset: 0;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr) auto;
}

.welcome-dialog[open] {
  display: grid;
}

.welcome-copy {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.welcome-actions {
  min-height: 0;
  flex: 0 0 auto;
}

.archive-shell {
  width: 100%;
  height: 100vh;
  padding: var(--v2-gutter);
  display: grid;
  grid-template-columns: var(--v2-sidebar) minmax(0, 1fr);
  gap: var(--v2-gutter);
}

@supports (height: 100dvh) {
  .archive-shell { height: 100dvh; }
  .welcome-dialog { height: 100dvh; max-height: 100dvh; }
}

.archive-sidebar,
.browser-card {
  min-width: 0;
  min-height: 0;
  border-radius: 9px;
  background: var(--panel);
  overflow: hidden;
}

.archive-sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 10px;
  overflow: hidden;
  scrollbar-color: #55516b transparent;
  scrollbar-width: thin;
}

.browser-toolbar {
  flex: 0 0 auto;
  min-height: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 20px;
  background: transparent;
  border-radius: 0;
}

.search-box {
  grid-column: 1 / -1;
  height: 38px;
  border-radius: 8px;
  padding: 0 10px;
}

.search-box input {
  font-size: 12px;
  font-weight: 650;
}

.browser-toolbar > select {
  grid-column: 1;
  max-width: none;
}

.filter-panel {
  min-height: 0;
  padding: 18px 0 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px 20px;
  background: transparent;
  border-radius: 0;
  align-content: start;
  overflow-y: auto;
  scrollbar-color: #55516b transparent;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}

.filter-panel label {
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

select,
input[type="number"] {
  height: 34px;
  border-radius: 7px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.filter-actions {
  grid-column: 1 / -1;
  margin-top: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.filter-actions > button,
.filter-actions .bundle-button {
  width: 100%;
  height: 34px;
  border-radius: 7px;
  padding: 0 10px;
  font-size: 11px;
}

.filter-actions .bundle-button {
  grid-column: 1 / -1;
  margin-left: 0;
}

.sidebar-actions {
  margin-top: 0;
  padding-top: 24px;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 10px;
}

.sidebar-actions .header-button,
.sidebar-actions .osu-login {
  width: 134px;
  height: 34px;
  border-radius: 7px;
  padding: 0 12px;
  font-size: 11px;
}

.notification-badge {
  min-width: 18px;
  height: 18px;
  margin-left: 7px;
  padding: 0 5px;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  background: var(--pink);
  color: #fff;
  font-size: 9px;
}

#detail-dialog {
  max-height: calc(100vh - 28px);
  overflow-y: auto;
}

.replay-comments {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.comments-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.comments-heading h3 { margin: 0; font-size: 15px; }
.comments-heading span { color: var(--faint); font-size: 11px; font-weight: 800; }
.comment-list { display: grid; gap: 7px; }
.comment-list.comments-collapsed .comment-item:nth-child(n + 4) { display: none; }
.comment-empty { padding: 18px 10px; color: var(--faint); text-align: center; font-size: 11px; }
.comment-expand { margin: 8px auto 0; display: block; border: 0; background: transparent; color: var(--muted); font-size: 10px; font-weight: 800; cursor: pointer; }
.comment-expand:hover { color: #fff; }

.comment-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--control);
  border-left: 3px solid transparent;
}

.comment-item.comment-unreviewed { border-left-color: var(--pink); }
.comment-item.comment-hidden { opacity: .68; }

.comment-avatar { width: 34px; height: 34px; display: grid; place-items: center; overflow: hidden; border-radius: 8px; background: #5c5678; color: #fff; font-size: 10px; font-weight: 900; }
.comment-avatar b, .comment-avatar img { grid-area: 1 / 1; }
.comment-avatar img { width: 34px; height: 34px; display: block; border-radius: inherit; object-fit: cover; }
.comment-avatar img.avatar-failed { display: none; }
.comment-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.comment-meta > span { display: inline-flex; align-items: baseline; gap: 7px; min-width: 0; }
.comment-meta a, .comment-login { color: #e5dff5; text-decoration: none; font-size: 11px; font-weight: 800; }
.comment-meta a:hover, .comment-login:hover { color: var(--pink); }
.comment-meta time { color: var(--faint); font-size: 9px; }
.comment-item p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.score-comment-status { padding: 2px 5px; border-radius: 4px; background: #4b3c4a; color: #efadb8; font-size: 8px; text-transform: uppercase; letter-spacing: .05em; }
.score-comment-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 8px; }
.comment-action { height: 25px; border: 0; border-radius: 6px; padding: 0 9px; background: var(--button); color: var(--text); font-size: 9px; font-weight: 800; cursor: pointer; }
.comment-action:hover { filter: brightness(1.12); }
.comment-action.delete { background: #5a303d; color: #ffc2cc; }
.comment-action:disabled { opacity: .45; cursor: wait; }
.comment-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 9px; margin-top: 9px; }
.comment-form textarea { min-height: 62px; resize: vertical; border: 0; border-radius: 8px; padding: 10px; background: var(--control); color: var(--text); outline: none; font: inherit; font-size: 11px; line-height: 1.4; }
.comment-form textarea:focus { outline: 2px solid var(--pink); outline-offset: -2px; }
.comment-login { display: inline-block; margin-top: 10px; }

.sidebar-actions .user-menu {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
}

.sidebar-actions .user-menu img,
.sidebar-actions .user-menu span {
  display: none;
}

.sidebar-actions .user-menu a {
  width: 134px;
  height: 34px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--pink);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.sidebar-actions .user-menu a:hover {
  color: #fff;
  background: var(--pink-strong);
}

.browser-card {
  height: 100%;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr) 48px;
  gap: 0;
  padding: 10px;
}

.view-switcher {
  width: 100%;
  height: 38px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.view-button {
  width: 100%;
  height: 38px;
  border-radius: 7px;
  background: var(--control);
  font-size: 11px;
}

.view-button.active {
  background: var(--pink);
}

.view-button:hover {
  filter: brightness(1.08);
}

.results-heading {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.replay-list {
  min-height: 0;
  padding: 0;
  background: transparent;
  overflow: auto;
  scrollbar-color: #55516b transparent;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}

.filter-panel::-webkit-scrollbar,
.replay-list::-webkit-scrollbar,
#detail-dialog::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.filter-panel::-webkit-scrollbar-track,
.replay-list::-webkit-scrollbar-track,
#detail-dialog::-webkit-scrollbar-track {
  background: transparent;
}

.filter-panel::-webkit-scrollbar-thumb,
.replay-list::-webkit-scrollbar-thumb,
#detail-dialog::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #55516b;
}

.replay-row {
  min-height: 67px;
  margin: 0 0 8px;
  padding: 7px 9px;
  display: grid;
  grid-template-columns: 52px minmax(230px, 1fr) minmax(330px, 42%) 32px;
  gap: 10px;
  border-radius: 8px;
  background: var(--row);
}

.grade {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  font-size: 25px;
}

.map-title {
  font-size: 13px;
  line-height: 1.18;
}

.map-subtitle {
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.15;
}

.mods {
  min-height: 11px;
  margin-top: 3px;
  gap: 4px;
}

.mod {
  font-size: 9px;
  line-height: 1.1;
}

.result-data {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.result-data div {
  min-width: 0;
  text-align: center;
}

.result-data strong {
  font-size: 12px;
  white-space: nowrap;
}

.result-data span {
  display: none;
}

.row-action,
.folder-download {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-size: 14px;
}

.pagination {
  height: 48px;
  gap: 10px;
  background: transparent;
  border-radius: 0;
}

.pagination button {
  width: 105px;
  height: 32px;
  border-radius: 7px;
  font-size: 10px;
}

.page-jump { min-width: 112px; display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 750; }
.page-jump input[type="number"] { width: 48px; height: 28px; padding: 0 5px; border-radius: 6px; background: var(--control); color: var(--text); text-align: center; font-size: 10px; }
.page-jump input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.page-jump input[type="number"]::-webkit-inner-spin-button,
.page-jump input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.page-jump span { min-width: 0; color: var(--muted); font-size: 10px; }

.tree-list {
  min-width: 720px;
}

.tree-navigation {
  height: 39px;
  padding: 0 4px;
  gap: 7px;
  font-size: 11px;
  font-weight: 650;
}

.tree-back {
  display: none;
}

.tree-crumbs {
  gap: 5px;
}

.tree-crumbs button {
  padding: 3px 1px;
}

.tree-head,
.tree-row {
  min-height: 31px;
  padding: 0 8px;
  grid-template-columns: minmax(320px, 2.4fr) minmax(115px, .8fr) minmax(75px, .55fr) minmax(64px, .45fr) 30px;
  gap: 9px;
  border-radius: 7px;
  font-size: 10px;
}

.tree-head {
  height: 31px;
  font-size: 10px;
}

.tree-row {
  margin-bottom: 4px;
  background: var(--row);
  font-weight: 650;
}

.tree-name {
  gap: 8px;
}

.tree-file-row .tree-name {
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-file-row,
.tree-files-head {
  grid-template-columns: minmax(360px, 1fr) minmax(105px, .18fr) minmax(70px, .13fr) 30px;
}

.folder-icon {
  width: 19px;
  height: 13px;
  flex-basis: 19px;
}

.folder-icon::before {
  width: 8px;
  height: 5px;
}

.empty-state {
  padding: 70px 20px;
  font-size: 12px;
}

@media (max-width: 1080px) {
  :root { --v2-sidebar: 350px; }
  .replay-row { grid-template-columns: 52px minmax(200px, 1fr) minmax(280px, 40%) 32px; }
  .filter-panel { gap: 13px 14px; }
}

@media (max-width: 960px) {
  html,
  body { height: auto; overflow: auto; }
  body.modal-open {
    position: fixed;
    top: var(--modal-scroll-offset, 0);
    right: 0;
    left: 0;
    width: 100%;
  }
  .archive-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    padding: 6px;
  }
  .archive-sidebar {
    display: grid;
    grid-template-rows: auto auto auto;
    overflow: visible;
  }
  .browser-toolbar { grid-template-columns: minmax(0, 1fr) 150px auto; }
  .search-box { grid-column: 1; }
  .browser-toolbar > select { grid-column: 2; }
  .filter-toggle { display: inline-flex; grid-column: 3; }
  .filter-panel { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-panel { overflow: visible; }
  .filter-panel:not(.open) { display: none; }
  .sidebar-actions { padding-top: 8px; flex-direction: row; align-items: center; }
  .sidebar-actions .user-menu { flex-direction: row; }
  .browser-card { height: auto; min-height: 760px; }
  .replay-list { overflow: visible; }
  .tree-list { min-width: 0; overflow-x: auto; }
  .tree-head > :nth-child(4),
  .tree-row > :nth-child(4) { display: block; }
}

@media (max-width: 620px) {
  .browser-toolbar { grid-template-columns: 1fr auto; }
  .search-box { grid-column: 1 / -1; }
  .browser-toolbar > select { grid-column: 1; }
  .browser-toolbar .filter-toggle { grid-column: 2; }
  .filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .replay-row {
    grid-template-columns: 48px minmax(0, 1fr) 30px;
    min-height: 64px;
  }
  .grade { width: 48px; height: 48px; font-size: 23px; }
  .result-data { grid-column: 2 / 3; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .result-data strong { font-size: 11px; }
  .row-action { grid-column: 3; grid-row: 1 / 3; }
  .sidebar-actions { flex-wrap: wrap; }
  .browser-card { min-height: 680px; padding: 7px; }
  .view-switcher { gap: 7px; }
  .tree-head,
  .tree-row,
  .tree-file-row,
  .tree-files-head { grid-template-columns: minmax(0, 1fr) 30px; }
  .tree-head > :nth-child(2),
  .tree-row > :nth-child(2),
  .tree-head > :nth-child(3),
  .tree-row > :nth-child(3),
  .tree-head > :nth-child(4),
  .tree-row > :nth-child(4) { display: none; }
  .tree-files-head > :nth-child(4),
  .tree-file-row > :nth-child(4) { display: block; }
  .tree-file-row .row-action {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
  }
  .native-dialog {
    width: calc(100% - 12px);
    max-height: calc(100vh - 12px);
    padding: 20px 14px;
  }
  .dialog-actions > * { flex: 1 1 0; }
  .comment-form { grid-template-columns: 1fr; }
  .comment-form .quiet-button { width: 100%; }
  .request-item { grid-template-columns: 1fr; }
  .request-item a { justify-self: start; }
  .toast {
    width: calc(100% - 20px);
    bottom: max(10px, env(safe-area-inset-bottom));
    text-align: center;
  }
  .welcome-dialog {
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  .welcome-copy {
    padding: 16px;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.35;
  }
  .welcome-copy h1 { margin-bottom: 18px; font-size: 24px; }
  .welcome-actions { gap: 8px; padding: 10px 0 0; }
  .welcome-actions a,
  .welcome-actions button { height: 52px; min-height: 52px; border-radius: 8px; font-size: 14px; }
}

@media (max-width: 420px) {
  .replay-row { grid-template-columns: 44px minmax(0, 1fr) 28px; gap: 7px; }
  .grade { width: 44px; height: 44px; font-size: 21px; }
  .map-title { font-size: 12px; }
  .map-subtitle { font-size: 9px; }
  .result-data { grid-column: 1 / 3; padding-top: 2px; }
  .result-data strong { font-size: 10px; }
  .row-action { width: 28px; height: 28px; }
  .pagination { justify-content: space-between; gap: 6px; }
  .pagination button { width: auto; min-width: 68px; padding: 0 8px; }
  .page-jump { min-width: 0; gap: 4px; }
  .page-jump input[type="number"] { width: 42px; }
  .detail-actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .detail-actions > * { width: 100%; min-width: 0; padding-right: 8px; padding-left: 8px; }
  .detail-actions .download-button { grid-column: 1 / -1; }
}

@media (max-height: 620px) {
  .welcome-copy { padding: 14px 18px; font-size: 14px; line-height: 1.3; }
  .welcome-copy h1 { margin-bottom: 12px; font-size: 23px; }
  .welcome-copy p { margin-bottom: 10px; }
  .welcome-actions { gap: 10px; padding: 8px; }
  .welcome-actions a,
  .welcome-actions button { height: 48px; min-height: 48px; font-size: 14px; }
}
