/* スナリス - Sunaris */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --c-sand: #f6c445;
  --c-red: #f0605a;
  --c-blue: #4aa8f0;
  --c-green: #63c96a;
  --bg-panel: rgba(255, 255, 255, 0.07);
  --bg-panel-border: rgba(255, 255, 255, 0.13);
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(165deg, #2a2440 0%, #1b1a33 45%, #121226 100%);
  color: #f4f2ec;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ---------- 汎用 ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  color: #fff;
  transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(180deg, #f7c948, #e09a1a);
  color: #3a2a08;
  box-shadow: 0 4px 14px rgba(224, 154, 26, 0.4);
  padding: 12px 28px;
  font-size: 16px;
}
.btn-sub {
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  color: #d8d4c8;
  padding: 10px 22px;
  font-size: 14px;
}
.btn-big {
  width: 100%;
  padding: 15px 20px;
  font-size: 18px;
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  color: #fff;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  line-height: 1;
}

/* ---------- 画面共通 ---------- */
.screen {
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- タイトル画面 ---------- */
#screen-title {
  justify-content: center;
  padding: 24px 16px calc(16px + env(safe-area-inset-bottom));
}
.title-inner {
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.title-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}
#logo-canvas {
  width: 240px;
  height: 120px;
  image-rendering: pixelated;
}
.title-jp {
  font-size: 42px;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, #ffe9a8 20%, #f6c445 55%, #d98a1f 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 3px 18px rgba(246, 196, 69, 0.25);
}
.title-en {
  font-size: 14px;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  color: #b8b09a;
  margin-top: 2px;
}
.title-desc {
  margin: 18px 0 22px;
  font-size: 14px;
  line-height: 1.9;
  color: #d8d4c8;
}
.menu-panel {
  max-width: 300px;
  margin: 0 auto;
}
.menu-panel .btn + .btn {
  margin-top: 12px;
}
.title-highscore {
  margin-top: 14px;
  font-size: 13px;
  color: #b8b09a;
}
.title-highscore span {
  color: var(--c-sand);
  font-size: 16px;
  font-weight: 700;
  margin-left: 4px;
}

.howto {
  margin: 26px auto 0;
  max-width: 360px;
  text-align: left;
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
}
.howto summary {
  cursor: pointer;
  font-weight: 700;
  color: #eee8d8;
}
.howto ul {
  margin: 10px 0 4px;
  padding-left: 18px;
  color: #cfcabc;
  line-height: 1.8;
}
.howto li { margin-bottom: 6px; }
.howto strong { color: var(--c-sand); }

.title-footer {
  margin-top: 34px;
  font-size: 11px;
  color: #8f8a7c;
  line-height: 1.9;
}
.title-footer a {
  color: #b0aa98;
  text-decoration: none;
}
.title-footer a:hover { text-decoration: underline; }

/* ---------- ゲーム画面 ---------- */
#screen-game {
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  overflow: hidden;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.game-header {
  width: 100%;
  max-width: 460px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}
.game-header-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.15em;
  color: #eee8d8;
}
.game-header-right {
  display: flex;
  gap: 8px;
}

.game-layout {
  width: 100%;
  max-width: 460px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.stats-bar {
  width: 100%;
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}
.stat {
  flex: 1 1 0;
  background: var(--bg-panel);
  border: 1px solid var(--bg-panel-border);
  border-radius: 10px;
  padding: 5px 8px 6px;
  text-align: center;
  min-width: 0;
}
.stat-label {
  font-size: 10px;
  color: #a29c8c;
  letter-spacing: 0.08em;
}
.stat-value {
  font-size: 17px;
  font-weight: 700;
  color: #ffe9a8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-next { flex: 0 0 auto; }
#next-canvas {
  width: 50px;
  height: 25px;
  image-rendering: pixelated;
  margin-top: 2px;
}

#board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  width: 100%;
}
#board {
  border: 2px solid rgba(246, 196, 69, 0.35);
  border-radius: 6px;
  background: #0c0c1a;
  box-shadow: 0 0 30px rgba(246, 196, 69, 0.08), inset 0 0 24px rgba(0, 0, 0, 0.6);
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#popup-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.score-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 8px rgba(246, 196, 69, 0.9), 0 2px 4px rgba(0, 0, 0, 0.6);
  animation: popup-rise 1.1s ease-out forwards;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.score-popup .combo {
  color: var(--c-sand);
  font-size: 0.75em;
  margin-left: 4px;
}
@keyframes popup-rise {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  30%  { transform: translate(-50%, -55%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
.level-popup {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #ffe9a8;
  text-shadow: 0 0 16px rgba(246, 196, 69, 0.9), 0 2px 6px rgba(0, 0, 0, 0.7);
  animation: level-flash 1.6s ease-out forwards;
  white-space: nowrap;
}
@keyframes level-flash {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  30%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* タッチ操作ボタン */
#touch-controls {
  width: 100%;
  max-width: 400px;
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}
.ctrl-btn {
  flex: 1 1 0;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--bg-panel-border);
  background: var(--bg-panel);
  color: #eee8d8;
  font-size: 20px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.ctrl-btn:active {
  background: rgba(246, 196, 69, 0.25);
  transform: scale(0.95);
}
.ctrl-btn-main {
  background: linear-gradient(180deg, rgba(247, 201, 72, 0.35), rgba(224, 154, 26, 0.25));
  border-color: rgba(246, 196, 69, 0.4);
}

@media (min-width: 700px) and (pointer: fine) {
  #touch-controls { display: none; }
}

/* ---------- オーバーレイ・モーダル ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 22, 0.78);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-box {
  background: linear-gradient(165deg, #2e2947 0%, #201d38 100%);
  border: 1px solid var(--bg-panel-border);
  border-radius: 16px;
  padding: 26px 28px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.modal-box p {
  font-size: 15px;
  line-height: 1.8;
  margin-bottom: 18px;
}
.pause-title {
  font-weight: 700;
  font-size: 18px;
}
.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.result-newrecord {
  color: var(--c-sand);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  animation: newrecord-blink 1s ease-in-out infinite alternate;
}
@keyframes newrecord-blink {
  from { opacity: 1; }
  to   { opacity: 0.55; }
}
.result-score-label {
  font-size: 12px;
  color: #a29c8c;
  margin-top: 8px;
}
.result-score {
  font-size: 40px;
  font-weight: 800;
  color: #ffe9a8;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 10px;
}
.result-detail {
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 13px;
  color: #cfcabc;
  margin-bottom: 20px;
}
.result-detail b { color: #ffe9a8; }

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

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(10, 10, 22, 0.78);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(165deg, #2e2947 0%, #201d38 100%);
  color: #f4f2ec;
  border: 1px solid var(--bg-panel-border);
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

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

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: 1px solid var(--bg-panel-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg-panel);
  color: #f4f2ec;
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(180deg, #f7c948, #e09a1a);
  border-color: transparent;
  color: #3a2a08;
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 8px 10px;
  border: 2px solid var(--bg-panel-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: #f4f2ec;
}

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

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(180deg, #f7c948, #e09a1a);
  color: #3a2a08;
  cursor: pointer;
}

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

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

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--c-red);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: #cfcabc;
}

.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: 6px;
  font-size: 14px;
}

.sgr-row:nth-child(even) {
  background: var(--bg-panel);
}

.sgr-row.sgr-row-me {
  background: linear-gradient(180deg, #f7c948, #e09a1a);
  color: #3a2a08;
}

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


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

.sgr-row-score {
  font-weight: 700;
  flex-shrink: 0;
  color: #ffe9a8;
}

.sgr-row.sgr-row-me .sgr-row-score {
  color: inherit;
}

.sgr-close {
  border: 1px solid var(--bg-panel-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg-panel);
  color: #d8d4c8;
  cursor: pointer;
}

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

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

.sgr-cta-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(180deg, #f7c948, #e09a1a);
  color: #3a2a08;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(224, 154, 26, 0.4);
}

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-size: 13px;
  color: inherit;
  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; }
}
