:root {
  color-scheme: dark;
  --md-sys-color-primary: #9b53ff;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-surface: #09090b;
  --md-sys-color-on-surface: #f4eff6;
  --md-sys-color-on-surface-variant: #c9c2cc;
  --md-sys-color-surface-container: #202329;
  --md-sys-color-surface-container-high: #292c33;
  --md-sys-color-outline: #8e8891;
  --md-sys-color-outline-variant: #383b42;
  --md-sys-shape-small: 8px;
  --md-sys-shape-medium: 12px;
  --md-sys-shape-large: 18px;
  --md-sys-shape-full: 9999px;
  --motion: cubic-bezier(.2, 0, 0, 1);
  font-family: "Roboto Flex", "Noto Sans SC", "Microsoft YaHei UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --md-sys-color-primary: #7040b8;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-surface: #fff8ff;
  --md-sys-color-on-surface: #211f23;
  --md-sys-color-on-surface-variant: #4c474f;
  --md-sys-color-surface-container: #f1ecf2;
  --md-sys-color-surface-container-high: #e9e4ea;
  --md-sys-color-outline: #7d767f;
  --md-sys-color-outline-variant: #cec7cf;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  padding-bottom: 112px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

button, input { font: inherit; }
button { cursor: pointer; }

button:focus-visible, input:focus-visible {
  outline: 3px solid var(--md-sys-color-primary);
  outline-offset: 3px;
}

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

.topbar {
  width: min(calc(100% - 40px), 1320px);
  margin: 0 auto;
  padding: 36px 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 5vw, 64px);
  line-height: 1;
  letter-spacing: -.055em;
  font-weight: 900;
}

.top-actions, .add-form { display: flex; align-items: center; gap: 10px; }

.add-form input {
  width: min(32vw, 260px);
  height: 52px;
  padding: 0 18px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-medium);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

.add-form input::placeholder { color: var(--md-sys-color-on-surface-variant); }

.filled-button, .mini-button, .text-button, .danger-button, .icon-button {
  min-height: 48px;
  border: 0;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  transition: transform 180ms var(--motion), filter 180ms var(--motion);
}

.filled-button {
  padding: 0 24px;
  border-radius: var(--md-sys-shape-medium);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.add-button { width: 52px; padding: 0; }

.icon-button {
  width: 48px;
  padding: 0;
  border-radius: var(--md-sys-shape-full);
  background: transparent;
  color: currentColor;
}

.icon-button:hover { background: color-mix(in srgb, currentColor 10%, transparent); }
.filled-button:hover, .mini-button:hover { filter: brightness(1.08); }
.filled-button:active, .mini-button:active, .icon-button:active { transform: scale(.95); }
button:disabled { cursor: not-allowed; opacity: .32; }
button svg { width: 21px; height: 21px; fill: currentColor; }

main {
  width: min(calc(100% - 40px), 1320px);
  margin: 0 auto;
  padding: 0 0 64px;
}

.tier-board {
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-large);
  background: var(--md-sys-color-surface-container);
}

.tier-row {
  min-height: 142px;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.tier-row:last-child { border-bottom: 0; }

.tier-row > h2 {
  margin: 0;
  padding: 16px 12px;
  display: grid;
  place-items: center;
  color: #111114;
  font-size: 25px;
  line-height: 1.15;
  text-align: center;
  word-break: break-all;
}

.tier-row[data-tier="hang"] { --tier-color: #ff7d82; }
.tier-row[data-tier="top"] { --tier-color: #ffbc76; }
.tier-row[data-tier="elite"] { --tier-color: #ffe08a; }
.tier-row[data-tier="npc"] { --tier-color: #ffff79; }
.tier-row[data-tier="lame"] { --tier-color: #b2ff72; }
.tier-row > h2 { background: var(--tier-color); }

.tier-people {
  min-width: 0;
  padding: 14px;
  display: flex;
  align-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
}

.person-card {
  width: 150px;
  min-height: 92px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr;
  gap: 4px 8px;
  border-radius: var(--md-sys-shape-medium);
  border: 3px solid transparent;
  background: var(--tier-color);
  color: #111114;
  animation: card-in 300ms var(--motion) both;
}

.person-card:hover { filter: brightness(1.04); }
.person-card.selected { border-color: #111114; box-shadow: inset 0 0 0 2px rgb(255 255 255 / 72%); transform: translateY(-2px); }
.person-card:focus-visible { outline-color: var(--tier-color); }

.rank-number, .score {
  color: rgb(17 17 20 / 72%);
  font-size: 12px;
  font-weight: 800;
}

.score { text-align: right; }

.person-card h3 {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 2px 0 6px;
  overflow: hidden;
  color: inherit;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-actions {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 520px);
  min-height: 76px;
  padding: 10px 12px 10px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px 56px 56px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 24px;
  background: var(--md-sys-color-surface-container-high);
  box-shadow: 0 10px 32px rgb(0 0 0 / 38%);
}

.bottom-actions[hidden] { display: none; }
.selected-person { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.selected-person strong { overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.selected-person span { color: var(--md-sys-color-on-surface-variant); font-size: 13px; font-weight: 800; }
.action-button {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
  color: var(--md-sys-color-on-surface);
  font-size: 19px;
  font-weight: 900;
}
.action-button svg { width: 23px; height: 23px; fill: currentColor; }
.deduct-button { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.delete-button { color: var(--md-sys-color-error); }

dialog {
  width: min(calc(100% - 32px), 380px);
  padding: 0;
  border: 0;
  border-radius: 28px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

dialog::backdrop { background: rgb(0 0 0 / 68%); }
dialog form { padding: 28px; }
dialog h2 { margin: 0; font-size: 22px; }
.dialog-actions { margin-top: 28px; display: flex; justify-content: flex-end; gap: 8px; }
.text-button, .danger-button { padding: 0 20px; border-radius: var(--md-sys-shape-full); }
.text-button { background: transparent; color: var(--md-sys-color-on-surface); }
.danger-button { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }

.snackbar {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 108px;
  max-width: calc(100% - 32px);
  padding: 14px 20px;
  border-radius: var(--md-sys-shape-small);
  background: var(--md-sys-color-on-surface);
  color: var(--md-sys-color-surface);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 220ms var(--motion), transform 220ms var(--motion);
}

.snackbar.visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes card-in { from { opacity: 0; transform: scale(.96); } }

@media (max-width: 699px) {
  .topbar {
    width: min(calc(100% - 24px), 1320px);
    padding: 20px 0 16px;
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }
  h1 { font-size: 40px; }
  .top-actions { width: 100%; }
  .add-form { min-width: 0; flex: 1; }
  .add-form input { min-width: 0; width: auto; flex: 1; }
  .filled-button { padding: 0 18px; }
  main { width: min(calc(100% - 24px), 1320px); }
  .tier-row { min-height: 122px; grid-template-columns: 76px minmax(0, 1fr); }
  .tier-row > h2 { padding: 10px 7px; font-size: 20px; }
  .tier-people { padding: 10px; flex-wrap: nowrap; overflow-x: auto; }
  .person-card { width: 136px; min-width: 136px; min-height: 88px; }
  .bottom-actions {
    width: calc(100% - 24px);
    grid-template-columns: minmax(0, 1fr) 52px 52px 52px;
    padding-left: 16px;
  }
  .action-button { width: 52px; height: 52px; border-radius: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
