:root {
  --bg: #000000;
  --board: #141414;
  --tile: #0e0e0e;
  --tile-border: #2a2a2a;
  --line: #1f1f1f;
  --text: #f5f5f5;
  --muted: #9a9a9a;
  --soft: #6f6f6f;
  --panel: #111111;
  --btn: #1c1c1c;
  --btn-border: #2e2e2e;
  --radius: 18px;
  --card-width: 960px;
  --label-width: 88px;
  --tile-w: 88px;
  --tile-h: 96px;
  --s: #ff5d5d;
  --a: #ff9a3d;
  --b: #ffd23d;
  --c: #5fd66b;
  --d: #43c5e0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

body { min-height: 100vh; }

button, input {
  font: inherit;
  color: inherit;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 72px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.brand strong {
  display: block;
  font-size: 20px;
  letter-spacing: -0.03em;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  background: var(--btn);
  border: 1px solid var(--btn-border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn:hover { background: #242424; }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.btn-primary {
  background: #f5f5f5;
  color: #111;
  border-color: #f5f5f5;
}

.btn-primary:hover { background: #ffffff; }

.btn:disabled { opacity: 0.55; cursor: wait; }

.stage {
  overflow-x: auto;
  padding-bottom: 8px;
}

.export-card {
  width: var(--card-width);
  margin: 0 auto;
  padding: 24px 20px 20px;
  background: #000;
}

.board-title {
  margin: 0 0 16px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  outline: none;
  min-height: 1.2em;
}

.board-title:empty::before {
  content: "Untitled ranking";
  color: #555;
}

.board {
  background: var(--board);
  border: 1px solid #262626;
  border-radius: var(--radius);
  overflow: hidden;
}

.tier-row {
  display: flex;
  min-height: 112px;
  align-items: stretch;
}

.tier-row + .tier-row {
  border-top: 1px solid var(--line);
}

.tier-label {
  width: var(--label-width);
  flex: 0 0 var(--label-width);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #111;
  font-weight: 800;
  font-size: 36px;
  line-height: 1;
  letter-spacing: 0;
  padding: 10px 8px;
  outline: none;
  white-space: nowrap;
}

.tier-items {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  align-content: flex-start;
  min-height: 112px;
  min-width: 0;
}

.tile {
  position: relative;
  width: var(--tile-w);
  height: var(--tile-h);
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px 8px;
  cursor: grab;
  user-select: none;
}

.tile:active { cursor: grabbing; }

.tile-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 40px;
}

.tile-icon svg {
  width: 34px;
  height: 34px;
  display: block;
}

.tile-emoji {
  font-size: 28px;
  line-height: 1;
}

.tile-letter {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.tile-name {
  font-size: 11px;
  line-height: 1.2;
  color: #bdbdbd;
  text-align: center;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  outline: none;
  cursor: inherit;
}

.tile-name[contenteditable="true"] {
  cursor: text;
  color: #fff;
}

.tile-x {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 999px;
  background: #000c;
  color: #ccc;
  font-size: 13px;
  line-height: 18px;
  display: none;
  cursor: pointer;
  padding: 0;
}

.tile:hover .tile-x,
.tile:focus-within .tile-x { display: block; }

body.exporting .tile-x { display: none !important; }
body.exporting .board-title { caret-color: transparent; }

.tile-ghost {
  opacity: 0.35;
}

.tile-drag {
  opacity: 0.95;
  transform: scale(1.03);
}

.sortable-ghost {
  opacity: 0.35;
}

.dock-wrap {
  width: min(var(--card-width), 100%);
  margin: 28px auto 0;
}

.dock-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.dock-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.dock-head p {
  margin: 0;
  font-size: 12px;
  color: var(--soft);
}

.dock {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 112px;
  padding: 10px;
  background: #0c0c0c;
  border: 1px dashed #2a2a2a;
  border-radius: 14px;
}

.dock:empty::after {
  content: "Dock is empty. Add an item or pick a template.";
  color: var(--soft);
  font-size: 13px;
  align-self: center;
  padding: 8px;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
}

.modal::backdrop {
  background: #000000cc;
}

.modal-card {
  width: min(560px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid #2a2a2a;
  border-radius: 16px;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-card h2 {
  margin: 0;
  font-size: 18px;
}

.modal-lead {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-x {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-card label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.modal-card input {
  background: #0c0c0c;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}

.modal-card input::placeholder {
  color: #6f6f6f;
}

.modal-card input:focus {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.modal-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.template-card {
  text-align: left;
  background: #0c0c0c;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  color: inherit;
}

.template-card:hover { border-color: #4a4a4a; }

.template-card strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.template-card span {
  color: var(--muted);
  font-size: 12px;
}

.quick-emoji {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-emoji button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #2a2a2a;
  background: #0c0c0c;
  cursor: pointer;
  font-size: 18px;
}

.swatch-label {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch[aria-pressed="true"] {
  border-color: #fff;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #f5f5f5;
  color: #111;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  z-index: 20;
}

@media (max-width: 720px) {
  .page { padding: 14px 12px 56px; }
  .board-title { font-size: 24px; }
  .template-grid { grid-template-columns: 1fr; }
  .dock-head { flex-direction: column; }
}
