:root {
  color-scheme: dark;
  --page: #101514;
  --surface: #18201e;
  --surface-strong: #202a27;
  --ink: #f3f6f4;
  --muted: #9aa7a2;
  --line: #36413e;
  --accent: #75dfb9;
  --accent-strong: #a7f0d5;
  --danger: #ff7d74;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100svh;
  padding-bottom: 78px;
}

.game-shell.has-selection {
  padding-bottom: 88px;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
  padding: max(8px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 8px max(20px, env(safe-area-inset-left));
  background: #131a18;
}

.back-link,
.game-name,
.header-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 800;
}

.back-link {
  justify-self: start;
  min-height: 40px;
  color: var(--muted);
  text-decoration: none;
}

.game-name {
  justify-self: center;
}

.game-name__mark {
  width: 12px;
  height: 12px;
  border: 3px solid var(--accent);
  transform: rotate(45deg);
}

.header-button {
  justify-self: end;
  min-height: 38px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.back-link:hover,
.back-link:focus-visible,
.header-button:hover,
.header-button:focus-visible {
  color: var(--ink);
}

.topic-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 94px;
  border-bottom: 1px solid var(--line);
  padding: 16px clamp(18px, 4vw, 56px);
  background: var(--surface);
}

.topic-bar p,
.tray-heading p,
.start-screen > p,
.dialog-heading p {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.topic-bar h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 3.4vw, 46px);
  line-height: 1;
  letter-spacing: 0;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 850;
}

.button {
  gap: 8px;
  min-height: 44px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-size: 13px;
}

.button--secondary {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.button--secondary:hover,
.button--secondary:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  border-color: #5b6a65;
  background: #283330;
}

.button--primary,
.button--start {
  border-color: var(--accent);
  background: var(--accent);
  color: #0c1613;
}

.button--primary:hover,
.button--primary:focus-visible,
.button--start:hover,
.button--start:focus-visible {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 20px;
}

.tier-board {
  border-bottom: 1px solid var(--line);
}

.tier-row {
  display: grid;
  grid-template-columns: clamp(64px, 7vw, 92px) minmax(0, 1fr);
  min-height: 92px;
  border-bottom: 1px solid var(--line);
  background: #111716;
}

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

.tier-label {
  display: grid;
  place-items: center;
  color: #111614;
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 950;
}

.tier-label--s {
  background: #ef7168;
}

.tier-label--a {
  background: #f2a65f;
}

.tier-label--b {
  background: #f2d06b;
}

.tier-label--c {
  background: #68b895;
}

.tier-label--d {
  background: #6ea8d9;
}

.drop-zone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 92px;
  overflow-x: auto;
  padding: 7px 10px;
  scrollbar-color: #4a5853 transparent;
  scrollbar-width: thin;
}

.drop-zone:empty::after {
  margin: auto;
  color: #6e7b76;
  content: "Drop cards here";
  font-size: 12px;
  font-weight: 750;
}

.rank-card {
  position: relative;
  flex: 0 0 clamp(76px, 8vw, 104px);
  width: clamp(76px, 8vw, 104px);
  overflow: hidden;
  border: 2px solid #43504c;
  border-radius: 6px;
  background: #f4f5f1;
  color: #121817;
  cursor: grab;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.2);
  transition: border-color 120ms ease, transform 120ms ease;
}

.rank-card:active {
  cursor: grabbing;
}

.rank-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.rank-card span {
  display: block;
  overflow: hidden;
  height: 26px;
  padding: 5px 5px 4px;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-card:hover,
.rank-card:focus-visible,
.rank-card.remote-focus {
  border-color: var(--accent);
  outline: 3px solid rgba(117, 223, 185, 0.36);
  outline-offset: 2px;
}

.rank-card.is-selected {
  border-color: #ffffff;
  outline: 4px solid var(--accent);
  outline-offset: 2px;
  transform: translateY(-4px);
}

.game-shell.has-selection .rank-card.is-placement-target {
  cursor: pointer;
}

.game-shell.has-selection .rank-card.is-placement-target:hover,
.game-shell.has-selection .rank-card.is-placement-target:focus-visible {
  border-color: #ffffff;
  box-shadow: inset 5px 0 0 var(--accent), 0 5px 14px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
}

.sortable-ghost {
  opacity: 0.24;
}

.sortable-chosen {
  border-color: var(--accent);
}

.card-tray {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  min-height: 132px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tray-heading {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  border-right: 1px solid var(--line);
  padding: 16px;
}

.tray-heading h2 {
  margin: 3px 0 0;
  font-size: 20px;
}

.tray-heading > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.tray-zone {
  min-height: 132px;
  padding: 12px;
}

.tray-zone:empty::after {
  content: "Everything is ranked";
}

.action-bar {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 70px;
  border-top: 1px solid var(--line);
  padding: 10px max(20px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: rgba(19, 26, 24, 0.96);
  backdrop-filter: blur(14px);
}

.progress-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
}

.move-controls {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.progress-controls[hidden],
.move-controls[hidden] {
  display: none;
}

.move-card-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.move-card-copy span {
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.move-card-copy strong {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tier-targets,
.move-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tier-target {
  width: 44px;
  height: 44px;
  border: 2px solid transparent;
  border-radius: 6px;
  color: #111614;
  cursor: pointer;
  font-size: 16px;
  font-weight: 950;
}

.tier-target--tray {
  width: 58px;
  border-color: #52605c;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 11px;
}

.tier-target--s {
  background: #ef7168;
}

.tier-target--a {
  background: #f2a65f;
}

.tier-target--b {
  background: #f2d06b;
}

.tier-target--c {
  background: #68b895;
}

.tier-target--d {
  background: #6ea8d9;
}

.tier-target:hover,
.tier-target:focus-visible,
.tier-target.is-current {
  border-color: #ffffff;
  outline: 3px solid rgba(117, 223, 185, 0.52);
  outline-offset: 2px;
}

.move-actions .icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.progress-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.progress-copy strong {
  font-size: 14px;
}

.progress-copy span {
  color: var(--muted);
  font-size: 11px;
}

.start-screen {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: flex;
  visibility: hidden;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 30px;
  background: rgba(9, 14, 13, 0.92);
  opacity: 0;
  text-align: center;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.start-screen.is-visible {
  visibility: visible;
  opacity: 1;
}

.start-screen h2 {
  margin: 8px 0 12px;
  font-size: clamp(54px, 10vw, 104px);
  line-height: 0.95;
  letter-spacing: 0;
}

.start-screen > span {
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 17px;
}

.button--start {
  min-width: 210px;
  min-height: 52px;
}

.start-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
}

.results-dialog,
.history-dialog {
  width: min(760px, calc(100% - 32px));
  max-height: min(820px, calc(100vh - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: #f3f5f2;
  color: #19211f;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}

.results-dialog::backdrop,
.history-dialog::backdrop {
  background: rgba(5, 9, 8, 0.76);
  backdrop-filter: blur(5px);
}

.dialog-shell {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.dialog-heading p {
  color: #4c7567;
}

.dialog-heading h2 {
  margin: 3px 0 0;
  font-size: 30px;
  line-height: 1.15;
}

.saved-badge {
  border: 1px solid #92baa9;
  border-radius: 999px;
  padding: 5px 10px;
  background: #dceee6;
  color: #25694f;
  font-size: 11px;
  font-weight: 850;
}

.result-list {
  display: grid;
  overflow: hidden;
  border: 1px solid #cbd3cf;
  border-radius: 6px;
}

.result-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  min-height: 54px;
  border-bottom: 1px solid #cbd3cf;
}

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

.result-row strong {
  display: grid;
  place-items: center;
  background: var(--result-color);
  color: #111614;
  font-size: 21px;
}

.result-row span {
  align-self: center;
  padding: 10px 14px;
  color: #4f5b57;
  font-size: 14px;
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.history-list {
  display: grid;
  max-height: 520px;
  overflow-y: auto;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid #d1d8d4;
  padding: 14px 0;
}

.history-item:first-child {
  padding-top: 0;
}

.history-item:last-child {
  border-bottom: 0;
}

.history-copy {
  min-width: 0;
}

.history-copy h3 {
  overflow: hidden;
  margin: 0 0 3px;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-copy p {
  margin: 0;
  color: #6c7773;
  font-size: 12px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.history-actions .button {
  min-height: 36px;
  padding-inline: 11px;
}

.history-actions .icon-button {
  width: 36px;
  height: 36px;
  border-color: #cbd3cf;
  background: #ffffff;
  color: #64706c;
}

.history-actions [data-history-action="delete"]:hover,
.history-actions [data-history-action="delete"]:focus-visible {
  border-color: #d5aaa6;
  background: #f9e8e6;
  color: #a13c35;
}

.history-empty {
  margin: 24px 0;
  color: #6c7773;
  font-size: 14px;
  text-align: center;
}

.history-empty[hidden] {
  display: none;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 86px;
  visibility: hidden;
  max-width: min(340px, calc(100% - 36px));
  border-radius: 6px;
  padding: 11px 14px;
  background: #f3f5f2;
  color: #19211f;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
  font-size: 13px;
  font-weight: 750;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease, visibility 150ms ease;
}

.toast.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

:focus-visible {
  outline: 3px solid rgba(117, 223, 185, 0.7);
  outline-offset: 3px;
}

@media (max-width: 640px) {
  .game-shell.has-selection {
    padding-bottom: 132px;
  }

  .game-header {
    grid-template-columns: 1fr auto;
    min-height: 58px;
    padding-inline: 14px;
  }

  .game-name {
    justify-self: end;
  }

  .header-button {
    position: fixed;
    z-index: 12;
    right: 16px;
    bottom: 82px;
    width: 42px;
    height: 42px;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-strong);
  }

  .header-button span:last-child {
    display: none;
  }

  .game-shell.has-selection .header-button {
    display: none;
  }

  .topic-bar {
    align-items: flex-start;
    min-height: 88px;
    padding: 14px;
  }

  .topic-bar h1 {
    font-size: 26px;
  }

  .topic-bar .button {
    flex: none;
    min-width: 44px;
    width: 44px;
    padding: 0;
    font-size: 0;
  }

  .topic-bar .button span {
    font-size: 18px;
  }

  .tier-row {
    grid-template-columns: 52px minmax(0, 1fr);
    min-height: 78px;
  }

  .tier-label {
    font-size: 23px;
  }

  .drop-zone {
    min-height: 78px;
    gap: 6px;
    padding: 6px;
  }

  .rank-card {
    flex-basis: 68px;
    width: 68px;
  }

  .rank-card span {
    height: 23px;
    padding-top: 4px;
    font-size: 9px;
  }

  .card-tray {
    grid-template-columns: 92px minmax(0, 1fr);
    min-height: 108px;
  }

  .tray-heading {
    padding: 10px;
  }

  .tray-heading h2 {
    font-size: 16px;
  }

  .tray-zone {
    min-height: 108px;
  }

  .action-bar {
    min-height: 68px;
    padding-inline: 14px;
  }

  .move-controls {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
  }

  .tier-targets {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .tier-target {
    width: 40px;
    height: 40px;
  }

  .tier-target--tray {
    width: 52px;
  }

  .move-actions {
    justify-content: flex-end;
  }

  .move-actions .icon-button {
    width: 38px;
    height: 38px;
  }

  .progress-copy span {
    display: none;
  }

  .dialog-shell {
    padding: 18px;
  }

  .dialog-heading h2 {
    font-size: 24px;
  }

  .history-item {
    align-items: flex-start;
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

@media (max-height: 760px) and (min-width: 641px) {
  .game-header {
    min-height: 52px;
  }

  .topic-bar {
    min-height: 74px;
    padding-block: 10px;
  }

  .tier-row,
  .drop-zone {
    min-height: 66px;
  }

  .rank-card {
    flex-basis: 68px;
    width: 68px;
  }

  .rank-card span {
    height: 20px;
    padding-block: 3px;
    font-size: 9px;
  }

  .card-tray,
  .tray-zone {
    min-height: 92px;
  }

  .tray-heading {
    padding: 10px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rank-card,
  .start-screen,
  .toast {
    transition: none;
  }
}
