/* フリーセル固有スタイル */

.fc-stage {
  position: relative;
  width: 100%;
  max-width: min(100%, 780px);
  margin: 0 auto 14px;
}

.fc-board {
  --fc-card-w: clamp(30px, 10.5vw, 80px);
  --fc-card-h: calc(var(--fc-card-w) * 1.4);
  --fc-gap: clamp(3px, 1.1vw, 12px);
  --fc-radius: clamp(4px, 1vw, 9px);
  --fc-board-bg: #0d1730;
  --fc-cell: #3fc4ff;
  --fc-home: #a58bff;
  --fc-target: #ff6fd8;

  position: relative;
  padding: clamp(8px, 2vw, 18px);
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(ellipse 80% 50% at 10% 0%, rgba(63, 196, 255, 0.14), transparent 55%),
    radial-gradient(ellipse 70% 45% at 90% 100%, rgba(165, 139, 255, 0.13), transparent 50%),
    var(--fc-board-bg);
  box-shadow: 0 14px 34px rgba(28, 52, 96, 0.24);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.fc-top,
.fc-tableau {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  column-gap: var(--fc-gap);
  align-items: start;
}

.fc-top {
  margin-bottom: clamp(12px, 2.6vw, 22px);
}

.fc-slot {
  position: relative;
  width: var(--fc-card-w);
  min-height: var(--fc-card-h);
  margin: 0 auto;
  border: 1.5px dashed rgba(96, 154, 214, 0.38);
  border-radius: var(--fc-radius);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.fc-slot:focus-visible {
  outline: 2px solid var(--fc-cell);
  outline-offset: 2px;
}

.fc-slot.is-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.fc-cell {
  height: var(--fc-card-h);
  border: 1.5px solid rgba(63, 196, 255, 0.5);
  background: rgba(63, 196, 255, 0.06);
}

.fc-foundation {
  height: var(--fc-card-h);
  border: 1.5px solid rgba(165, 139, 255, 0.5);
  background: rgba(165, 139, 255, 0.07);
}

.fc-column:not(.is-empty) {
  border-color: transparent;
  background: transparent;
}

.fc-slot.is-target {
  border-style: solid;
  border-color: var(--fc-target);
  background: rgba(255, 111, 216, 0.1);
}

.fc-slot.is-target > .fc-card:last-child {
  outline: 2px solid var(--fc-target);
  outline-offset: 1px;
}

.fc-slot.is-invalid {
  animation: fc-shake 280ms ease;
}

@keyframes fc-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.fc-slot__hint {
  color: rgba(160, 210, 245, 0.6);
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: max(9px, calc(var(--fc-card-w) * 0.2));
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  pointer-events: none;
}

.fc-foundation .fc-slot__hint {
  font-size: calc(var(--fc-card-w) * 0.5);
}

.fc-slot__hint--red {
  color: rgba(255, 138, 150, 0.55);
}

.fc-slot__hint--black {
  color: rgba(200, 190, 255, 0.55);
}

.fc-cell > .fc-card,
.fc-foundation > .fc-card {
  position: absolute;
  top: -1.5px;
  left: -1.5px;
}

.fc-column .fc-card {
  position: absolute;
  left: 0;
}

.fc-card {
  position: relative;
  display: block;
  width: var(--fc-card-w);
  height: var(--fc-card-h);
  margin: 0;
  padding: 0;
  border: 1px solid rgba(20, 36, 68, 0.2);
  border-radius: var(--fc-radius);
  background: linear-gradient(180deg, #ffffff 0%, #f3f7fd 100%);
  box-shadow: 0 2px 6px rgba(8, 16, 36, 0.28);
  color: #1b2436;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  touch-action: manipulation;
  overflow: hidden;
}

.fc-card[data-color="red"] {
  color: #c62828;
}

.fc-card.is-home {
  cursor: default;
}

.fc-card__corner {
  position: absolute;
  display: flex;
  align-items: baseline;
  gap: 1px;
  line-height: 1;
}

.fc-card__corner--tl {
  top: 3%;
  left: 6%;
}

.fc-card__corner--br {
  right: 6%;
  bottom: 3%;
  transform: rotate(180deg);
}

.fc-card__rank {
  font-size: max(10px, calc(var(--fc-card-w) * 0.3));
  font-weight: 700;
  letter-spacing: -0.03em;
}

.fc-card__suit {
  font-size: max(9px, calc(var(--fc-card-w) * 0.25));
}

.fc-card__center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 12%;
  font-size: calc(var(--fc-card-w) * 0.46);
  opacity: 0.92;
  pointer-events: none;
}

.fc-card.is-selected {
  outline: 2px solid var(--fc-cell);
  outline-offset: 1px;
  box-shadow:
    0 0 0 2px rgba(63, 196, 255, 0.3),
    0 0 12px rgba(63, 196, 255, 0.45),
    0 2px 6px rgba(8, 16, 36, 0.28);
}

.fc-card:focus-visible {
  outline: 2px solid var(--fc-cell);
  outline-offset: 1px;
}

.fc-card.is-dragging-source {
  opacity: 0.35;
}

.fc-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  width: var(--fc-card-w);
  --fc-radius: 8px;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(8, 18, 40, 0.45));
  opacity: 0.96;
}

.fc-drag-ghost .fc-card {
  position: absolute;
  left: 0;
}

.fc-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: rgba(11, 20, 42, 0.92);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  text-align: center;
  animation: fc-fade 220ms ease-out;
}

@keyframes fc-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fc-overlay__title {
  margin: 0;
  color: #e8f4ff;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.fc-overlay.is-win .fc-overlay__title {
  color: #7ee0ff;
  text-shadow: 0 0 18px rgba(63, 196, 255, 0.55);
}

.fc-overlay__detail {
  margin: 0 0 8px;
  color: rgba(220, 236, 255, 0.9);
  font-size: 0.95rem;
  line-height: 1.5;
}

.fc-overlay__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.fc-overlay__actions .btn {
  min-width: 140px;
}

.fc-guide {
  max-width: min(100%, 760px);
  margin: 0 auto 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.88rem;
  line-height: 1.55;
  text-align: center;
}

.game-controls {
  justify-content: center;
}

@media (max-width: 560px) {
  /* 8列を少しでも大きく見せるため、tool-card の左右余白まで盤面を広げる */
  .fc-stage {
    width: calc(100% + 28px);
    max-width: none;
    margin-inline: -14px;
  }

  .fc-board {
    padding: 8px 5px 12px;
  }

  .fc-status {
    max-width: 100%;
  }

  .fc-card__center {
    font-size: calc(var(--fc-card-w) * 0.4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fc-overlay,
  .fc-slot.is-invalid {
    animation: none;
  }
}

/* 共通外枠・HUD・操作色を利用し、8列のカードだけ幅に合わせる。 */
html.gs-playing .game-panel { align-items: center; gap: 12px; }
html.gs-playing .game-panel > .gs-bar,
html.gs-playing .fc-status,
html.gs-playing .fc-stage,
html.gs-playing .game-controls {
  flex: none;
  width: 100%;
  max-width: 640px;
  margin: 0;
}
html.gs-playing .fc-stage { container-type: inline-size; }
html.gs-playing .fc-board {
  --fc-gap: clamp(3px, 1cqw, 10px);
  padding: 12px 5px;
  border-color: var(--play-border);
}
html.gs-playing .fc-guide { display: none; }
html.gs-playing .game-controls { padding: 0; }
.fc-drag-ghost { visibility: visible; }
/* 横向きの短い画面では共通操作を1行にまとめ、盤面の高さを確保する。 */
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    display: grid;
    grid-template-columns: 44px minmax(0, 432px) auto;
    justify-content: center;
    grid-template-rows: auto auto;
    align-content: start;
    align-items: center;
    gap: 6px 10px;
  }
  html.gs-playing .game-panel > .gs-bar { grid-area: 1 / 1; }
  html.gs-playing .fc-status { grid-area: 1 / 2; }
  html.gs-playing .game-controls {
    grid-area: 1 / 3;
    width: auto;
    flex-wrap: nowrap;
    gap: 6px;
  }
  html.gs-playing .fc-stage {
    grid-area: 2 / 1 / 3 / -1;
    justify-self: center;
  }
  html.gs-playing .fc-board { padding-block: 6px; }
  html.gs-playing .fc-top { margin-bottom: 8px; }
}
@media (min-width: 768px) and (min-height: 700px) {
  html.gs-playing .game-panel {
    padding-top: max(24px, env(safe-area-inset-top));
    gap: 20px;
  }
}
