:root {
  --bg: #0d0e12;
  --row: #17191f;
  --line: #2b303b;
  --tile-bg: #222631;
  --text: #e9ebf0;
  --muted: #8b91a0;
  /* One tile size drives the whole layout. It follows the smaller of the
     screen's width and height so 5 rows plus the tray fit an iPad screen. */
  --tile: clamp(60px, min(11vw, 11.6vh), 150px);
}
@supports (height: 1dvh) {
  :root { --tile: clamp(60px, min(11vw, 11.6dvh), 150px); }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 10px;
}

h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#reset {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
#reset.armed {
  color: #fff;
  background: #b3261e;
  border-color: #b3261e;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px;
}

.row {
  display: flex;
  background: var(--row);
  border-radius: 6px;
  overflow: hidden;
  min-height: calc(var(--tile) + 8px);
}

.label {
  flex: 0 0 var(--tile);
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.42);
  font-weight: 800;
  color: #15171c;
}
.row[data-tier="S"] .label { background: #ff7f7f; }
.row[data-tier="A"] .label { background: #ffbf7f; }
.row[data-tier="B"] .label { background: #ffe97f; }
.row[data-tier="C"] .label { background: #8fe58f; }
.row[data-tier="D"] .label { background: #7fbfff; }

.zone {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  padding: 4px;
  min-height: calc(var(--tile) + 8px);
}

.tray {
  margin: 8px 8px 0;
  border: 1px dashed var(--line);
  border-radius: 6px;
  justify-content: center;
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Sized from the tile, not with %: a % here would follow the row's width. */
  padding: calc(var(--tile) * 0.07) calc(var(--tile) * 0.07) calc(var(--tile) * 0.03);
  background: var(--tile-bg);
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
}
.tile img {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}
.tile span {
  max-width: 100%;
  margin-top: calc(var(--tile) * 0.03);
  font-size: calc(var(--tile) * 0.13);
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.tile.dragging {
  position: fixed;
  z-index: 10;
  margin: 0;
  cursor: grabbing;
  transform: scale(1.08);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6);
  outline: 2px solid rgba(255, 255, 255, 0.35);
}

.placeholder {
  width: var(--tile);
  height: var(--tile);
  border: 2px dashed #4d5466;
  border-radius: 6px;
}

.noscript {
  padding: 16px;
  color: var(--muted);
}
