/* ── 主台：数字、画布、操作紧贴在一起 ───────────────────── */

.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.board__code {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
}

.board__actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
}

.board__actions .btn--big {
  flex: 1;
}

/* 暗号输入框：一位数字一列，随时可改 */
.code {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  padding: 0 var(--space-3);
  background: var(--color-layer-dim);
  border: 0;
  border-radius: var(--radius-md);
  color: var(--color-ink);
  font-size: var(--font-size-xl);
  font-weight: 700;
  letter-spacing: 0.24em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.code:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: var(--color-layer);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.stage__canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #ffffff;
  cursor: grab;
  /* 手势归不归自己管，按下那一刻在 touchstart 里定：
     按在物品或水印上就拦下来自己拖，按在空处照常让页面滚 */
  -webkit-touch-callout: none;
}

.stage__canvas:active {
  cursor: grabbing;
}

/* ── 列条与控制 ─────────────────────────────────────────── */

.tray {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.strip {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--color-layer-dim);
  border-radius: var(--radius-md);
  justify-content: safe center;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  /* 列条自己横滚交给浏览器，只有把手那一条归脚本管 */
  touch-action: pan-x;
  scroll-padding: var(--space-2);
}

.chip {
  position: relative;
  flex: 0 0 auto;
  min-width: 78px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2) var(--space-2);
  background: var(--color-layer);
  border: 0;
  border-radius: var(--radius-md);
  cursor: grab;
  touch-action: pan-x;
  transition: background-color var(--duration) var(--ease);
}

.chip:active {
  cursor: grabbing;
}

.chip[data-selected="true"] {
  background: var(--color-highlight);
}

.chip[data-dragging="true"] {
  z-index: 2;
  transform: scale(1.06);
  box-shadow: 0 8px 20px rgba(31, 27, 25, 0.26);
}

/* 顶上这条是拖拽把手，按住它就能改顺序 */
.chip__handle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin: calc(var(--space-2) * -1) calc(var(--space-2) * -1) 0;
  padding: 3px 0;
  background: var(--color-layer-dim);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  color: var(--color-ink-soft);
  cursor: grab;
  touch-action: none;
}

.chip__handle:active {
  cursor: grabbing;
}

.chip[data-selected="true"] .chip__handle {
  background: rgba(255, 255, 255, 0.6);
  color: var(--color-ink);
}

.chip__order {
  font-size: var(--font-size-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chip__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  padding: 2px;
  background: var(--color-layer-dim);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip[data-selected="true"] .chip__icon {
  background: var(--color-layer);
}

.chip__handle svg {
  display: block;
}

.chip__icon:hover {
  background: var(--color-layer-mute);
}

.chip__icon img {
  max-height: 100%;
  width: auto;
  object-fit: contain;
}

.chip__count {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.chip__step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  background: var(--color-layer-dim);
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-ink);
  font-size: var(--font-size-md);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip[data-selected="true"] .chip__step {
  background: var(--color-layer);
}

.chip__step:hover:not(:disabled) {
  background: var(--color-layer-mute);
}

.chip__step:disabled {
  opacity: 0.3;
  cursor: default;
}

.chip__value {
  flex: 0 0 auto;
  min-width: 1.4em;
  text-align: center;
  font-size: var(--font-size-md);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chip__remove {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-layer-deep);
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-ink);
  font-size: var(--font-size-sm);
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip__remove:hover {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

.chip--add {
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--color-layer);
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-ink-soft);
  cursor: pointer;
}

.chip--add:hover:not(:disabled) {
  background: var(--color-layer-mute);
}

.chip--add:disabled {
  opacity: 0.35;
  cursor: default;
}

.tip {
  color: var(--color-ink-soft);
  font-size: var(--font-size-xs);
  text-align: center;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-layer-dim);
  border-radius: var(--radius-md);
}

.control {
  display: grid;
  grid-template-columns: 4.5em 1fr auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 36px;
}

.control__label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-ink-soft);
}

.control__value {
  min-width: 3.2em;
  font-size: var(--font-size-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.control .segmented {
  grid-column: 2 / -1;
  justify-self: start;
}

/* ── 按钮 ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-size);
  min-width: var(--tap-size);
  padding: 0 var(--space-4);
  background: var(--color-layer-dim);
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-ink);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), opacity var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--color-layer-mute);
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
}

.btn--block {
  width: 100%;
}

.btn--big {
  min-height: 50px;
  font-size: var(--font-size-md);
}

.btn--round {
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: var(--radius-pill);
  line-height: 1;
}

.board__code .btn--round {
  width: 52px;
  height: 52px;
  min-height: 52px;
}

/* ── 分段选择器，替代原生下拉 ───────────────────────────── */

.segmented {
  display: inline-flex;
  gap: var(--space-1);
  padding: 3px;
  background: var(--color-layer);
  border-radius: var(--radius-pill);
}

.segmented__item {
  min-height: 30px;
  padding: 0 var(--space-3);
  background: transparent;
  border: 0;
  border-radius: var(--radius-pill);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-ink-soft);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.segmented__item:hover {
  background: var(--color-layer-dim);
  color: var(--color-ink);
}

.segmented__item[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

.segmented__item--glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  padding: 0;
}

.segmented__item--glyph svg {
  display: block;
}

/* ── 滑动条：自定义外观 ─────────────────────────────────── */

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.slider:disabled {
  opacity: 0.35;
  cursor: default;
}

.slider::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--color-layer-mute);
  border-radius: var(--radius-pill);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-pill);
}

.slider::-moz-range-track {
  height: 6px;
  background: var(--color-layer-mute);
  border-radius: var(--radius-pill);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-pill);
}

/* ── 弹窗 ───────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal__scrim {
  position: absolute;
  inset: 0;
  background: rgba(31, 27, 25, 0.4);
}

.modal__box {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(380px, 100%);
  max-height: 100%;
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-2) var(--space-4);
}

.modal__title {
  font-size: var(--font-size-md);
}

/* 图案一屏放完，不滚动：网格按可用空间等比缩放 */
.modal__body {
  display: flex;
  min-height: 0;
  padding: 0 var(--space-3) var(--space-3);
  overflow: hidden;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: var(--space-1);
  aspect-ratio: 4 / 5;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
}

.icon-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: var(--space-1);
  background: var(--color-layer-dim);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.icon-cell:hover {
  background: var(--color-layer-mute);
}

.icon-cell[data-state="taken"] {
  background: var(--color-layer-deep);
}

.icon-cell[data-state="current"] {
  background: var(--color-highlight);
}

.icon-cell img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ── 轻提示 ─────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  z-index: 80;
  transform: translateX(-50%);
  max-width: min(360px, calc(100vw - var(--space-6)));
  padding: var(--space-3) var(--space-4);
  background: var(--color-ink);
  color: var(--color-ink-invert);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-sm);
  text-align: center;
}

@media (max-width: 359px) {
  .code {
    letter-spacing: 0.14em;
    font-size: var(--font-size-lg);
  }

  .control {
    grid-template-columns: 4em 1fr auto;
    gap: var(--space-2);
  }
}

/* ── 操作台 ─────────────────────────────────────────────── */

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-layer-dim);
  border-radius: var(--radius-lg);
}

.lead {
  font-size: var(--font-size-sm);
  color: var(--color-ink-soft);
  text-align: center;
}

.themes {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.theme {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-layer-dim);
  border: 0;
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.theme:hover {
  background: var(--color-layer-mute);
}

.theme[data-active="true"] {
  background: var(--color-highlight);
}

.theme__cover {
  flex: 0 0 auto;
  width: 72px;
  height: 54px;
  object-fit: contain;
}

.theme__name {
  flex: 1;
  min-width: 0;
  font-size: var(--font-size-md);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme__badge {
  flex: 0 0 auto;
  padding: 2px var(--space-3);
  background: var(--color-accent);
  border-radius: var(--radius-pill);
  color: var(--color-accent-ink);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

.name {
  text-align: center;
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: normal;
}

.name::placeholder {
  color: var(--color-ink-soft);
  font-weight: 500;
}

.wheel-mount {
  display: flex;
  justify-content: center;
}

.wheel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.wheel__disc {
  width: 220px;
  max-width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

.wheel__bar {
  width: 220px;
  max-width: 100%;
  height: 22px;
  border-radius: var(--radius-pill);
  touch-action: none;
  cursor: pointer;
}

.wheel__readout {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.wheel__dot {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 2px var(--color-layer), 0 0 0 1px var(--color-layer-deep);
}

.wheel__field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.wheel__tag {
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: var(--color-ink-soft);
}

.wheel__value {
  width: 3.4em;
  min-height: 32px;
  padding: 0 var(--space-2);
  background: var(--color-layer);
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--color-ink);
  font-size: var(--font-size-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  background: var(--color-layer);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.slot:hover {
  background: var(--color-layer-mute);
}

.slots .slot {
  aspect-ratio: 4 / 3;
}

.slot__hint {
  padding: 0 var(--space-2);
  color: var(--color-ink-soft);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-body);
  text-align: center;
}

.slot__image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.slot__button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.slot--grid {
  aspect-ratio: 1;
  padding: var(--space-2);
}

.slot--add {
  aspect-ratio: 1;
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-ink-soft);
}

.masthead__back {
  grid-column: 1;
  justify-self: start;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-pill);
  color: var(--color-accent-ink);
  font-size: var(--font-size-lg);
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.masthead__back:hover {
  background: rgba(255, 255, 255, 0.32);
}

.workbench {
  margin-top: var(--space-2);
  text-decoration: none;
}
