.place-shift-card {
  min-width: 0;
  grid-column: 1 / -1;
}

.place-shift-activity {
  padding: 18px 16px 16px;
}

.place-shift-board {
  position: relative;
  --shift-gap: clamp(3px, 1vw, 8px);
}

.place-shift-grid {
  position: relative;
  display: grid;
  width: 100%;
  grid-template-columns: repeat(var(--shift-columns), minmax(0, 1fr));
  grid-template-rows: 2.8em 64px;
  justify-content: center;
  column-gap: var(--shift-gap);
  row-gap: 6px;
}

.place-shift-label {
  grid-row: 1;
  min-height: 0;
  height: 2.8em;
  padding: 2px 1px;
  overflow: hidden;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.15;
}

.place-shift-cell {
  position: relative;
  grid-row: 2;
  min-height: 64px;
  border-radius: 12px;
  color: #172033;
  background: #f1f5f9;
  font-size: clamp(26px, 5.5vw, 40px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.place-shift-cell.is-zero {
  color: #1d4ed8;
  background: #dbeafe;
}

.place-shift-comma-mark {
  position: absolute;
  grid-column: 1 / -1;
  grid-row: 2;
  z-index: 2;
  right: auto;
  bottom: 18px;
  left: calc(
    var(--comma-at) * (100% - (var(--shift-columns) - 1) * var(--shift-gap))
      / var(--shift-columns)
    + (var(--comma-at) - 1) * var(--shift-gap)
    + var(--shift-gap) / 2
  );
  width: 0;
  color: #2563eb;
  font-size: 28px;
  font-weight: 900;
  line-height: 0;
  pointer-events: none;
  transform: translate(-50%, 0);
}

.place-shift-comma-mark.is-moving {
  animation: comma-slide .75s ease forwards;
}

@keyframes comma-slide {
  to {
    left: calc(
      (var(--comma-at) + var(--comma-cells))
        * (100% - (var(--shift-columns) - 1) * var(--shift-gap))
        / var(--shift-columns)
      + (var(--comma-at) + var(--comma-cells) - 1) * var(--shift-gap)
      + var(--shift-gap) / 2
    );
  }
}

.place-shift-cell.is-ones {
  box-shadow: inset 0 -3px 0 #93c5fd;
}

.place-shift-label,
.place-shift-cell {
  display: grid;
  min-width: 0;
  place-items: center;
  text-align: center;
}

.place-shift-cell.is-empty {
  color: #cbd5e1;
  background: #f8fafc;
}

.place-shift-reading {
  margin: 12px 0 0;
  color: #0f172a;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.place-shift-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.place-shift-controls button {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  color: #1d4ed8;
  background: #eff6ff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.place-shift-controls button[data-shift-check] {
  border: 0;
  color: #fff;
  background: var(--accent, #2855d9);
}

.place-shift-feedback {
  min-height: 24px;
  margin-top: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.place-shift-feedback.success { color: #16794a; }
.place-shift-feedback.error { color: #b42318; }

.pv-place-demo {
  width: 100%;
  padding: 8px 4px 12px;
}

.pv-place-demo-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(var(--place-columns), minmax(0, 1fr));
  gap: clamp(3px, 1vw, 8px);
}

.pv-place-demo-digit,
.pv-place-demo-name {
  display: grid;
  min-width: 0;
  place-items: center;
  border-radius: 12px;
  text-align: center;
}

.pv-place-demo-digit {
  position: relative;
  min-height: 64px;
  color: #172033;
  background: #f1f5f9;
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pv-place-demo-digit.before-comma::after {
  position: absolute;
  right: -.12em;
  bottom: .13em;
  color: #2563eb;
  content: ",";
  font-size: .72em;
}

.pv-place-demo-digit.is-current {
  color: #fff;
  background: #2563eb;
}

.pv-place-demo-name {
  min-height: 48px;
  padding: 6px 4px;
  color: #94a3b8;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
}

.pv-place-demo-name.is-lit {
  color: #1d4ed8;
  background: #dbeafe;
}

.pv-place-demo-name.is-current {
  color: #fff;
  background: #2563eb;
}

/* The complete number stays visible, including the spare places for shifting. */
.place-shift-activity {
  min-width: 0;
  max-width: 100%;
  container-type: inline-size;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
.place-shift-activity .place-shift-board { width: 100%; min-width: 0; }
.place-shift-activity .place-shift-grid { grid-template-rows: 44px 64px; }
.place-shift-activity .place-shift-label {
  height: auto;
  overflow-wrap: anywhere;
  align-self: stretch;
  font-size: 12px;
  line-height: 1.2;
}
@container (max-width: 600px) {
  .place-shift-board { --shift-gap: 3px; }
  .place-shift-activity .place-shift-grid { grid-template-rows: 108px 48px; }
  .place-shift-activity .place-shift-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 108px;
    box-sizing: border-box;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    justify-self: center;
    white-space: nowrap;
    overflow: visible;
    font-size: 11px;
    padding: 4px 0;
  }
  .place-shift-activity .place-shift-cell {
    min-height: 48px;
    border-radius: 6px;
    font-size: clamp(18px, 5vw, 28px);
  }
  .place-shift-activity .place-shift-comma-mark { bottom: 12px; font-size: 24px; }
  .place-shift-activity .place-shift-reading { font-size: 17px; }
  .place-shift-activity .place-shift-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .place-shift-controls button {
    min-width: 0;
    min-height: 44px;
    padding: 8px 6px;
    border-radius: 6px;
  }
  .place-shift-controls button[data-shift-check] { grid-column: 1 / -1; }
}
/* Viewport fallback for mobile browsers without reliable container queries. */
@media (max-width: 720px) {
  .place-shift-board { --shift-gap: 3px; }
  .place-shift-activity .place-shift-grid { grid-template-rows: 108px 48px; }
  .place-shift-activity .place-shift-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 108px;
    box-sizing: border-box;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    justify-self: center;
    white-space: nowrap;
    overflow: visible;
    font-size: 11px;
    padding: 4px 0;
  }
  .place-shift-activity .place-shift-cell {
    min-height: 48px;
    border-radius: 6px;
    font-size: clamp(18px, 5vw, 28px);
  }
  .place-shift-activity .place-shift-comma-mark { bottom: 12px; font-size: 24px; }
  .place-shift-activity .place-shift-reading { font-size: 17px; }
  .place-shift-activity .place-shift-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .place-shift-controls button {
    min-width: 0;
    min-height: 44px;
    padding: 8px 6px;
    border-radius: 6px;
  }
  .place-shift-controls button[data-shift-check] { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .place-shift-card .place-shift-activity { padding: 8px 0 0; }
}
