/* ============================================================
   shared.css — 全ゲーム共通スタイル
   Sunmax warm game shell
   ============================================================ */

/* ---- Shared design tokens ---- */
:root {
  --md-primary:              #8f6300;
  --md-on-primary:           #fffaf0;
  --md-primary-container:    #fff0bf;
  --md-on-primary-container: #7d5a00;
  --md-secondary:            #d69c00;
  --md-on-secondary:         #2f260f;
  --md-secondary-container:  #fff4c2;
  --md-on-secondary-container: #6a4f05;
  --md-tertiary:             #7d5a00;
  --md-on-tertiary:          #fff7e1;
  --md-tertiary-container:   #f6e9b8;
  --md-on-tertiary-container: #5d4b1d;
  --md-surface:              #fff7dd;
  --md-on-surface:           #2f260f;
  --md-surface-variant:      #f6e9b8;
  --md-on-surface-variant:   #6a571f;
  --md-surface-container-lowest: #fffdf4;
  --md-surface-container-low: #fff9e6;
  --md-surface-container:    #fff2c8;
  --md-surface-container-high: #fffdf2;
  --md-surface-container-highest: #fffef9;
  --md-outline:              #d8bf63;
  --md-outline-variant:      #ead79c;
  --md-error:                #cf3f3f;
  --md-on-error:             #ffffff;
  --md-shape-xs:   4px;
  --md-shape-sm:   8px;
  --md-shape-md:   12px;
  --md-shape-lg:   16px;
  --md-shape-xl:   28px;
  --md-shape-full: 9999px;
  --md-elev-1: 0 8px 18px rgba(91, 69, 14, 0.10);
  --md-elev-2: 0 16px 30px rgba(91, 69, 14, 0.14);
  --md-elev-3: 0 28px 54px rgba(75, 55, 8, 0.18);
  --md-font: "Hiragino Sans", "Yu Gothic", "Meiryo", "Segoe UI", sans-serif;
  --md-state-hover:   0.08;
  --md-state-pressed: 0.12;
  --md-shell-border: rgba(184, 146, 33, 0.62);
  --nav-item-width: 13rem;
  --settings-card-width: min(560px, 100%);
  --settings-title-size: 2.25rem;
  --settings-title-margin: 36px;
  --game-shell-max-width: 1180px;
  --game-screen-width: min(1320px, calc(100vw - 32px));
  --game-screen-height: min(920px, calc(100dvh - 32px));
  --game-screen-min-height: 640px;
}

/* ---- リセット ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ---- ベーススタイル ---- */
body {
  font-family: var(--md-font);
  background:
    radial-gradient(circle at top left, rgba(240, 208, 64, 0.26), transparent 30%),
    radial-gradient(circle at top right, rgba(255, 234, 128, 0.24), transparent 24%),
    linear-gradient(180deg, #fbf2b8 0%, #f5e18d 100%);
  color: var(--md-on-surface);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), transparent 30%, transparent 70%, rgba(255, 255, 255, 0.10)),
    repeating-linear-gradient(
      0deg,
      rgba(139, 121, 94, 0.04) 0,
      rgba(139, 121, 94, 0.04) 1px,
      transparent 1px,
      transparent 22px
    );
}

.game-site-footer {
  width: min(calc(100% - 24px), var(--game-shell-max-width));
  margin: auto auto 24px;
  padding: 18px 20px;
  background:
    linear-gradient(135deg, rgba(255, 252, 240, 0.98), rgba(250, 235, 166, 0.96)),
    radial-gradient(circle at top right, rgba(240, 208, 64, 0.24), transparent 32%);
  border: 1px solid var(--md-shell-border);
  border-radius: 28px;
  box-shadow: var(--md-elev-2);
  text-align: center;
  color: #5d4b1d;
  font-size: 0.92rem;
}

.portfolio-nav {
  width: min(calc(100% - 24px), var(--game-shell-max-width));
  margin: clamp(18px, 3vw, 30px) auto 0;
  padding: clamp(16px, 2vw, 24px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
  position: relative;
  z-index: 1200;
  isolation: isolate;
  border: 1px solid var(--md-shell-border);
  border-radius: 36px;
  background:
    linear-gradient(135deg, rgba(255, 252, 240, 0.98), rgba(250, 235, 166, 0.96)),
    radial-gradient(circle at top right, rgba(240, 208, 64, 0.24), transparent 32%);
  box-shadow: var(--md-elev-3);
}

.portfolio-nav > a,
.portfolio-menu > summary {
  list-style: none;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 249, 227, 0.92);
  border: 1px solid rgba(184, 146, 33, 0.50);
  color: var(--md-on-surface);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.portfolio-nav > a:hover,
.portfolio-nav > a.active,
.portfolio-menu > summary:hover,
.portfolio-menu > summary.active,
.portfolio-menu[open] > summary {
  background: #ffffff;
  border-color: rgba(184, 146, 33, 0.62);
  box-shadow: var(--md-elev-1);
  transform: translateY(-2px);
}

.portfolio-menu {
  position: relative;
}

.portfolio-menu[open] {
  z-index: 1210;
}

.portfolio-menu > summary::-webkit-details-marker {
  display: none;
}

.portfolio-menu > summary::after {
  content: " +";
  color: var(--md-secondary);
  font-weight: 700;
}

.portfolio-menu[open] > summary::after {
  content: " -";
}

.portfolio-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: min(340px, calc(100vw - 48px));
  display: grid;
  gap: 0.5rem;
  background: rgba(255, 249, 228, 0.98);
  border: 1px solid var(--md-shell-border);
  border-radius: 24px;
  box-shadow: var(--md-elev-2);
  padding: 0.75rem;
  z-index: 1220;
}

.portfolio-dropdown a {
  display: block;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  text-decoration: none;
  color: var(--md-on-surface);
  font-weight: 600;
  background: linear-gradient(180deg, var(--md-surface), #fff0be);
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.portfolio-dropdown a:hover {
  background: #ffffff;
  color: var(--md-primary);
  transform: translateX(4px);
}

/* ---- ボタン (MD3 State Layer) ---- */
button {
  cursor: pointer;
  border: none;
  font-family: var(--md-font);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.006rem;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 200ms;
}
button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  border-radius: inherit;
  opacity: 0;
  transition: opacity 200ms;
  pointer-events: none;
}
button:hover::before  { opacity: var(--md-state-hover); }
button:active::before { opacity: var(--md-state-pressed); }

/* ---- スライダー (MD3 Slider) ---- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--md-primary-container);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--md-primary);
  transition: box-shadow 200ms;
}
input[type="range"]:hover::-webkit-slider-thumb  { box-shadow: 0 0 0 8px rgba(208,188,255,.12); }
input[type="range"]:active::-webkit-slider-thumb { box-shadow: 0 0 0 12px rgba(208,188,255,.12); }

/* ============================================================
   設定画面
   ============================================================ */
#settings-screen {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 0;
  padding: clamp(22px, 3vw, 36px) 16px clamp(32px, 4vw, 52px);
  background: transparent;
  overflow-y: auto;
}

.settings-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 253, 242, 0.98), rgba(255, 247, 221, 0.98)),
    radial-gradient(circle at top right, rgba(240, 208, 64, 0.18), transparent 30%);
  border: 1px solid var(--md-shell-border);
  border-radius: 28px;
  padding: 40px 44px;
  width: var(--settings-card-width);
  box-shadow: var(--md-elev-3);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

.settings-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 20px;
  border: 1px solid rgba(184, 146, 33, 0.22);
  pointer-events: none;
}

.settings-card h1 {
  text-align: center;
  font-size: var(--settings-title-size);
  font-weight: 700;
  margin-bottom: var(--settings-title-margin);
  color: var(--md-primary);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Times New Roman", serif;
  letter-spacing: -0.03em;
  position: relative;
}

.setting-group {
  margin-bottom: 28px;
  width: 100%;
}

.setting-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  margin-bottom: 12px;
}

.setting-group label span {
  color: var(--md-primary);
  font-weight: 700;
}

/* ---- スライダー行 ---- */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.slider-limit {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  min-width: 16px;
  text-align: center;
}

/* ---- 操作説明 ---- */
.how-to-play {
  width: 100%;
  padding: 16px;
  background: linear-gradient(180deg, var(--md-surface-container), #fff5d8);
  border-radius: 18px;
  font-size: 0.8rem;
  color: var(--md-on-surface-variant);
  line-height: 1.9;
  margin-bottom: 24px;
  border: 1px solid var(--md-outline-variant);
}
.how-to-play p { margin-bottom: 2px; }
.how-to-play p:last-child { margin-bottom: 0; }

/* ---- 難易度説明文 ---- */
.diff-desc {
  margin-top: 10px;
  min-height: 1.4em;
  font-size: 0.8rem;
  color: var(--md-on-surface-variant);
}

/* ---- モードトグル ---- */
.mode-toggle {
  display: flex;
  gap: 4px;
  background: linear-gradient(180deg, var(--md-surface-container), #fff7dc);
  border-radius: var(--md-shape-full);
  padding: 4px;
  width: 100%;
  border: 1px solid rgba(184, 146, 33, 0.22);
}

.mode-btn {
  flex: 1 1 0;
  padding: 8px 20px;
  border-radius: var(--md-shape-full);
  font-size: 0.875rem;
  font-weight: 500;
  background: transparent;
  color: var(--md-on-surface-variant);
  transition: background 200ms, color 200ms, box-shadow 200ms;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  box-shadow: var(--md-elev-1);
}

/* ---- 難易度ボタン ---- */
.diff-buttons { display: flex; gap: 8px; }

.diff-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: var(--md-shape-sm);
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--md-surface-container);
  color: var(--md-on-surface-variant);
  transition: background 200ms, color 200ms, box-shadow 200ms;
}

.diff-btn.active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  box-shadow: var(--md-elev-1);
}

/* ---- スタートボタン ---- */
#start-btn {
  width: 100%;
  padding: 14px 24px;
  margin-top: 8px;
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--md-primary), var(--md-secondary));
  color: var(--md-on-primary);
  border-radius: var(--md-shape-full);
  box-shadow: var(--md-elev-1);
  transition: box-shadow 200ms;
}
#start-btn:hover { box-shadow: var(--md-elev-2); }

/* ---- MD3 ボタンバリアント ---- */
.btn-filled {
  background: linear-gradient(135deg, var(--md-primary), var(--md-secondary));
  color: var(--md-on-primary);
  border-radius: var(--md-shape-full);
  padding: 10px 24px;
  box-shadow: var(--md-elev-1);
}
.btn-filled:hover { box-shadow: var(--md-elev-2); }

.btn-tonal {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-radius: var(--md-shape-full);
  padding: 10px 24px;
}
.btn-tonal:hover { box-shadow: var(--md-elev-1); }

.btn-outlined {
  background: transparent;
  color: var(--md-primary);
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-full);
  padding: 10px 24px;
}
.btn-outlined:hover { background: rgba(208,188,255,.08); }

/* ============================================================
   ゲーム画面
   ============================================================ */
#game-screen {
  display: none;
  position: relative;
  width: var(--game-screen-width);
  height: var(--game-screen-height);
  min-height: var(--game-screen-min-height);
  margin: clamp(18px, 3vw, 28px) auto;
  background:
    linear-gradient(180deg, #fffef7 0%, var(--md-surface-container-lowest) 100%),
    radial-gradient(circle at top right, rgba(240, 208, 64, 0.10), transparent 32%);
  border: 1px solid var(--md-shell-border);
  border-radius: 24px;
  box-shadow: var(--md-elev-3);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---- 上部固定HUDの共通形 ---- */
#hud {
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  z-index: 10;
  pointer-events: none;
  flex-wrap: wrap;
}

.hud-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 14px;
  z-index: 10;
  pointer-events: none;
  flex-wrap: wrap;
  background: transparent;
  border: 0;
  box-shadow: none;
}

#hud.hud-bar {
  top: 0;
  left: 0;
  right: 0;
  gap: 10px;
  padding: 12px 14px;
  background: transparent;
}

.hud-pill {
  background: var(--md-surface-container-high);
  color: var(--md-primary);
  padding: 8px 18px;
  border-radius: var(--md-shape-full);
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: var(--md-elev-2);
  text-align: center;
  white-space: nowrap;
}

.hud-pill-soft {
  background: var(--md-surface-container);
  color: var(--md-on-surface-variant);
  box-shadow: var(--md-elev-1);
}

.hud-button {
  pointer-events: all;
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-radius: var(--md-shape-full);
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--md-elev-1);
  white-space: nowrap;
}

.hud-button:hover {
  box-shadow: var(--md-elev-2);
}

.hud-meter {
  flex: 0 1 320px;
  width: min(320px, 100%);
  height: 6px;
  background: rgba(255, 249, 227, 0.82);
  border-radius: var(--md-shape-full);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(44, 44, 44, 0.08);
}

.hud-meter-fill {
  height: 100%;
  width: 0%;
  background: var(--md-primary);
  border-radius: var(--md-shape-full);
  transition: width 0.1s linear;
}

/* 共通バッジ */
:is(
  #score-display,
  #moves-display,
  #crowd-display,
  #gen-display,
  #pop-display,
  #mines-display,
  #timer-display
) {
  background: var(--md-surface-container-high);
  color: var(--md-primary);
  padding: 8px 18px;
  border-radius: var(--md-shape-full);
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: var(--md-elev-2);
  text-align: center;
}

#restart-btn {
  pointer-events: all;
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-radius: var(--md-shape-full);
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--md-elev-1);
}
#restart-btn:hover { box-shadow: var(--md-elev-2); }

/* ============================================================
   ゲームオーバー / 結果 オーバーレイ
   ============================================================ */
#game-over-overlay,
#result-overlay {
  display: none;
  position: absolute;
  inset: 0;
  justify-content: center;
  align-items: center;
  background: rgba(47, 38, 15, 0.58);
  backdrop-filter: blur(4px);
  z-index: 20;
  padding: 16px;
}

.game-over-card,
.result-card {
  background: linear-gradient(180deg, var(--md-surface-container-high), #fff7dd);
  border-radius: var(--md-shape-xl);
  padding: 40px 48px;
  text-align: center;
  box-shadow: var(--md-elev-3);
  width: min(420px, 100%);
  border: 1px solid var(--md-shell-border);
}

.game-over-card h2,
.result-card h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--md-primary);
}

.game-over-card p,
.result-card p {
  font-size: 0.875rem;
  color: var(--md-on-surface-variant);
  margin-bottom: 6px;
}

#final-score,
.score-big {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--md-primary);
  line-height: 1.2;
  margin-bottom: 4px;
}

.btn-group {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

#retry-btn {
  padding: 10px 24px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  border-radius: var(--md-shape-full);
  font-weight: 700;
  box-shadow: var(--md-elev-1);
}
#retry-btn:hover { box-shadow: var(--md-elev-2); }

#back-btn {
  padding: 10px 24px;
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-radius: var(--md-shape-full);
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (max-width: 600px) {
  .portfolio-nav {
    width: calc(100% - 16px);
    margin-top: 8px;
    padding: 12px;
    gap: 8px;
    border-radius: 24px;
  }

  .portfolio-nav > a,
  .portfolio-menu > summary {
    width: 100%;
    text-align: center;
  }

  .portfolio-dropdown {
    position: static;
    min-width: 0;
    margin-top: 0.5rem;
  }

  .game-site-footer {
    width: calc(100% - 16px);
    margin-bottom: 12px;
    padding: 14px 12px;
    font-size: 0.82rem;
    border-radius: 20px;
  }

  .settings-card { padding: 24px 18px; }
  .settings-card h1 { font-size: 1.6rem; margin-bottom: 20px; }
  .setting-group { margin-bottom: 18px; }
  .mode-btn { padding: 8px 10px; font-size: 0.8rem; }
  #hud {
    top: 8px;
    gap: 6px;
    padding: 0 10px;
  }
  .hud-bar {
    gap: 6px;
    padding: 8px 10px;
  }
  .hud-pill,
  .hud-button {
    font-size: 0.8rem;
    padding: 6px 10px;
  }
  .hud-meter {
    flex-basis: 220px;
    width: min(220px, 100%);
  }
  :is(
    #score-display,
    #moves-display,
    #crowd-display,
    #gen-display,
    #pop-display,
    #mines-display,
    #timer-display
  ) {
    font-size: 0.88rem;
    padding: 6px 12px;
    min-width: 0;
  }
  #game-screen {
    width: calc(100vw - 16px);
    height: min(calc(100dvh - 16px), 760px);
    min-height: 520px;
    margin: 8px auto;
    border-radius: 18px;
  }
}
