.spider-shell {
  width: min(1240px, 100%);
}

.spider-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 18px;
  background: #f9fbfe;
  border-bottom: 1px solid var(--line);
}

.spider-mode-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.spider-mode-btn,
.spider-control-bar button,
.spider-stock-card,
.spider-result-card button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  transition:
    border-color 0.18s,
    background 0.18s,
    color 0.18s;
}

.spider-mode-btn {
  padding: 0 16px;
}

.spider-mode-btn.active,
.spider-control-bar button:first-child,
.spider-result-card button {
  color: #fff;
  background: #1f7a5c;
  border-color: #1f7a5c;
}

.spider-mode-btn:hover,
.spider-mode-btn:focus-visible,
.spider-control-bar button:hover,
.spider-control-bar button:focus-visible,
.spider-stock-card:hover,
.spider-stock-card:focus-visible,
.spider-result-card button:hover,
.spider-result-card button:focus-visible {
  border-color: #1f7a5c;
  outline: none;
}

.spider-control-bar button:disabled,
.spider-stock-card:disabled {
  cursor: not-allowed;
  color: #97a3b6;
  background: #eef2f7;
  border-color: var(--line);
}

.spider-score-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(74px, 1fr));
  gap: 8px;
}

.spider-score-grid div {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  background: #101828;
  color: #fff;
}

.spider-score-grid span {
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

.spider-score-grid strong {
  max-width: 100%;
  overflow: hidden;
  color: #f4c95d;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
}

.spider-play-area {
  position: relative;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px), #116149;
  background-size: 20px 20px;
}

.spider-table-top {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 240px;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}

.spider-stock-card {
  min-height: 74px;
  display: grid;
  place-content: center;
  gap: 2px;
  padding: 8px;
  background: #fff;
}

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

.spider-stock-card strong {
  font-size: 18px;
}

.spider-foundation-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(54px, 1fr));
  gap: 8px;
}

.spider-foundation-pile {
  min-height: 74px;
  display: grid;
  place-items: center;
  padding: 4px;
  border: 1px dashed rgba(255, 255, 255, 0.48);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(11, 63, 50, 0.36);
  font-weight: 900;
  text-align: center;
}

.spider-foundation-pile.black,
.spider-foundation-pile.red {
  border-style: solid;
  background: #fff;
  color: #111827;
}

.spider-foundation-pile.red {
  color: #c8433f;
}

.spider-status-card {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
}

.spider-status-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.spider-status-card strong {
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.35;
}

.spider-tableau-scroll {
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-color: rgba(255, 255, 255, 0.45) rgba(11, 63, 50, 0.4);
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.spider-tableau {
  --card-top: 5px;
  --card-step: 28px;
  --card-height: 104px;
  --table-min-height: 560px;
  min-width: 980px;
  min-height: var(--table-min-height);
  display: grid;
  grid-template-columns: repeat(10, minmax(84px, 1fr));
  gap: 8px;
  align-items: start;
}

.spider-column {
  position: relative;
  min-height: calc(var(--table-min-height) - 12px);
  padding: 5px;
  border-radius: 8px;
  background: rgba(11, 63, 50, 0.32);
  outline: 1px solid rgba(255, 255, 255, 0.08);
}

.spider-column.hint-target {
  outline: 2px solid #f4c95d;
  background: rgba(244, 201, 93, 0.14);
}

.spider-empty-slot {
  height: 118px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.42);
  border-radius: 7px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
  font-weight: 800;
}

.spider-card {
  --offset: 0;
  position: absolute;
  top: calc(var(--card-top) + var(--offset) * var(--card-step));
  left: 5px;
  right: 5px;
  height: var(--card-height);
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: start;
  gap: 2px;
  padding: 8px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 7px;
  background: #fff;
  color: #111827;
  box-shadow: 0 3px 8px rgba(2, 6, 23, 0.22);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.spider-card.face-down {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%) 0 0 / 14px 14px,
    linear-gradient(135deg, transparent 75%, rgba(255, 255, 255, 0.2) 75%) 0 0 / 14px 14px,
    #174b8e;
  border-color: rgba(255, 255, 255, 0.2);
}

.spider-card.face-up.red {
  color: #c8433f;
}

.spider-card span {
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.spider-card strong {
  align-self: end;
  justify-self: end;
  font-size: 28px;
  line-height: 1;
}

.spider-card.selected {
  transform: translateY(-5px);
  outline: 3px solid #f4c95d;
  z-index: 20;
}

.spider-card.hint-source {
  outline: 3px solid rgba(244, 201, 93, 0.72);
  z-index: 18;
}

.spider-result-overlay {
  position: absolute;
  inset: 18px;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 8px;
  background: rgba(16, 24, 40, 0.62);
  z-index: 50;
}

.spider-result-overlay[hidden] {
  display: none;
}

.spider-result-card {
  width: min(300px, 100%);
  display: grid;
  gap: 10px;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.spider-result-card strong {
  font-size: 24px;
  line-height: 1.2;
}

.spider-result-card span {
  color: var(--muted);
}

.spider-result-card button {
  width: 100%;
}

.spider-control-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 18px 18px;
  background: #116149;
}

@media (max-width: 800px) {
  .spider-top,
  .spider-table-top {
    grid-template-columns: 1fr;
  }

  .spider-score-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .spider-foundation-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .spider-tableau {
    min-width: 820px;
    grid-template-columns: repeat(10, 76px);
  }
}

@media (max-width: 700px) {
  .spider-top {
    grid-template-columns: minmax(132px, 0.92fr) minmax(0, 1.08fr);
    align-items: stretch;
    gap: 8px;
    padding: 8px;
  }

  .spider-mode-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }

  .spider-mode-btn {
    min-height: 36px;
    padding: 0 4px;
    font-size: 13px;
  }

  .spider-score-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  .spider-score-grid div {
    min-height: 35px;
    padding: 2px 4px;
  }

  .spider-score-grid span {
    font-size: 10px;
  }

  .spider-score-grid strong {
    font-size: 15px;
  }

  .spider-play-area {
    padding: 6px;
  }

  .spider-table-top {
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 6px;
    margin-bottom: 6px;
  }

  .spider-stock-card {
    min-height: 66px;
    padding: 5px;
  }

  .spider-stock-card span {
    font-size: 12px;
  }

  .spider-stock-card strong {
    font-size: 16px;
  }

  .spider-foundation-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .spider-foundation-pile {
    min-height: 31px;
    padding: 1px;
    border-radius: 5px;
    font-size: 10px;
  }

  .spider-status-card {
    grid-column: 1 / -1;
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 6px 8px;
  }

  .spider-status-card span {
    display: none;
  }

  .spider-status-card strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  .spider-tableau-scroll {
    margin: 0 -6px;
    padding: 0 6px 8px;
    scroll-snap-type: x proximity;
  }

  .spider-tableau {
    --card-top: 4px;
    --card-step: 20px;
    --card-height: 80px;
    --table-min-height: 438px;
    min-width: 650px;
    grid-template-columns: repeat(10, 60px);
    gap: 5px;
  }

  .spider-column {
    min-height: calc(var(--table-min-height) - 10px);
    padding: 4px;
    border-radius: 6px;
    scroll-snap-align: start;
  }

  .spider-empty-slot {
    height: var(--card-height);
    border-radius: 6px;
    font-size: 11px;
  }

  .spider-card {
    left: 4px;
    right: 4px;
    padding: 5px;
    border-radius: 6px;
  }

  .spider-card span {
    font-size: 14px;
  }

  .spider-card strong {
    font-size: 21px;
  }

  .spider-card.selected,
  .spider-card.hint-source {
    outline-width: 2px;
  }

  .spider-card.selected {
    transform: translateY(-3px);
  }

  .spider-result-overlay {
    position: fixed;
    inset: 0;
    padding: 16px;
    border-radius: 0;
    z-index: 100;
  }

  .spider-result-card {
    padding: 18px;
  }

  .spider-control-bar {
    position: sticky;
    bottom: 0;
    z-index: 45;
    gap: 6px;
    padding: 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 -8px 20px rgba(2, 6, 23, 0.18);
  }

  .spider-control-bar button {
    min-height: 40px;
    font-size: 13px;
  }
}

@media (max-width: 380px) {
  .spider-top {
    grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.1fr);
  }

  .spider-mode-btn {
    min-height: 34px;
    font-size: 12px;
  }

  .spider-score-grid strong {
    font-size: 14px;
  }

  .spider-tableau {
    --card-step: 19px;
    --card-height: 76px;
    --table-min-height: 420px;
    min-width: 610px;
    grid-template-columns: repeat(10, 56px);
    gap: 4px;
  }

  .spider-card span {
    font-size: 13px;
  }

  .spider-card strong {
    font-size: 20px;
  }
}
