:root {
  color-scheme: dark;
  --bg: #171614;
  --panel: #24211d;
  --panel-strong: #2f2923;
  --panel-soft: #1d2320;
  --line: #463f36;
  --line-strong: #6d5d4b;
  --text: #f4efe5;
  --muted: #bfb4a4;
  --gold: #d7ad52;
  --red: #b94842;
  --green: #4e936c;
  --teal: #4f9aa4;
  --ink: #11100e;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --tier-label-width: 76px;
  --card-width: 168px;
  --card-height: 58px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  display: flex;
  height: 100vh;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 240px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 96px),
    var(--bg);
}

button,
input {
  font: inherit;
}

.app-header {
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 22, 20, 0.94);
  backdrop-filter: blur(12px);
}

.brand-block {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(215, 173, 82, 0.72);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--gold);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  color: var(--text);
  font-size: 20px;
  font-weight: 850;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 15px;
  font-weight: 820;
  letter-spacing: 0;
}

h3 {
  font-size: 18px;
  font-weight: 840;
  letter-spacing: 0;
}

.meta-text,
.empty-details {
  color: var(--muted);
  font-size: 13px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(17, 16, 14, 0.78);
  backdrop-filter: blur(8px);
}

.is-loading .loading-overlay {
  display: grid;
}

.loading-dialog {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  width: min(460px, 100%);
  padding: 18px;
  border: 1px solid rgba(215, 173, 82, 0.62);
  border-radius: var(--radius);
  background: #24211d;
  box-shadow: var(--shadow);
}

.loading-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(244, 239, 229, 0.18);
  border-top-color: var(--gold);
  border-radius: 999px;
  animation: spin 900ms linear infinite;
}

.loading-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 820;
}

.loading-message {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toolbar,
.notice-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: #292620;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.button:hover {
  border-color: var(--gold);
  background: #393228;
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible,
.character-card:focus-visible,
input:focus-visible,
select:focus-visible,
.category-chip-remove:focus-visible,
.wiki-link:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.button-primary {
  border-color: #d2b167;
  color: var(--ink);
  background: var(--gold);
  font-weight: 780;
}

.button-primary:hover {
  background: #e8c56c;
}

.button-danger {
  border-color: rgba(185, 72, 66, 0.86);
}

.button-danger:hover {
  background: #44211f;
}

.reset-confirm-button {
  border-color: rgba(226, 100, 92, 0.95);
  background: #a93e39;
  font-weight: 780;
}

.reset-confirm-button:hover {
  border-color: #f18a81;
  background: #c14d46;
}

.button-small {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.app-shell {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: minmax(280px, 330px) minmax(480px, 1fr) minmax(280px, 340px);
  gap: 14px;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
  padding: 14px;
}

.pool-panel,
.board-panel,
.details-panel {
  min-width: 0;
}

.pool-panel,
.details-panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(36, 33, 29, 0.92);
  box-shadow: var(--shadow);
}

.pool-panel {
  display: flex;
  flex-direction: column;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px;
  border-bottom: 1px solid var(--line);
}

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

.ranked-pill {
  flex: 0 0 auto;
  min-width: 68px;
  padding: 5px 8px;
  border: 1px solid rgba(79, 154, 164, 0.55);
  border-radius: 999px;
  color: #d5f7f8;
  background: rgba(79, 154, 164, 0.16);
  font-size: 12px;
  font-weight: 780;
  text-align: center;
}

.picker-close-button,
.mobile-board-actions {
  display: none;
}

.placement-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(215, 173, 82, 0.68);
  border-radius: var(--radius);
  color: #fff8df;
  background: rgba(63, 49, 24, 0.94);
}

.placement-bar[hidden] {
  display: none;
}

.placement-bar strong {
  font-weight: 840;
}

.search-box {
  display: block;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: #151411;
}

.search-box input::placeholder {
  color: #867b6d;
}

.category-filter {
  display: grid;
  gap: 6px;
  padding: 0 12px 12px;
  border-bottom: 1px solid var(--line);
}

.category-filter-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.category-filter select {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: #151411;
  cursor: pointer;
}

.category-filter select:disabled {
  cursor: wait;
  opacity: 0.58;
}

.selected-category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selected-category-list[hidden] {
  display: none;
}

.selected-category-chip {
  display: inline-flex;
  max-width: 100%;
  min-height: 28px;
  align-items: center;
  gap: 6px;
  padding: 4px 5px 4px 9px;
  border: 1px solid rgba(215, 173, 82, 0.55);
  border-radius: 999px;
  color: #fff8df;
  background: rgba(215, 173, 82, 0.12);
  font-size: 12px;
  font-weight: 760;
}

.selected-category-chip span {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-chip-remove {
  display: grid;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(244, 239, 229, 0.2);
  border-radius: 999px;
  color: var(--text);
  background: rgba(17, 16, 14, 0.64);
  cursor: pointer;
  font-size: 12px;
  font-weight: 820;
  line-height: 1;
}

.category-chip-remove:hover {
  border-color: rgba(215, 173, 82, 0.86);
  background: rgba(57, 50, 40, 0.92);
}

.drop-zone {
  min-height: 84px;
}

.pool-grid {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 1fr;
  gap: 8px;
  min-height: 0;
  align-content: start;
  overflow: auto;
  padding: 12px;
}

.board-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.share-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(79, 154, 164, 0.55);
  border-radius: var(--radius);
  color: #e9ffff;
  background: rgba(29, 56, 58, 0.92);
}

.share-notice[hidden] {
  display: none;
}

.share-link-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(36, 33, 29, 0.92);
}

.share-link-panel[hidden] {
  display: none;
}

.share-link-panel input {
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: #151411;
}

.tier-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.tier-row {
  display: grid;
  grid-template-columns: var(--tier-label-width) 1fr;
  min-height: 86px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(36, 33, 29, 0.88);
  box-shadow: var(--shadow);
}

.tier-label {
  display: grid;
  place-items: center;
  min-height: 86px;
  color: #16110d;
  font-size: 28px;
  font-weight: 920;
  letter-spacing: 0;
}

.tier-drop {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-content: flex-start;
  min-height: 86px;
  padding: 13px;
}

.tier-drop.drag-over,
.pool-grid.drag-over {
  outline: 2px dashed rgba(215, 173, 82, 0.75);
  outline-offset: -5px;
}

.character-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: var(--card-width);
  min-height: var(--card-height);
  padding: 7px;
  border: 1px solid rgba(109, 93, 75, 0.88);
  border-radius: var(--radius);
  color: var(--text);
  background: #1c1a17;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
}

.pool-grid .character-card {
  width: 100%;
}

.character-card:hover,
.character-card.selected {
  border-color: var(--gold);
  background: #2a241d;
}

.character-card.dragging {
  opacity: 0.42;
}

.character-card.pointer-drag-source {
  opacity: 0.38;
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  width: var(--card-width);
  max-width: 260px;
  pointer-events: none;
  transform: translate(-9999px, -9999px);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.42);
}

body.is-pointer-dragging {
  cursor: grabbing;
  user-select: none;
}

.portrait-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: #11100e;
}

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

.portrait[hidden],
.portrait-fallback[hidden] {
  display: none;
}

.portrait-fallback {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: var(--ink);
  background: var(--green);
  font-size: 13px;
  font-weight: 860;
}

.character-name {
  display: -webkit-box;
  overflow: hidden;
  max-height: 38px;
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
  line-height: 1.25;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.details-panel {
  padding: 0;
}

.details-content {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  overflow: auto;
}

.details-image {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  height: clamp(140px, 28vh, 260px);
  object-fit: contain;
  object-position: center;
  border-bottom: 1px solid var(--line);
  background: #11100e;
}

.details-fallback {
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--teal);
  font-size: 48px;
  font-weight: 900;
}

.details-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.details-summary {
  color: #e6ded1;
  font-size: 14px;
}

.wiki-link {
  display: inline-flex;
  width: fit-content;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border: 1px solid rgba(79, 154, 164, 0.7);
  border-radius: var(--radius);
  color: #d7f8fa;
  text-decoration: none;
}

.wiki-link:hover {
  background: rgba(79, 154, 164, 0.18);
}

.empty-details {
  padding: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.is-loading .toolbar .button,
.is-loading .search-box input,
.is-loading .category-filter select,
.is-loading .category-chip-remove {
  pointer-events: none;
  opacity: 0.58;
}

.site-footer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 16px 14px 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(23, 22, 20, 0.92);
  font-size: 12px;
}

.footer-mail-link {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 1px solid rgba(215, 173, 82, 0.45);
  border-radius: 999px;
  color: var(--text);
  background: rgba(215, 173, 82, 0.08);
  text-decoration: none;
}

.footer-mail-link:hover {
  border-color: rgba(215, 173, 82, 0.85);
  background: rgba(215, 173, 82, 0.14);
}

.picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 720;
  background: rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(3px);
}

.picker-backdrop[hidden] {
  display: none;
}

.reset-dialog {
  position: fixed;
  inset: 0;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(215, 173, 82, 0.62);
  border-radius: var(--radius);
  margin: auto;
  color: var(--text);
  background: #24211d;
  box-shadow: var(--shadow);
}

.reset-dialog:not([open]) {
  display: none;
}

.reset-dialog::backdrop {
  background: rgba(17, 16, 14, 0.74);
  backdrop-filter: blur(8px);
}

.reset-modal-card {
  display: grid;
  gap: 15px;
  padding: 18px;
}

.reset-modal-eyebrow {
  color: #f1bf60;
  font-size: 12px;
  font-weight: 820;
}

.reset-modal-title {
  margin-top: 2px;
  font-size: 22px;
}

.reset-modal-copy {
  color: #e6ded1;
  font-size: 14px;
}

.reset-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.mobile-details-dialog {
  position: fixed;
  inset: 0;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(79, 154, 164, 0.64);
  border-radius: var(--radius);
  margin: auto;
  color: var(--text);
  background: #24211d;
  box-shadow: var(--shadow);
}

.mobile-details-dialog:not([open]) {
  display: none;
}

.mobile-details-dialog::backdrop {
  background: rgba(17, 16, 14, 0.74);
  backdrop-filter: blur(8px);
}

.mobile-details-card {
  position: relative;
  display: flex;
  max-height: calc(100dvh - 32px);
  flex-direction: column;
}

.mobile-details-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  background: rgba(17, 16, 14, 0.86);
}

.mobile-details-content {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: auto;
}

.mobile-details-content .details-image {
  height: clamp(180px, 34dvh, 300px);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(260px, 320px) minmax(430px, 1fr);
    align-items: start;
    overflow: auto;
  }

  .details-panel {
    position: static;
    grid-column: 1 / -1;
    height: auto;
    max-height: none;
  }

  .details-content {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
    height: auto;
    min-height: 0;
  }

  .details-image {
    height: clamp(160px, 24vh, 240px);
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
}

@media (max-width: 820px) {
  :root {
    --tier-label-width: 48px;
    --card-width: clamp(108px, 36vw, 150px);
    --card-height: 42px;
  }

  body {
    overflow: hidden;
  }

  .app-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }

  h1 {
    font-size: 17px;
    white-space: normal;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }

  .toolbar .button {
    min-width: 0;
    min-height: 34px;
    padding: 6px 7px;
    font-size: 13px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    overflow: hidden;
    padding: 8px;
  }

  .board-panel {
    order: 1;
    overflow: auto;
    padding-bottom: 14px;
  }

  .share-link-panel {
    order: -2;
  }

  .mobile-board-actions {
    position: sticky;
    top: 0;
    z-index: 30;
    display: block;
    padding-bottom: 8px;
    background: var(--bg);
  }

  .mobile-rank-button {
    width: 100%;
  }

  .pool-panel {
    position: fixed;
    right: 8px;
    bottom: 8px;
    left: 8px;
    z-index: 760;
    display: flex;
    height: min(78dvh, 680px);
    max-height: calc(100dvh - 22px);
    border-radius: var(--radius);
    transform: translateY(calc(100% + 18px));
    transition: transform 180ms ease;
  }

  .is-picker-open .pool-panel {
    transform: translateY(0);
  }

  .picker-close-button {
    display: inline-flex;
  }

  .details-panel {
    display: none;
  }

  .pool-grid {
    max-height: none;
    overscroll-behavior: contain;
  }

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

  .tier-label {
    min-height: 78px;
    font-size: 21px;
  }

  .tier-drop {
    gap: 7px;
    min-height: 78px;
    padding: 8px;
  }

  .character-card {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    width: var(--card-width);
    min-height: var(--card-height);
    padding: 8px 9px;
  }

  .pool-grid .character-card {
    width: 100%;
    min-height: 44px;
    padding: 11px 12px;
    cursor: pointer;
    touch-action: pan-y;
  }

  .portrait-wrap {
    display: none;
  }

  .character-name {
    max-height: 32px;
    font-size: 12px;
    line-height: 1.22;
  }

  .pool-grid .character-name {
    display: block;
    max-height: none;
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.is-placement-active .tier-drop {
    outline: 2px dashed rgba(215, 173, 82, 0.68);
    outline-offset: -5px;
  }

  body.is-placement-active .tier-row {
    cursor: pointer;
  }

  .drag-ghost {
    width: min(58vw, 220px);
  }

  .site-footer {
    display: none;
  }

  .mobile-details-dialog {
    inset: 50% auto auto 50%;
    width: min(440px, calc(100vw - 24px));
    max-height: min(82dvh, 720px);
    margin: 0;
    transform: translate(-50%, -50%);
  }

  .mobile-details-card {
    max-height: min(82dvh, 720px);
  }

  .mobile-details-content .details-image {
    height: clamp(180px, 38dvh, 340px);
  }
}

@media (max-width: 520px) {
  :root {
    --tier-label-width: 42px;
    --card-width: clamp(94px, 34vw, 132px);
  }

  .brand-mark {
    display: none;
  }

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

  .toolbar .button {
    width: auto;
  }

  .share-notice {
    align-items: stretch;
    flex-direction: column;
  }

  .reset-dialog {
    inset: auto 8px 8px;
    width: auto;
    max-height: calc(100dvh - 16px);
    margin: 0;
  }

  .reset-modal-card {
    padding: 16px;
  }

  .reset-modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .reset-modal-actions .button {
    width: 100%;
  }
}
