/* ============================================================
   カラーライン - Color Line  style.css
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg1: #0a0b14;
  --bg2: #1c2140;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #eef1fa;
  --text-dim: #96a0c2;
  --accent: #7cf0d8;
  --accent2: #ffd43b;
  --danger: #ff6b6b;
  --radius: 14px;
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background: radial-gradient(130% 90% at 50% 0%, var(--bg2) 0%, var(--bg1) 70%);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));   /* dvh 未対応ブラウザ向けフォールバック */
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 上のセーフエリアは共通ヘッダー（--sgh-top）が、広告があるときの下のセーフエリアは --ad-space が
     すでに取っているので、二重に空けない（ヘッダーが無いときだけ自分で空ける） */
  padding: max(0px, calc(env(safe-area-inset-top, 0px) - var(--sgh-top, 0px))) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
html.has-ad-banner #app { padding-bottom: 0; }

/* ---------- ヘッダー ---------- */
#topbar {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 4px;
}

#logo-wrap { display: flex; align-items: center; gap: 9px; min-width: 0; }

#logo {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(96deg, #ff8a8a 0%, #ffd43b 26%, #6ee7a8 52%, #6cc6ff 76%, #c79bff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

#mode-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent2);
  background: rgba(255, 212, 59, 0.12);
  border: 1px solid rgba(255, 212, 59, 0.35);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

#topbar-buttons { display: flex; gap: 8px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- 難易度バー ---------- */
#mode-bar {
  width: 100%;
  max-width: 420px;
  display: flex;
  gap: 6px;
  padding: 6px 14px 0;
}

.mode-btn {
  flex: 1;
  min-width: 0;
  padding: 8px 3px 7px;
  border-radius: 11px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text-dim);
  font-family: inherit;
  /* 4つ並べても狭い端末で溢れないように画面幅に追従させる */
  font-size: clamp(11px, 3.2vw, 13.5px);
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.mode-btn .mode-size {
  display: block;
  font-size: clamp(9px, 2.5vw, 10.5px);
  font-weight: 700;
  opacity: 0.75;
  font-family: "SF Mono", "Courier New", monospace;
}
.mode-btn.active {
  color: #08131a;
  background: linear-gradient(180deg, #9df5e2, #46c9b0);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 14px rgba(124, 240, 216, 0.28);
}
.mode-btn:active { transform: scale(0.97); }

/* ---------- ステータスバー ---------- */
#status-bar {
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 7px 14px 0;
}

.status-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 8px;
  min-width: 0;
  color: var(--text);
  font-family: inherit;
}

.status-box-btn { cursor: pointer; }
.status-box-btn:active { transform: scale(0.96); }

.status-icon { font-size: 13px; }

.status-value {
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 17px;
  font-weight: 700;
  color: #e4ecff;
  text-align: center;
  white-space: nowrap;
}

.status-sub {
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
}

#time-value { min-width: 3.6ch; }

.status-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 46px;
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
.status-btn:active { transform: scale(0.95); }
.status-btn:disabled { opacity: 0.35; cursor: default; }
#hint-count { font-family: "SF Mono", "Courier New", monospace; font-size: 12px; }

/* ---------- 進捗バー ---------- */
#progress-wrap {
  position: relative;
  width: calc(100% - 28px);
  max-width: 412px;
  height: 20px;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

#progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(124, 240, 216, 0.5), rgba(255, 212, 59, 0.65));
  transition: width 0.2s ease-out;
}

#progress-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #eaf1ff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
}

/* ---------- 盤面 ---------- */
#board-wrap {
  position: relative;
  width: 100%;
  max-width: 640px;
  flex: 1;
  min-height: 0;
  padding: 8px 6px 8px;
}

/* 盤面の余白は layout()（js/game.js）が入れ物の padding 込みの大きさから取るので、
   canvas も padding 込みの領域にぴったり重ねる（padding の内側に置くと右と下へはみ出す） */
#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
  border-radius: 16px;
  outline: none;
}
#board:focus-visible { box-shadow: 0 0 0 2px rgba(255, 212, 59, 0.7); }

/* ---------- 結果オーバーレイ ---------- */
#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 18, 0.76);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fadein 0.25s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#result-box {
  width: min(92vw, 360px);
  background: linear-gradient(180deg, #262d55, #131734);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  animation: rise 0.3s ease-out;
}
@keyframes rise {
  from { transform: translateY(24px) scale(0.95); opacity: 0; }
  to { transform: none; opacity: 1; }
}

#result-icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 8px;
  animation: bounce 0.5s ease-out;
}
@keyframes bounce {
  0% { transform: scale(0.3); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

#result-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #ffeeb0, #ffbc48);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#result-mode {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}

#result-time {
  margin-top: 10px;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  color: #eef7ff;
  text-shadow: 0 0 18px rgba(124, 240, 216, 0.45);
}

#result-sub {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}

#result-record {
  margin-top: 12px;
  display: inline-block;
  font-size: 13px;
  font-weight: 900;
  color: #4a3200;
  background: linear-gradient(180deg, #ffe08a, #ffb648);
  border-radius: 999px;
  padding: 5px 14px;
  animation: bounce 0.5s ease-out 0.15s backwards;
}

#result-best {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent2);
}

#result-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- ボタン共通 ---------- */
.btn {
  padding: 13px 18px;
  border-radius: 12px;
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(180deg, #8ff0dc, #35b9a0);
  color: #05221c;
  box-shadow: 0 6px 18px rgba(124, 240, 216, 0.3);
}

.btn-sub {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
}
.btn-sub.danger {
  background: rgba(255, 107, 107, 0.16);
  border-color: rgba(255, 107, 107, 0.45);
  color: #ffb3b3;
}

/* ---------- モーダル ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 18, 0.76);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 12px;
  animation: fadein 0.2s ease-out;
}

.modal-box {
  width: min(92vw, 400px);
  max-height: 86vh;   /* dvh 未対応ブラウザ向けフォールバック */
  max-height: 86dvh;
  overflow-y: auto;
  background: linear-gradient(180deg, #262d55, #131734);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-title {
  font-size: 20px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 6px;
}

.modal-sub {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 14px;
}

.menu-section { margin-bottom: 18px; }

.menu-caption {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 2px;
  font-size: 14px;
  font-weight: 600;
}
.menu-row small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-top: 2px;
}

.toggle {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.1);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle.on .knob { transform: translateX(20px); }

.record-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 2px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}
.record-row span:last-child {
  font-weight: 800;
  color: var(--accent2);
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 13px;
}

#btn-reset {
  width: 100%;
  margin-top: 12px;
  font-size: 13px;
  padding: 10px 14px;
}

.howto {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: #ccd6ee;
}
.howto li { padding-left: 1.1em; position: relative; }
.howto li::before { content: "•"; position: absolute; left: 0; color: var(--accent); }

#btn-close-menu, #btn-close-stages { width: 100%; }

/* ---------- ステージ選択 ---------- */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 7px;
  margin-bottom: 16px;
}

.stage-cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.stage-cell:active { transform: scale(0.94); }
.stage-cell.done {
  background: linear-gradient(180deg, rgba(124, 240, 216, 0.28), rgba(53, 185, 160, 0.2));
  border-color: rgba(124, 240, 216, 0.55);
  color: #d9fff5;
}
.stage-cell.locked {
  opacity: 0.32;
  cursor: default;
}
.stage-cell.current {
  outline: 2px solid var(--accent2);
  outline-offset: -2px;
}

/* ---------- トースト ---------- */
#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(80px + env(safe-area-inset-bottom) + var(--ad-space, 0px));
  transform: translateX(-50%);
  background: rgba(22, 26, 48, 0.95);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 70;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastin 0.25s ease-out;
}
@keyframes toastin {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- 紙吹雪 ---------- */
.confetti {
  position: fixed;
  top: -12px;
  width: 9px;
  height: 14px;
  z-index: 55;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to {
    transform: translateY(105vh) rotate(720deg);   /* dvh 未対応ブラウザ向けフォールバック */
    transform: translateY(105dvh) rotate(720deg);
    opacity: 0.7;
  }
}

/* ---------- フッター ---------- */
#footer {
  padding: 6px 0 12px;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.7;
}
#footer a { color: var(--text-dim); }

/* ---------- 汎用 ---------- */
.hidden { display: none !important; }

/* ---------- レスポンシブ ---------- */
@media (min-width: 700px) {
  #logo { font-size: 22px; }
  #mode-bar { max-width: 460px; }
  #status-bar { max-width: 480px; }
  #progress-wrap { max-width: 452px; }
}

@media (prefers-reduced-motion: reduce) {
  #result-overlay, #result-box, #result-icon, #result-record, .modal, #toast { animation: none; }
  #progress-fill { transition: none; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden {
  display: none !important;
}

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000; /* 既存モーダル(60)・トースト(70)・広告バナー(2147482000)より上 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 8, 18, 0.76);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #262d55, #131734);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.sgr-tabs {
  display: flex;
  flex-wrap: wrap;   /* 難易度4つでも狭い端末で溢れないように */
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.sgr-tab-active {
  background: rgba(124, 240, 216, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 800;
  color: var(--accent2);
  text-align: center;
}

.sgr-form {
  display: flex;
  gap: 8px;
}

.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

.sgr-name:focus {
  outline: none;
  border-color: var(--accent);
}

.sgr-submit {
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #8ff0dc, #35b9a0);
  color: #05221c;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(124, 240, 216, 0.3);
}

.sgr-submit:hover {
  filter: brightness(1.08);
}

.sgr-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 14px;
}

.sgr-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.05);
}

.sgr-row.sgr-row-me {
  background: rgba(124, 240, 216, 0.25);
  color: #fff;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: 800;
  flex-shrink: 0;
}

.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sgr-row-score {
  font-weight: 800;
  color: var(--accent2);
  flex-shrink: 0;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 12px;
}

.sgr-row.sgr-row-me .sgr-row-score {
  color: #fff;
}

.sgr-close {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.sgr-close:active { transform: scale(0.97); }

.sgr-cta {
  margin: 0 0 14px;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 800;
  color: var(--accent2);
}

.sgr-cta-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffe08a, #ffb648);
  color: #4a3200;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 212, 59, 0.35);
}
.sgr-cta-btn:active { transform: scale(0.97); }

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
