/* ライトアウトパズル固有スタイル */

.lo-settings {
  max-width: min(100%, 520px);
  margin: 4px auto 14px;
  text-align: center;
}

.lo-settings .field-label {
  margin-bottom: 8px;
}

.option-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.option-tab {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 8px 6px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.04s ease;
}

.option-tab small {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.75;
}

.option-tab:hover {
  background: var(--md-sys-color-primary-container);
}

.option-tab:active {
  transform: translateY(1px);
}

.option-tab.is-active {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.option-tab:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--md-sys-color-primary) 70%, white);
  outline-offset: 2px;
}

.game-panel {
  margin-top: 20px;
}

.lo-stage {
  position: relative;
  width: 100%;
}

.lo-result {
  position: absolute;
  inset: 0;
  z-index: 2;
  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: lo-result-in 180ms ease-out;
}

.lo-result__title {
  margin: 0;
  color: #a8f0ff;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: clamp(1.5rem, 7vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 0 18px rgba(96, 220, 255, 0.7), 0 0 34px rgba(150, 106, 255, 0.45);
}

.lo-result__detail {
  margin: 0;
  color: rgba(230, 240, 255, 0.86);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.lo-result__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.lo-result__actions .btn {
  min-width: 8.5rem;
  justify-content: center;
}

@keyframes lo-result-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ベスト更新表示は既存の記録判定を使う。 */
.lo-result__best { margin: 0; color: #cdaaff; font-weight: 700; }

.lo-board-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: min(100%, 440px);
  margin: 0 auto 10px;
}

.lo-board {
  --lo-size: 3;
  --lo-gap: clamp(8px, 2.2vw, 14px);
  display: grid;
  grid-template-columns: repeat(var(--lo-size), minmax(0, 1fr));
  gap: var(--lo-gap);
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: var(--lo-gap);
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(circle at 18% 0%, rgba(63, 196, 255, 0.16), transparent 62%),
    radial-gradient(circle at 86% 100%, rgba(150, 106, 255, 0.14), transparent 60%),
    linear-gradient(160deg, #16264a 0%, #101c38 55%, #0d1730 100%);
  box-shadow: 0 14px 34px rgba(28, 52, 96, 0.24), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  user-select: none;
  -webkit-user-select: none;
}

.lo-cell {
  position: relative;
  appearance: none;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid rgba(120, 160, 210, 0.28);
  border-radius: clamp(8px, 2vw, 12px);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.05), transparent 55%),
    #0d1832;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    transform 80ms ease;
}

.lo-cell__core,
.lo-cell__ring,
.lo-cell__dot {
  position: absolute;
  inset: 0;
  margin: auto;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.lo-cell__core {
  width: 62%;
  height: 62%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  opacity: 0.55;
}

.lo-cell__ring {
  width: 74%;
  height: 74%;
  border-radius: 50%;
  border: 2px solid transparent;
  opacity: 0;
}

.lo-cell__dot {
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: rgba(180, 210, 245, 0.22);
  opacity: 0.35;
}

.lo-cell.is-on {
  border-color: rgba(100, 220, 255, 0.75);
  background:
    radial-gradient(circle at 50% 42%, rgba(180, 245, 255, 0.55), transparent 42%),
    linear-gradient(160deg, #3fc4ff 0%, #2aa8e8 45%, #1f7fd0 100%);
  box-shadow:
    0 0 14px rgba(63, 196, 255, 0.45),
    0 0 28px rgba(63, 196, 255, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.lo-cell.is-on .lo-cell__core {
  background: radial-gradient(circle at 40% 30%, #e9fbff, #7adfff 55%, #2bb4ea);
  opacity: 1;
  box-shadow: 0 0 12px rgba(180, 245, 255, 0.55);
}

.lo-cell.is-on .lo-cell__ring {
  border-color: rgba(255, 255, 255, 0.55);
  opacity: 1;
  box-shadow: 0 0 10px rgba(120, 230, 255, 0.35);
}

.lo-cell.is-on .lo-cell__dot {
  background: #ffffff;
  opacity: 0.95;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

.lo-cell.is-off .lo-cell__ring {
  opacity: 0;
}

.lo-cell:hover:not(:disabled) {
  border-color: rgba(160, 210, 255, 0.55);
  box-shadow: 0 0 12px rgba(90, 180, 255, 0.18);
}

.lo-cell.is-on:hover:not(:disabled) {
  box-shadow:
    0 0 16px rgba(63, 196, 255, 0.55),
    0 0 30px rgba(63, 196, 255, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}

.lo-cell:active:not(:disabled) {
  transform: scale(0.96);
}

.lo-cell:focus-visible {
  outline: 3px solid rgba(64, 200, 255, 0.9);
  outline-offset: 2px;
}

.lo-cell:disabled {
  cursor: default;
}

.lo-guide {
  max-width: min(100%, 480px);
  margin: 0 auto 14px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.875rem;
  line-height: 1.6;
  text-align: center;
}

@media (max-width: 480px) {
  .option-tabs {
    gap: 8px;
  }

  .option-tab {
    min-height: 44px;
    padding: 7px 4px;
    font-size: 0.8rem;
  }

  .lo-board-wrap {
    max-width: min(100%, 360px);
  }

  .lo-result__actions .btn {
    min-width: 0;
    flex: 1 1 calc(50% - 4px);
  }
}

/* 共通テーマとパイプパズルの配置を踏襲。盤面は少数マスのため最大440px。 */
html.gs-playing .game-panel {
  --lo-chrome: 212px;
  display: grid;
  grid-template-columns: 44px minmax(0, 586px);
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    "bar settings"
    "status status"
    "board board"
    "controls controls";
  column-gap: 10px;
  justify-content: center;
  align-content: start;
}

html.gs-playing .game-panel > .gs-bar {
  grid-area: bar;
}

html.gs-playing .lo-settings {
  grid-area: settings;
  justify-self: stretch;
  width: 100%;
  max-width: none;
  margin: 0 0 10px;
}

html.gs-playing .lo-settings .field-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html.gs-playing .option-tabs {
  gap: 6px;
}

html.gs-playing .option-tab {
  flex-direction: column;
  gap: 0;
  min-height: 44px;
  padding: 4px 6px;
  border-color: var(--play-border);
  background: var(--play-hud-bg);
  color: var(--play-text);
  font-size: .8125rem;
}

html.gs-playing .option-tab small {
  font-size: .6875rem;
}

@media (hover: hover) {
  html.gs-playing .option-tab:hover {
    border-color: color-mix(in srgb, var(--play-accent) 55%, var(--play-border));
    background: var(--play-btn-hover);
  }
}

html.gs-playing .option-tab.is-active {
  border-color: var(--play-accent);
  background: color-mix(in srgb, var(--play-accent) 18%, var(--play-hud-bg));
  color: var(--play-accent);
}

html.gs-playing .option-tab:focus-visible {
  outline: 2px solid var(--play-accent);
  outline-offset: 2px;
}

html.gs-playing .gs-hud { grid-area: status; justify-self: center; margin: 0 0 10px; }

html.gs-playing .lo-result__actions .btn--secondary {
  border: 1px solid var(--play-border);
  background: var(--play-bg);
  color: var(--play-text);
  box-shadow: none;
}

@media (hover: hover) {
  html.gs-playing .lo-result__actions .btn--secondary:hover {
    border-color: color-mix(in srgb, var(--play-accent) 55%, var(--play-border));
    background: var(--play-btn-hover);
    color: var(--play-accent);
  }
}

html.gs-playing .lo-board-wrap {
  grid-area: board;
  justify-self: center;
  width: 100%;
  max-width: none;
  margin: 0 0 10px;
  container-type: inline-size;
}

html.gs-playing .lo-stage {
  width: auto;
}

html.gs-playing .lo-board {
  --lo-board-size: min(100cqw, max(160px, min(100vh - var(--lo-chrome), 440px)));
  --lo-board-size: min(100cqw, max(160px, min(100dvh - var(--lo-chrome), 440px)));
  width: var(--lo-board-size);
  border-color: var(--play-border);
  box-shadow: 0 16px 38px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* 操作説明は盤面の読み上げ用に残す。 */

html.gs-playing .lo-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html.gs-playing .game-panel .game-controls {
  grid-area: controls;
  justify-content: center;
  gap: 12px;
  margin: 0;
}

/* PCは最大640pxを基準にし、盤面は高さにも収める。 */
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .game-panel {
    --lo-chrome: 300px;
    grid-template-columns: 44px minmax(0, 586px);
    padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top));
  }

  html.gs-playing .game-panel > .gs-bar,
  html.gs-playing .lo-settings {
    margin-bottom: 28px;
  }

  html.gs-playing .gs-hud,
  html.gs-playing .lo-board-wrap,
  html.gs-playing .game-panel .game-controls {
    max-width: 640px;
  }

  html.gs-playing .gs-hud,
  html.gs-playing .lo-board-wrap {
    margin-bottom: 24px;
  }
}

/* スマートフォン横向きなど高さが足りない画面では、戻る・操作・難易度・情報を左、盤面を右に並べる */
/* 操作ボタンは戻るボタンと同じ行の右端に置き、左列の高さを抑える */
@media (orientation: landscape) and (max-height: 500px) {
  html.gs-playing .game-panel {
    grid-template-columns: minmax(200px, 280px) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "bar board"
      "settings board"
      "status board"
      ". board";
    column-gap: 16px;
  }

  html.gs-playing .game-panel > .gs-bar {
    justify-self: start;
  }

  html.gs-playing .lo-settings {
    justify-self: stretch;
    width: 100%;
  }

  html.gs-playing .game-panel .game-controls {
    grid-area: bar;
    justify-self: end;
    width: auto;
    margin-bottom: 10px;
  }

  html.gs-playing .lo-board-wrap {
    align-items: center;
    min-height: 0;
    margin: 0;
    container-type: size;
  }

  html.gs-playing .lo-board {
    --lo-board-size: min(100cqw, 100cqh, 440px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lo-cell, .lo-cell__core, .lo-cell__ring, .lo-cell__dot { transition: none; }
  .lo-result { animation: none; }
}

@media (max-width: 360px) {
  html.gs-playing .option-tab { padding-inline: 2px; font-size: .75rem; }
}
