/* main.css - ゲーム用スタイル */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

html,
body {
  height: 100%;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

#albumModal {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 18px;
  padding: 32px 40px 28px;
  position: relative;
  width: min(92vw, 700px);
  max-height: min(92dvh, 720px);
  overflow: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

#albumModal.detail-mode {
  width: min(90vw, 560px);
  padding: 24px 24px 20px;
}

#albumModal h2 {
  font-size: clamp(18px, 2.5vw, 26px);
  font-weight: 700;
  letter-spacing: .05em;
  text-align: center;
  margin-bottom: 6px;
}

#albumSubtitle {
  font-size: clamp(11px, 1.2vw, 13px);
  color: #64748b;
  text-align: center;
  margin-bottom: 24px;
}

#albumFrames {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

#albumFrames.hidden {
  display: none;
}

.frame {
  width: 100%;
  height: clamp(90px, 13vh, 120px);
  border-radius: 10px;
  border: 1px solid #334155;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
  transition: transform .15s, border-color .15s;
}

.frame.empty-waypoint {
  border: 1.5px dashed #334155;
  cursor: default;
  background: #0f172a;
}

.frame.filled-waypoint {
  border: 1.5px solid #6366f1;
}

.frame.empty-goal {
  border: 2.5px dashed #f59e0b;
  cursor: default;
  background: #0f172a;
}

.frame.filled-goal {
  border: 2.5px solid #f59e0b;
}

.frame:hover:not(.is-locked) {
  transform: translateY(-2px);
}

.frame.is-selected {
  border-color: #f8fafc;
}

.frame.is-locked {
  opacity: 0.5;
}

.frame-fallback {
  font-size: clamp(26px, 5vw, 44px);
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
}

.frame-lock {
  position: absolute;
  inset: auto 8px 8px auto;
  font-size: 18px;
  opacity: 0.75;
}

.frame-icon {
  font-size: clamp(18px, 2.5vw, 26px);
}

.frame-title {
  font-weight: 700;
}

.frame-story {
  font-size: clamp(9px, 1vw, 11px);
  line-height: 1.45;
  opacity: 0.9;
}

#spotDetail.hidden {
  display: none;
}

#spotDetailBack {
  border: 1px solid #475569;
  background: #0f172a;
  color: #cbd5e1;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 12px;
}

#spotDetailImage {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  font-size: clamp(42px, 8vw, 86px);
  margin-bottom: 12px;
}

#spotDetailName {
  font-size: clamp(16px, 2vw, 22px);
  color: #f8fafc;
  margin-bottom: 8px;
}

#spotDetailStory {
  color: #cbd5e1;
  line-height: 1.7;
  font-size: clamp(12px, 1.4vw, 15px);
  max-height: min(28vh, 220px);
  overflow-y: auto;
  padding-right: 4px;
}

#albumClose {
  display: block;
  margin: 0 auto;
  padding: 9px 36px;
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 600;
  transition: background .2s;
}

#albumClose:hover {
  background: #4f46e5;
}

.modal-x {
  position: absolute;
  top: 14px;
  right: 18px;
  background: none;
  border: none;
  color: #475569;
  font-size: 20px;
  cursor: pointer;
  transition: color .15s;
}

.modal-x:hover {
  color: #e2e8f0;
}

#game {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  gap: 10px;
}

#hudPanel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(36vw, 260px);
}

#btnAlbum {
  padding: 7px 16px;
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: clamp(11px, 1.4vw, 14px);
  font-weight: 600;
  transition: background .2s;
}

#btnLang {
  padding: 7px 12px;
  background: #0f766e;
  color: #f0fdfa;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: clamp(11px, 1.3vw, 14px);
  font-weight: 700;
  transition: background .2s;
}

#btnLang:hover {
  background: #0d9488;
}

#btnAlbum:hover {
  background: #4f46e5;
}

#btnAlbum.is-spotlist-hint {
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.45), 0 0 16px rgba(129, 140, 248, 0.45);
  animation: spotlistHintPulse 1.8s ease-in-out infinite;
}

@keyframes spotlistHintPulse {
  0% {
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.25), 0 0 8px rgba(129, 140, 248, 0.25);
  }

  50% {
    box-shadow: 0 0 0 3px rgba(165, 180, 252, 0.65), 0 0 20px rgba(129, 140, 248, 0.55);
  }

  100% {
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.25), 0 0 8px rgba(129, 140, 248, 0.25);
  }
}

#distInfo {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: clamp(11px, 1.3vw, 14px);
  color: #64748b;
  text-align: left;
  line-height: 1.8;
}

#distInfo span {
  color: #a5b4fc;
  font-weight: 600;
}

#sceneWrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#sceneLayout {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

#scene {
  aspect-ratio: 16/9;
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: min(100%, calc((100dvh - 180px) * 16 / 9));
  max-height: 100%;
  border-radius: 14px;
  border: 1px solid #334155;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

#sceneBg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(60px, 10vw, 120px);
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  background-size: cover;
  background-repeat: no-repeat !important;
  background-position: center;
  transition: background 0.6s;
}

#storyBox {
  position: relative;
  z-index: 2;
  width: 100%;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(4px);
  padding: clamp(8px, 1.5vh, 14px) clamp(12px, 2vw, 20px);
  font-size: clamp(10px, 1.3vw, 14px);
  color: #cbd5e1;
  line-height: 1.7;
  border-top: 1px solid #1e293b;
}

#storyName {
  font-size: clamp(11px, 1.4vw, 15px);
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 3px;
}

#spotBadge {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 3;
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: clamp(9px, 1vw, 12px);
  font-weight: 700;
  opacity: 0;
  transition: opacity .4s;
}

#controls {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.arrow-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
}

.arrow {
  width: clamp(36px, 5vw, 54px);
  height: clamp(36px, 5vw, 54px);
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 10px;
  cursor: pointer;
  font-size: clamp(16px, 2vw, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}

.arrow:hover:not(:disabled) {
  background: #6366f1;
  border-color: #6366f1;
}

.arrow:active:not(:disabled) {
  background: #4f46e5;
}

.arrow:disabled {
  opacity: .25;
  cursor: default;
}

.arrow.placeholder {
  visibility: hidden;
}

#minimap {
  --mini-cell-size: 18px;
  display: grid;
  gap: 3px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 8px;
  backdrop-filter: blur(4px);
}

.mCell {
  width: var(--mini-cell-size);
  height: var(--mini-cell-size);
  border-radius: 3px;
  border: 1px solid #1e293b;
  background: #1e293b;
  transition: background .3s, border-color .3s, box-shadow .3s;
}

.mCell.road {
  border-color: #334155;
}

.mCell.spot {
  border-color: #64748b;
}

.mCell.unknown {
  background: #1e293b;
  border-color: #1e293b;
}

.mCell.road.unknown {
  background: #1e293b;
  border-color: #1e293b;
}

.mCell.spot.unknown {
  background: #1e293b;
  border-color: #1e293b;
}

.mCell.blocked {
  background: #0b1220;
  border-color: #1f2937;
}

.mCell.movable {
  background: #064e3b;
  border-color: #10b981;
}

.mCell.visited {
  background: #334155;
  border-color: #475569;
}

.mCell.current {
  background: #6366f1;
  border-color: #818cf8;
  box-shadow: 0 0 6px #6366f1;
}

#btnGoalConfirm {
  padding: 7px 14px;
  background: #334155;
  color: #cbd5e1;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: none;
  transition: background .2s;
}

#btnGoalConfirm:hover {
  background: #475569;
}

#btnGoalConfirm.is-goal-ready {
  background: #f59e0b;
  color: #0f172a;
}

#btnGoalConfirm.is-goal-ready:hover {
  background: #d97706;
}

#restartModal {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 18px;
  padding: 28px 24px;
  width: min(90vw, 420px);
  max-height: min(90dvh, 420px);
  overflow: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  text-align: center;
}

#restartModal h2 {
  font-size: clamp(17px, 2.3vw, 24px);
  margin-bottom: 10px;
  color: #f8fafc;
}

#restartModal p {
  color: #cbd5e1;
  margin-bottom: 18px;
}

#restartActions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#restartCancel,
#restartOk {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}

#restartCancel {
  background: #334155;
  color: #e2e8f0;
}

#restartOk {
  background: #f59e0b;
  color: #0f172a;
}

@media (orientation: portrait) {
  #game {
    gap: 8px;
  }

  #sceneLayout {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #scene {
    width: 100%;
    max-width: 100%;
    max-height: min(58dvh, 430px);
  }

  #hudPanel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  #minimap {
    --mini-cell-size: 16px;
    gap: 2px;
    padding: 7px;
  }

  #distInfo {
    flex: 1 1 150px;
    text-align: left;
    line-height: 1.6;
  }

  #btnAlbum,
  #btnLang,
  #btnGoalConfirm {
    flex: 1 1 calc(50% - 6px);
    min-height: 36px;
  }

  #controls {
    width: 100%;
    justify-content: center;
  }

  #controls {
    gap: 8px;
  }

  .arrow {
    width: clamp(36px, 11vw, 58px);
    height: clamp(36px, 11vw, 58px);
    font-size: clamp(16px, 5.2vw, 28px);
  }
}

@media (orientation: portrait) and (max-width: 430px) {
  #game {
    padding: 8px;
    gap: 6px;
  }

  #scene {
    max-height: min(54dvh, 380px);
    border-radius: 10px;
  }

  #sceneBg {
    font-size: clamp(36px, 16vw, 84px);
  }

  #storyBox {
    padding: 7px 10px;
    line-height: 1.45;
    font-size: clamp(10px, 3.1vw, 12px);
  }

  #storyName {
    font-size: clamp(11px, 3.4vw, 13px);
    margin-bottom: 2px;
  }

  #minimap {
    --mini-cell-size: 12px;
    padding: 6px;
  }

  #distInfo {
    font-size: 11px;
    padding: 6px 8px;
    line-height: 1.45;
  }

  #btnAlbum,
  #btnLang,
  #btnGoalConfirm {
    font-size: 11px;
    padding: 6px 8px;
    min-height: 34px;
  }

  .arrow-grid {
    gap: 4px;
  }

  .arrow {
    width: clamp(30px, 10.5vw, 42px);
    height: clamp(30px, 10.5vw, 42px);
    font-size: clamp(14px, 4.6vw, 20px);
  }

  #spotBadge {
    top: 8px;
    right: 8px;
    padding: 3px 7px;
    font-size: 10px;
  }
}

@media (orientation: landscape) and (max-height: 430px) {
  #game {
    padding: 8px;
    gap: 6px;
  }

  #sceneLayout {
    gap: 8px;
    align-items: stretch;
  }

  #hudPanel {
    width: min(36vw, 190px);
    gap: 6px;
  }

  #minimap {
    --mini-cell-size: 13px;
    gap: 2px;
    padding: 6px;
  }

  #distInfo {
    padding: 6px 8px;
    line-height: 1.5;
    font-size: 11px;
  }

  #btnAlbum,
  #btnLang,
  #btnGoalConfirm {
    padding: 6px 10px;
    font-size: 11px;
  }

  #controls {
    gap: 8px;
  }

  .arrow-grid {
    gap: 4px;
  }

  .arrow {
    width: clamp(30px, 5.2vw, 38px);
    height: clamp(30px, 5.2vw, 38px);
    font-size: clamp(13px, 2.6vw, 18px);
  }

  #scene {
    border-radius: 10px;
    max-width: 100%;
  }

  #sceneBg {
    font-size: clamp(36px, 7vw, 78px);
  }

  #storyBox {
    padding: 6px 10px;
    font-size: clamp(10px, 1.7vw, 12px);
    line-height: 1.45;
  }

  #storyName {
    margin-bottom: 1px;
    font-size: clamp(10px, 1.8vw, 13px);
  }

  #spotBadge {
    top: 8px;
    right: 8px;
    padding: 3px 8px;
    font-size: 10px;
  }

  #albumModal,
  #restartModal {
    border-radius: 12px;
  }
}