/* Play stage: HUD, square grid sized to its area (container query units),
   tools and digit pad. Portrait: pad under the grid. Landscape: pad on the
   right as a 3×3 block. */
.sd-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.6rem;
  width: 100%;
  min-width: 0;
  max-width: 40rem;
  margin: 0 auto;
}

.sd-hud {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.75rem;
  font-size: 0.9rem;
}

.sd-hud-level {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--sd-accent-soft);
  color: var(--sd-accent);
  font-weight: 800;
}

.sd-hud-item {
  color: var(--sd-muted);
}

.sd-hud-item strong {
  color: var(--sd-ink);
}

.sd-hud-time {
  margin-left: auto;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.sd-pause {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--sd-surface);
  color: var(--sd-ink);
  box-shadow: var(--sd-shadow);
  cursor: pointer;
}

.sd-pause svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

/* --- Grid --- */
.sd-board-area {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.sd-board {
  --side: min(100cqw, 100cqh);
  width: var(--side);
  height: var(--side);
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border-radius: 0.75rem;
  background: var(--sd-line-strong);
  box-shadow: var(--sd-shadow);
  overflow: hidden;
}

.sd-box {
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--sd-line);
}

.sd-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: none;
  background: var(--sd-surface);
  color: var(--sd-user);
  font-size: calc(var(--side) * 0.062);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s;
}

.sd-cell:focus-visible {
  outline: 3px solid var(--sd-accent);
  outline-offset: -3px;
}

.sd-value,
.sd-notes {
  grid-area: 1 / 1;
}

.sd-value {
  align-self: center;
  line-height: 1;
}

.sd-notes {
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  place-items: center;
  padding: 1px;
  font-size: calc(var(--side) * 0.026);
  font-weight: 700;
  line-height: 1;
  color: var(--sd-muted);
}

.sd-note.is-focus {
  color: var(--sd-accent);
}

.sd-cell.is-given {
  color: var(--sd-ink);
  font-weight: 700;
}

.sd-cell.is-peer {
  background: var(--sd-peer);
}

.sd-cell.is-blocked {
  background: var(--sd-blocked);
}

.sd-cell.is-open {
  background: var(--sd-open);
}

.sd-cell.is-hinted {
  color: var(--sd-hinted);
}

.sd-cell.is-wrong {
  color: var(--sd-wrong);
}

.sd-cell.is-wrong:not(.is-selected) {
  background: var(--sd-wrong-bg);
}

/* The focused digit (solid) and the last tapped cell (amber) never share a look. */
.sd-cell.is-same {
  background: var(--sd-same);
  color: var(--sd-same-ink);
}

.sd-cell.is-same.is-wrong {
  background: var(--sd-wrong);
  color: #ffffff;
}

.sd-cell.is-selected {
  background: var(--sd-selected);
  box-shadow: inset 0 0 0 2px var(--sd-line-strong);
}

.sd-cell.is-selected.is-same {
  color: var(--sd-ink);
}

.sd-cell.is-flash {
  animation: sd-flash 0.7s ease;
}

@keyframes sd-flash {
  40% {
    background: var(--sd-flash);
    transform: scale(0.92);
  }
}

.sd-stage.is-paused .sd-value,
.sd-stage.is-paused .sd-notes {
  visibility: hidden;
}

.sd-paused {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  font-size: 1.6rem;
  font-weight: 900;
}

.sd-paused p {
  margin: 0;
}

/* --- Tools and pad --- */
.sd-controls {
  display: grid;
  gap: 0.6rem;
  min-height: 0;
}

.sd-tools {
  display: flex;
  gap: 0.4rem;
}

.sd-tool {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.25rem;
  border: none;
  border-radius: 0.75rem;
  background: transparent;
  color: var(--sd-ink);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.sd-tool svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sd-tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.sd-tool[aria-pressed="true"] {
  background: var(--sd-accent);
  color: #ffffff;
}

.sd-pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
}

.sd-key {
  display: grid;
  place-content: center;
  gap: 1px;
  height: clamp(50px, 13vw, 66px);
  padding: 0;
  border: none;
  border-radius: 0.75rem;
  background: var(--sd-surface);
  color: var(--sd-accent);
  box-shadow: var(--sd-shadow);
  cursor: pointer;
}

.sd-key-digit {
  font-size: clamp(1.45rem, 6vw, 2rem);
  font-weight: 700;
  line-height: 1;
}

.sd-key-left {
  min-height: 0.8em;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--sd-muted);
}

.sd-key.is-focus {
  background: var(--sd-same);
  color: var(--sd-same-ink);
}

.sd-key.is-focus .sd-key-left {
  color: inherit;
  opacity: 0.8;
}

.sd-key.is-done {
  opacity: 0.35;
}

.sd-key:active,
.sd-tool:active {
  transform: scale(0.94);
}

@media (min-aspect-ratio: 6/5) {
  .sd-stage {
    max-width: none;
    grid-template-columns: minmax(0, 1fr) clamp(190px, 32vw, 60dvh);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 1.4rem;
  }

  .sd-hud {
    grid-column: 1 / -1;
  }

  .sd-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .sd-pad {
    flex: 0 1 21rem;
    min-height: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .sd-key {
    height: auto;
    min-height: 0;
  }

  .sd-key-digit {
    font-size: clamp(1.4rem, 3.4vw, 2.3rem);
  }
}

/* Short landscape phones: grid on the left, a tighter pad on the right. */
@media (orientation: landscape) and (max-height: 500px) {
  .sd-stage {
    gap: 0.3rem;
  }

  .sd-hud {
    min-height: 2.5rem;
  }

  .sd-pause {
    width: 2.5rem;
    height: 2.5rem;
  }

  .sd-tool {
    padding: 0.2rem;
    font-size: 0.7rem;
  }

  .sd-tool svg {
    width: 1.2rem;
    height: 1.2rem;
  }

  .sd-pad {
    gap: 0.3rem;
  }
}

/* TV: the pad and its digits grow with the screen. */
@media (min-width: 960px) and (min-height: 500px) {
  .sd-key-digit {
    font-size: max(2rem, 4.5dvh);
  }

  .sd-key-left {
    font-size: max(0.68rem, 1.8dvh);
  }

  .sd-tool {
    font-size: max(0.78rem, 2.2dvh);
  }

  .sd-tool svg {
    width: max(24px, 3.5dvh);
    height: max(24px, 3.5dvh);
  }
}
