:root {
  color-scheme: light;
  --font-ui: Roboto, "Segoe UI", Arial, ui-sans-serif, system-ui, sans-serif;
  --font-display: Roboto, "Segoe UI", Arial, ui-sans-serif, system-ui, sans-serif;
  --page: #f4f1eb;
  --ink: #16181c;
  --muted: #666d76;
  --line: #d8d4ca;
  --panel: #fffdfa;
  --panel-soft: #f8f6f1;
  --board: #151d24;
  --board-row: #1d2831;
  --board-row-hover: #25333e;
  --chip: #fbfbf8;
  --chip-line: #d9dee5;
  --focus: #1769ff;
  --danger: #9c2f2f;
  --shadow: 0 16px 40px rgba(30, 29, 25, 0.12);
  --chip-shadow: 0 6px 18px rgba(17, 21, 28, 0.12);
  --tier-label-width: minmax(260px, 340px);
  --tier-row-height: 96px;
  --presentation-label-width: clamp(440px, 21.5vw, 552px);
  --presentation-row-height: clamp(124px, 10.8vh, 156px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.64), rgba(255, 255, 255, 0)),
    var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
select,
input,
textarea {
  border-radius: 8px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.item-card:focus-visible {
  outline: 3px solid rgba(23, 105, 255, 0.34);
  outline-offset: 2px;
}

.app {
  width: min(1760px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.title-control input,
.json-panel textarea,
.editor-row input,
.editor-row select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.title-control input {
  height: 48px;
  padding: 0 14px;
  font-size: 1.05rem;
  font-weight: 700;
}

.primary-actions,
.entry-row,
.json-actions,
.editor-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.button {
  min-height: 42px;
  border: 1px solid rgba(22, 24, 28, 0.12);
  background: #ffffff;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.button:hover {
  border-color: rgba(22, 24, 28, 0.22);
  box-shadow: 0 8px 20px rgba(22, 24, 28, 0.09);
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.button-primary {
  border-color: #111820;
  background: #111820;
  color: #ffffff;
}

.button-primary:hover {
  background: #202c37;
}

.button-danger {
  color: var(--danger);
}

.setup-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 16px;
  align-items: stretch;
  height: min(720px, calc(100vh - 120px));
  min-height: 460px;
  margin-bottom: 24px;
}

.setup-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  min-width: 0;
  border: 1px solid rgba(22, 24, 28, 0.09);
  background: rgba(255, 253, 250, 0.82);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(27, 26, 22, 0.07);
}

.json-panel {
  overflow: auto;
}

.panel-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.heading-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-heading h2,
.section-heading h2 {
  margin: 0;
  font-size: 0.96rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.count-pill {
  display: inline-flex;
  min-width: 34px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #ebe7dd;
  color: #3f454d;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

textarea {
  min-height: 88px;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.45;
}

.editor-list {
  display: grid;
  flex: 1 1 auto;
  gap: 10px;
  min-height: 0;
  align-content: start;
  overflow: auto;
  padding-right: 2px;
}

.editor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 0.48fr) auto;
  gap: 8px;
  align-items: center;
}

.tier-editor-row {
  grid-template-columns: 40px minmax(0, 1fr) auto;
}

.editor-row input,
.editor-row select {
  height: 38px;
  padding: 0 10px;
}

.color-input {
  width: 40px;
  height: 38px;
  padding: 4px;
  border: 1px solid var(--line);
  background: #ffffff;
  cursor: pointer;
}

.small-button {
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
}

.json-panel textarea {
  width: 100%;
  margin-bottom: 10px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.84rem;
}

#jsonOutput {
  border-color: #d6d2c8;
  background: #eeece6;
  color: #30343a;
}

.json-message {
  min-height: 1.2em;
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.json-message.error {
  color: var(--danger);
}

.shortcuts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(22, 24, 28, 0.08);
  color: var(--muted);
  font-size: 0.86rem;
}

.shortcuts h3 {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  color: var(--ink);
  font-size: 0.86rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.shortcuts p {
  margin: 0;
}

kbd {
  display: inline-flex;
  min-width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: 1px solid #cfc9bd;
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fffefa;
  color: #30343a;
  padding: 0 5px;
  font-size: 0.75rem;
  font-weight: 800;
}

.stage {
  min-width: 0;
}

#boardTitle {
  margin: 0 0 18px;
  color: #111820;
  font-family: var(--font-display);
  font-size: 4.3rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.02;
  text-align: center;
}

.tier-board {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--board);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
}

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

.tier-label {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #172026;
  padding: 14px;
  font-family: var(--font-display);
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.drop-zone {
  display: flex;
  min-height: var(--tier-row-height);
  align-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-radius: 8px;
  transition:
    background-color 180ms ease,
    box-shadow 180ms ease;
}

.tier-items {
  background: var(--board-row);
  padding: 12px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.025),
    inset 0 10px 24px rgba(0, 0, 0, 0.08);
}

.tier-items.drop-target {
  background: var(--board-row-hover);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.unranked-section {
  margin-top: 18px;
}

.deck-status,
.deck-progress {
  display: none;
}

.unranked-section .section-heading {
  margin-bottom: 10px;
}

.unranked-list {
  min-height: var(--tier-row-height);
  border: 1px solid rgba(22, 24, 28, 0.1);
  background: rgba(255, 253, 250, 0.72);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(27, 26, 22, 0.06);
}

.unranked-list.drop-target {
  background: #ffffff;
  box-shadow:
    0 8px 24px rgba(27, 26, 22, 0.08),
    inset 0 0 0 2px rgba(23, 105, 255, 0.18);
}

.item-card {
  display: inline-flex;
  min-width: 92px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--chip-line);
  border-radius: 8px;
  background: var(--chip);
  color: #171b20;
  padding: 9px 14px;
  font-family: var(--font-display);
  box-shadow: var(--chip-shadow);
  cursor: move;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.12;
  overflow-wrap: anywhere;
  text-align: center;
  touch-action: none;
  user-select: none;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease;
}

.item-card:hover {
  border-color: #bfc8d3;
  transform: translateY(-1px);
}

.item-card.dragging {
  position: fixed;
  z-index: 1000;
  box-shadow: 0 22px 52px rgba(8, 12, 18, 0.28);
  cursor: grabbing;
  opacity: 0.96;
  pointer-events: none;
  transform: scale(1.04);
}

body:has(.item-card.dragging),
body:has(.item-card.dragging) * {
  cursor: grabbing;
}

.item-placeholder {
  min-width: 92px;
  min-height: 44px;
  border: 2px dashed rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.unranked-list .item-placeholder {
  border-color: rgba(23, 105, 255, 0.28);
  background: rgba(23, 105, 255, 0.06);
}

.deck-complete {
  display: flex;
  width: 100%;
  min-height: 96px;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.62);
  padding: 18px;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  text-align: center;
}

.exit-presentation {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(17, 24, 32, 0.74);
  color: #ffffff;
  padding: 0 14px;
  font-weight: 850;
  cursor: pointer;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 180ms ease;
}

body.presentation {
  background: #f1eee7;
  overflow-x: hidden;
}

body.presentation .setup-only {
  display: none;
}

body.presentation .app {
  width: 100vw;
  min-height: 100vh;
  padding: clamp(12px, 1.25vw, 30px);
}

body.presentation #boardTitle {
  margin-bottom: clamp(14px, 2vh, 24px);
  font-size: clamp(4.8rem, 3.75vw, 6rem);
}

body.presentation .tier-board {
  gap: clamp(9px, 0.55vw, 12px);
  border-radius: 16px;
  padding: clamp(10px, 0.55vw, 12px);
}

body.presentation .tier-row {
  grid-template-columns: var(--presentation-label-width) minmax(0, 1fr);
  gap: clamp(9px, 0.55vw, 12px);
  min-height: var(--presentation-row-height);
}

body.presentation .tier-label {
  padding: clamp(14px, 1vw, 20px);
  font-size: clamp(1.72rem, 1.35vw, 2.15rem);
}

body.presentation .drop-zone {
  gap: clamp(10px, 0.8vw, 16px);
  min-height: var(--presentation-row-height);
}

body.presentation .item-card {
  min-height: clamp(50px, 4.35vh, 62px);
  min-width: clamp(104px, 6vw, 130px);
  padding: clamp(10px, 0.75vw, 14px) clamp(18px, 1.15vw, 28px);
  font-size: clamp(1.16rem, 0.95vw, 1.5rem);
}

body.presentation .unranked-section {
  display: grid;
  grid-template-columns: var(--presentation-label-width) minmax(0, 1fr);
  grid-template-areas: "progress deck";
  gap: clamp(9px, 0.55vw, 12px);
  margin-top: clamp(14px, 2vh, 22px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--board);
  border-radius: 16px;
  padding: clamp(10px, 0.55vw, 12px);
  box-shadow: var(--shadow);
}

body.presentation .unranked-section .section-heading {
  display: none;
}

body.presentation .deck-status {
  display: none;
}

body.presentation .deck-progress {
  display: flex;
  grid-area: progress;
  min-height: clamp(190px, 16.5vh, 238px);
  flex-direction: column;
  justify-content: center;
  border-radius: 8px;
  background: #e4dfd4;
  padding: clamp(24px, 1.6vw, 32px);
}

body.presentation .progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #2a3037;
  font-size: clamp(0.86rem, 0.7vw, 1.1rem);
  font-weight: 900;
}

body.presentation .progress-track {
  height: clamp(18px, 1.25vw, 24px);
  margin-top: clamp(14px, 1vw, 20px);
  overflow: hidden;
  border-radius: 999px;
  background: rgba(17, 24, 32, 0.14);
  box-shadow: inset 0 1px 2px rgba(17, 24, 32, 0.12);
}

body.presentation .progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ef8585, #f4dd7a, #aee47c);
  transition: width 220ms ease;
}

body.presentation .unranked-list {
  grid-area: deck;
  min-height: clamp(190px, 16.5vh, 238px);
  justify-content: center;
  border: 0;
  background: var(--board-row);
  padding: clamp(18px, 1.3vw, 28px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.025),
    inset 0 10px 24px rgba(0, 0, 0, 0.08);
}

body.presentation .unranked-list.drop-target {
  background: var(--board-row-hover);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}

body.presentation .unranked-list .item-placeholder {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.08);
}

body.presentation .unranked-list .item-card {
  min-width: min(clamp(560px, 30vw, 700px), 100%);
  min-height: clamp(112px, 9.8vh, 142px);
  padding: clamp(20px, 1.4vw, 30px) clamp(34px, 2vw, 48px);
  border-radius: 10px;
  font-size: clamp(2.6rem, 3vw, 4.25rem);
  box-shadow: 0 18px 44px rgba(4, 7, 11, 0.25);
}

body.presentation .section-heading h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
}

body:not(.presentation) .exit-presentation {
  display: none;
}

body.presentation .exit-presentation:hover,
body.presentation .exit-presentation:focus-visible {
  opacity: 1;
}

@media (max-width: 1120px) {
  .app {
    width: min(100vw - 28px, 1760px);
  }

  .topbar,
  .setup-grid {
    grid-template-columns: 1fr;
  }

  .setup-grid {
    height: auto;
    min-height: 0;
  }

  .primary-actions {
    flex-wrap: wrap;
  }

  .editor-list {
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .app {
    width: min(100vw - 20px, 1760px);
    padding-top: 14px;
  }

  .tier-row,
  body.presentation .tier-row {
    grid-template-columns: minmax(112px, 34vw) minmax(0, 1fr);
  }

  body.presentation .unranked-section {
    grid-template-columns: minmax(112px, 34vw) minmax(0, 1fr);
  }

  #boardTitle,
  body.presentation #boardTitle {
    font-size: 2.5rem;
  }

  .tier-label {
    font-size: 1rem;
  }

  .editor-row,
  .tier-editor-row {
    grid-template-columns: 1fr;
  }

  .editor-actions,
  .json-actions {
    flex-wrap: wrap;
  }

  .shortcuts {
    grid-template-columns: 1fr;
  }
}
