/* ==========================================================================
   霊夢の妖魔避け - 和風スタイルシート (ランキング＆ポータル追加版)
   ========================================================================== */

:root {
  /* Traditional Japanese Colors (和色 - Washoku) */
  --color-sumi: 240 10% 6%;         /* 墨色 (Sumi-iro) - Ink Charcoal Black */
  --color-sumi-light: 240 8% 10%;
  --color-washi: 40 18% 95%;        /* 生成り色 (Kinari-iro) - Soft Washi Paper White */
  --color-washi-opaque: 40 18% 95% / 0.96;
  --color-shuu: 6 80% 50%;          /* 朱色 (Shuu-iro) - Safflower Vermilion Red */
  --color-shuu-glow: 6 80% 50% / 0.45;
  --color-gold: 42 65% 55%;         /* 金色 (Konjiki) - Traditional Gold Accent */
  --color-pine: 145 28% 18%;        /* 松葉色 (Matsuba-iro) - Pine Needle Green */
  
  --color-text-dark: 240 15% 15%;
  --color-text-light: 40 20% 98%;
  --color-text-muted: 240 8% 45%;

  /* Typography */
  --font-traditional: 'Shippori Mincho', 'Noto Serif JP', 'Hiragino Mincho ProN', 'MS Mincho', serif;
}

/* 1. Global Reset & Layout */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden !important; /* 全体のスクロールを禁止 */
  background-color: hsl(var(--color-sumi));
  font-family: var(--font-traditional);
  color: hsl(var(--color-text-light));
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Traditional Wash Background Ambient Glare */
.ambient-glow {
  position: absolute;
  width: 50vmax;
  height: 50vmax;
  border-radius: 50%;
  filter: blur(140px);
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
}
.ink-bg-dark {
  background: radial-gradient(circle, hsl(var(--color-pine)) 0%, transparent 70%);
  top: -10%;
  left: -10%;
}
.paper-bg-light {
  background: radial-gradient(circle, hsl(var(--color-shuu)) 0%, transparent 70%);
  bottom: -10%;
  right: -10%;
}

/* ==========================================================================
   2. Responsive Game Cabinet Frame
   ========================================================================== */
#game-wrapper {
  width: 100%;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

#game-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-width: 1280px; /* PCでの表示迫力を大幅に強化（960pxから1280pxへ拡大） */
  background-color: hsl(var(--color-sumi-light));
  border: 3px solid rgba(235, 60, 40, 0.15); /* Soft vermilion border */
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  box-shadow: 
    0 25px 60px rgba(0, 0, 0, 0.85),
    0 0 40px rgba(235, 60, 40, 0.04);
  transition: border-color 0.4s ease;
}

#game-container.active {
  border-color: hsla(var(--color-shuu) / 0.5); /* Shines beautifully when game starts */
  box-shadow: 
    0 25px 60px rgba(0, 0, 0, 0.85),
    0 0 25px hsla(var(--color-shuu) / 0.15);
}

/* Hit shock flash screen */
#game-container.hit-flash {
  animation: flashInkRed 0.4s ease-out;
}
@keyframes flashInkRed {
  0% { box-shadow: inset 0 0 120px rgba(235, 60, 40, 0.75), 0 0 50px rgba(235, 60, 40, 0.35); }
  100% { box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85); }
}

/* Canvas Element Layout */
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

/* ==========================================================================
   3. Traditional HUD Elements
   ========================================================================== */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 15;
  pointer-events: none;
}

.score-container, .high-score-container {
  display: flex;
  flex-direction: column;
}
.score-container {
  align-items: flex-start;
}
.high-score-container {
  align-items: center;
  margin-left: auto; /* Push stats as far right as possible, sitting directly adjacent to controls div */
  margin-right: 20px;
}

.label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  opacity: 0.7;
  color: #fff;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  margin-bottom: 2px;
}

.traditional-text {
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 1px;
  text-shadow: 
    0 0 6px rgba(0, 0, 0, 0.9),
    0 0 10px hsla(var(--color-gold) / 0.6);
}
.high-score-container .traditional-text {
  color: hsl(var(--color-gold));
  text-shadow: 
    0 0 6px rgba(0, 0, 0, 0.9),
    0 0 10px hsla(var(--color-gold) / 0.5);
}

/* Glowing text highlight pulse on score */
#score.glow {
  transform: scale(1.15);
  transition: transform 0.1s ease-out;
  color: hsla(var(--color-shuu) / 0.9);
}

/* HUD controls layout containing Sound and Debug buttons side-by-side */
.hud-controls {
  display: flex;
  gap: 10px;
  pointer-events: auto; /* Re-enable pointer events so clicks pass to buttons */
}

.hud-btn {
  background: rgba(18, 18, 20, 0.75);
  border: 1.5px solid hsla(var(--color-gold) / 0.4);
  color: hsl(var(--color-gold));
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all 0.25s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.hud-btn:hover {
  background: hsla(var(--color-gold) / 0.15);
  border-color: hsl(var(--color-gold));
  color: #fff;
  box-shadow: 0 0 12px hsla(var(--color-gold) / 0.4);
}
.hud-btn:active {
  transform: scale(0.9);
}

/* Active debug visualizer highlighted state */
.hud-btn.active {
  background: hsla(var(--color-shuu) / 0.25);
  border-color: hsl(var(--color-shuu));
  color: #fff;
  box-shadow: 0 0 12px hsla(var(--color-shuu) / 0.6);
}

.icon {
  width: 18px;
  height: 18px;
}
.hidden {
  display: none !important;
}

/* ==========================================================================
   4. Traditional Washi Overlay Screens & PAUSE Card
   ========================================================================== */
.overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(5, 5, 8, 0.6);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Japanese parchment card */
.menu-card {
  width: 90%;
  max-width: 420px;
  background: hsl(var(--color-washi-opaque));
  border: 3px double hsl(var(--color-sumi)); /* Traditional double border */
  border-radius: 8px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 
    0 20px 45px rgba(0, 0, 0, 0.8),
    inset 0 0 30px rgba(180, 160, 130, 0.15); /* Vintage parchment tint */
  color: hsl(var(--color-text-dark));
  transform: scale(0.92);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.15);
  position: relative;
}

/* Red inner line decoration like a traditional scroll margin */
.menu-card::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid hsla(var(--color-shuu) / 0.4);
  border-radius: 4px;
  pointer-events: none;
}

.overlay.active .menu-card {
  transform: scale(1);
}

/* Game Title */
.brand {
  margin-bottom: 24px;
}
.sub-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 4px;
  color: hsl(var(--color-text-muted));
  display: block;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  padding-bottom: 6px;
}
.game-title {
  font-family: var(--font-traditional);
  font-size: 42px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 6px;
  color: hsl(var(--color-text-dark));
  margin-top: 8px;
}
.game-title .highlight {
  color: hsl(var(--color-shuu));
  position: relative;
  display: inline-block;
  margin-top: 4px;
}

/* Underline brush effect for highlighted text */
.game-title .highlight::after {
  content: '';
  position: absolute;
  left: -4px;
  right: -8px;
  bottom: -4px;
  height: 4px;
  background-color: hsla(var(--color-shuu) / 0.25);
  border-radius: 4px;
}

/* Simple instructions card */
.instructions-card {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 18px 16px;
  margin-bottom: 28px;
}

.control-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
  color: hsl(var(--color-shuu));
  font-weight: 700;
}
.tap-icon {
  animation: bounceTraditional 1.4s ease-in-out infinite;
}
@keyframes bounceTraditional {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.instructions-card p {
  font-size: 13.5px;
  color: hsl(var(--color-text-muted));
  line-height: 1.6;
}
.instructions-card strong {
  color: hsl(var(--color-text-dark));
  border-bottom: 1px dotted hsl(var(--color-shuu));
}
.game-rule {
  font-size: 11.5px !important;
  margin-top: 8px;
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
  padding-top: 8px;
  color: hsl(var(--color-text-muted));
}

/* Japanese Vermilion Brush-Stroke Styled Buttons */
.glow-btn {
  width: 100%;
  background: hsl(var(--color-shuu));
  color: #fff;
  border: none;
  font-family: var(--font-traditional);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 4px;
  padding: 14px 28px;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.25s ease;
  border: 2px solid hsl(var(--color-sumi));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.glow-btn span {
  position: relative;
  z-index: 5;
}

.glow-btn:hover {
  background: hsl(var(--color-sumi));
  color: hsl(var(--color-washi));
  border-color: hsl(var(--color-shuu));
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
  transform: translateY(-1.5px);
}
.glow-btn:active {
  transform: translateY(0.5px);
}

/* Traditional Pause Overlay Styles */
.pause-card {
  width: 85%;
  max-width: 320px;
  background: rgba(12, 12, 14, 0.9);
  border: 2px solid hsl(var(--color-gold));
  border-radius: 8px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 
    0 20px 45px rgba(0, 0, 0, 0.85),
    inset 0 0 20px rgba(180, 160, 130, 0.1);
  color: hsl(var(--color-washi));
  transform: scale(0.92);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.15);
  position: relative;
  animation: fadeInPause 0.25s ease-out;
}

.pause-card::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid hsla(var(--color-gold) / 0.35);
  border-radius: 4px;
  pointer-events: none;
}

.pause-title {
  font-family: var(--font-traditional);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 6px;
  color: hsl(var(--color-gold));
  text-shadow: 0 0 10px hsla(var(--color-gold) / 0.4);
  margin-bottom: 8px;
  margin-top: 4px;
}

.pause-subtitle {
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 2px;
  opacity: 0.8;
  color: hsl(var(--color-washi));
}

@keyframes fadeInPause {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.overlay.active .pause-card {
  transform: scale(1);
}

/* Game Over Card Customizations */
.game-over-card {
  border-color: hsl(var(--color-shuu));
  max-height: 85vh; /* 画面の高さの85%を最大値とする */
  overflow-y: auto; /* はみ出た場合のみ、この枠内に縦スクロールバーを出す */
}

/* Elegant traditional scrollbar styling for result modal */
.game-over-card::-webkit-scrollbar {
  width: 6px;
}
.game-over-card::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 3px;
}
.game-over-card::-webkit-scrollbar-thumb {
  background: hsl(var(--color-shuu) / 0.45);
  border-radius: 3px;
  transition: background 0.2s ease;
}
.game-over-card::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--color-shuu) / 0.8);
}

.system-alert {
  font-size: 11px;
  font-weight: 700;
  color: hsl(var(--color-shuu));
  letter-spacing: 4px;
  display: block;
  margin-bottom: 6px;
}

.game-over-title {
  font-family: var(--font-traditional);
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 8px;
  color: hsl(var(--color-text-dark));
  margin-bottom: 18px;
}

/* Stat Box Layout */
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: hsl(var(--color-text-muted));
  margin-bottom: 4px;
}

.stat-val {
  font-size: 28px;
  color: hsl(var(--color-text-dark));
}

.best-box {
  border-color: hsla(var(--color-gold) / 0.4);
}
.best-box .stat-val {
  color: hsl(var(--color-gold));
}

.badge {
  position: absolute;
  top: -10px;
  background: hsl(var(--color-shuu));
  color: #fff;
  font-family: var(--font-traditional);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 2px;
  border: 1px solid hsl(var(--color-sumi));
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  animation: bounceBadge 0.6s ease infinite alternate;
}
@keyframes bounceBadge {
  from { transform: translateY(0); }
  to { transform: translateY(-2px); }
}

.btn-retry {
  background: hsl(var(--color-sumi));
  color: hsl(var(--color-washi));
  border-color: hsl(var(--color-shuu));
}

.btn-retry:hover {
  background: hsl(var(--color-shuu));
  color: #fff;
  border-color: hsl(var(--color-sumi));
}

/* ==========================================================================
   5. Wafuu Form Wrapper inside Game Over
   ========================================================================== */
.form-wrapper {
  background: rgba(0, 0, 0, 0.02);
  border: 1px dashed rgba(235, 60, 40, 0.25);
  border-radius: 6px;
  padding: 14px 18px;
  margin-bottom: 16px;
  text-align: center;
  position: relative;
  z-index: 10;
}

.form-title {
  font-family: var(--font-traditional);
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 2px;
  color: hsl(var(--color-shuu));
  margin-bottom: 10px;
}

/* Traditional Calligraphic Input Field */
.input-group {
  width: 100%;
  margin-bottom: 8px;
}

#player-name {
  width: 100%;
  background: rgba(255, 255, 255, 0.75);
  border: 1.5px solid hsl(var(--color-sumi));
  border-radius: 4px;
  padding: 8px 12px;
  font-family: var(--font-traditional);
  font-size: 13.5px;
  font-weight: 700;
  color: hsl(var(--color-text-dark));
  text-align: center;
  letter-spacing: 2px;
  transition: all 0.2s ease;
}

#player-name:focus {
  background: #fff;
  border-color: hsl(var(--color-shuu));
  box-shadow: 0 0 8px hsla(var(--color-shuu) / 0.25);
  outline: none;
}

/* Vermilion submit button */
.btn-submit {
  background: hsl(var(--color-shuu));
  color: #fff;
  border-color: hsl(var(--color-sumi));
  font-size: 14px;
  padding: 10px 20px;
  margin-bottom: 4px;
}

.btn-submit:hover {
  background: hsl(var(--color-sumi));
  color: hsl(var(--color-washi));
  border-color: hsl(var(--color-shuu));
}

.btn-submit:disabled {
  background: hsl(var(--color-text-muted)) !important;
  border-color: hsl(var(--color-sumi)) !important;
  color: #ccc !important;
  cursor: not-allowed !important;
}

/* Submission status texts */
.status-text {
  font-size: 11px;
  margin-top: 4px;
  font-weight: 700;
  letter-spacing: 1px;
  min-height: 16px;
}
.status-text.success {
  color: #1a562d; /* Moss Green */
}
.status-text.error {
  color: hsl(var(--color-shuu));
}
.status-text.loading {
  color: hsl(var(--color-gold));
  animation: flashAlert 0.8s ease infinite alternate;
}

/* Link to portal rankings page */
.portal-link {
  display: inline-block;
  font-size: 11.5px;
  color: hsl(var(--color-shuu));
  text-decoration: none;
  margin-top: 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
  border-bottom: 1.5px solid hsla(var(--color-shuu) / 0.35);
  transition: all 0.2s ease;
}
.portal-link:hover {
  color: hsl(var(--color-gold));
  border-color: hsl(var(--color-gold));
  transform: translateY(-0.5px);
}

/* ==========================================================================
   6. 順位表ポータル (portal.html) 専用スタイル
   ========================================================================== */
.portal-body {
  overflow-y: auto !important; /* Allow scroll on leaderboard portal */
}

.leaderboard-card {
  max-width: 1080px !important; /* すべての難易度が一望できるよう、最大幅を1080pxへ大幅に拡張！ */
  width: 95% !important;
  padding: 32px 28px !important;
}

/* 3つの難易度カードを並べるレスポンシブコンテナ */
.rankings-container {
  display: flex;
  gap: 20px;
  width: 100%;
  margin: 18px 0 24px 0;
  flex-direction: row; /* PC上では3列に横並び */
}

.difficulty-rank-card {
  flex: 1;
  background: rgba(0, 0, 0, 0.015);
  border: 1px dashed rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  padding: 18px 14px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.02);
  display: flex;
  flex-direction: column;
}

.rank-card-title {
  font-family: var(--font-traditional);
  font-size: 14.5px;
  font-weight: 800;
  text-align: center;
  padding: 8px 0;
  margin-bottom: 14px;
  border-radius: 4px;
  letter-spacing: 2px;
  color: #fff;
  border: 1px solid hsl(var(--color-sumi));
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.normal-title {
  background: hsl(var(--color-pine));
}
.hard-title {
  background: #2b3a4a;
}
.lunatic-title {
  background: hsl(var(--color-shuu));
}

/* レスポンシブ対応（スマホやタブレットでは縦並びに） */
@media (max-width: 820px) {
  .rankings-container {
    flex-direction: column;
    gap: 16px;
  }
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-traditional);
  font-size: 13.5px;
  text-align: left;
}

.leaderboard-table th, .leaderboard-table td {
  padding: 11px 14px;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
  color: hsl(var(--color-text-dark));
}

.leaderboard-table th {
  background: rgba(0, 0, 0, 0.04);
  font-weight: 800;
  color: hsl(var(--color-text-dark));
  letter-spacing: 2px;
  border-bottom: 2px solid hsl(var(--color-sumi));
}

.leaderboard-table tr:last-child td {
  border-bottom: none;
}

/* Highlight ranks */
.rank-col {
  font-weight: 900;
  text-align: center;
  width: 60px;
}

/* Traditional Medal Colors */
.rank-1 {
  color: hsl(var(--color-gold)) !important;
  font-size: 16px;
  text-shadow: 0 0 1px rgba(0,0,0,0.1);
}
.rank-2 {
  color: #8a9ba8 !important; /* Elegant Silver */
  font-size: 15px;
}
.rank-3 {
  color: #b07040 !important; /* Elegant Bronze */
  font-size: 14.5px;
}

.score-col {
  font-family: var(--font-traditional);
  font-weight: 900;
  color: hsl(var(--color-shuu)) !important;
  text-align: right;
  width: 100px;
  font-size: 15px;
}
.rank-1-row .score-col {
  text-shadow: 0 0 4px hsla(var(--color-shuu) / 0.15);
}

.date-col {
  font-size: 11px;
  color: hsl(var(--color-text-muted)) !important;
  width: 140px;
}

/* Red border highlight for top row */
.rank-1-row {
  background: rgba(235, 60, 40, 0.03);
}

.btn-back {
  background: hsl(var(--color-sumi));
  color: hsl(var(--color-washi));
  border-color: hsl(var(--color-shuu));
}
.btn-back:hover {
  background: hsl(var(--color-shuu));
  color: #fff;
  border-color: hsl(var(--color-sumi));
}

/* ==========================================================================
   7. Responsive Viewports (PC・スマホ双方への完璧なレスポンシブ最適化)
   ========================================================================== */
@media (max-width: 768px) {
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
  }

  #game-wrapper {
    padding: 8px 0;
    height: auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  
  /* ゲーム画面のコンテナ：アスペクト比を解除し、スマホの縦長画面いっぱいに表示 */
  #game-container.interactive-area {
    aspect-ratio: auto !important;
    height: 100vh !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100vh !important;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding-bottom: 0 !important;
  }
  
  /* 順位表（ポータル）のコンテナ：アスペクト比を解除し、テーブルがすべて収まるようにする */
  #game-container.leaderboard-card {
    aspect-ratio: auto !important;
    height: auto !important;
    min-height: 100vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding-bottom: 40px !important;
    overflow: visible !important;
  }

  /* メニューオーバーレイ：全画面固定（fixed）かつFlexboxによるスクロール崩れ防止中央配置をサポート */
  .overlay {
    position: fixed !important;
    inset: 0 !important;
    z-index: 100 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important; /* スクリプトはみ出し時の上部見切れを防止 */
    align-items: center !important;
    overflow-y: auto !important;
    padding: 32px 16px !important;
  }

  /* 
     Flexboxのmargin-top/bottom: autoにより、
     画面内に収まるときは完璧に上下中央配置され、
     画面からはみ出るときは上部が切れずに上端から綺麗にスクロール可能になります！
  */
  .menu-card, .pause-card {
    width: 95% !important;
    max-width: 360px !important;
    margin-top: auto !important;
    margin-bottom: auto !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding: 20px 14px !important; /* スマートフォン向けにパディングを最適化 */
  }

  /* モバイル向けのボタンと余白の細密調整 */
  .glow-btn, .btn-difficulty {
    padding: 10px 16px !important;
    font-size: 14px !important;
  }

  .quick-instruction {
    margin-bottom: 16px !important;
    padding: 6px 10px !important;
  }

  .inst-text {
    font-size: 11.5px !important;
  }

  .btn-emoji {
    font-size: 18px !important;
    width: 24px !important;
  }

  .btn-title {
    font-size: 13.5px !important;
  }

  .btn-subtitle {
    font-size: 9.5px !important;
  }

  /* リザルト画面（ゲームオーバー）のモバイル表示最適化 */
  .form-wrapper {
    padding: 10px 12px !important;
    margin-bottom: 12px !important;
  }

  .stat-box {
    padding: 8px !important;
  }

  .result-stats {
    gap: 12px !important;
    margin-bottom: 12px !important;
  }

  .game-over-buttons {
    margin-top: 8px !important;
    margin-bottom: 4px !important;
  }
  
  .game-title {
    font-size: 30px !important;
  }
  
  .game-over-title {
    font-size: 26px !important;
  }

  .stat-val {
    font-size: 20px !important;
  }

  .traditional-text {
    font-size: 20px !important;
  }
  
  #hud {
    padding: 10px 14px !important;
  }

  /* 順位表（ポータル）のスマホ向け極小化レイアウト調整 */
  .rankings-container {
    flex-direction: column !important; /* 縦並びに強制 */
    gap: 16px !important;
  }

  .difficulty-rank-card {
    width: 100% !important;
    padding: 12px 8px !important;
  }

  .leaderboard-table th, .leaderboard-table td {
    padding: 8px 6px !important;
    font-size: 11.5px !important;
  }
  
  .score-col {
    width: 75px !important;
    font-size: 12.5px !important;
  }
  
  .rank-col {
    width: 35px !important;
  }
}

/* Quick Instruction Tag Banner */
.quick-instruction {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
  background: hsla(var(--color-shuu) / 0.05);
  border: 1px dashed hsla(var(--color-shuu) / 0.25);
  padding: 8px 14px;
  border-radius: 6px;
  width: 100%;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.02);
}

.inst-tag {
  background: hsl(var(--color-shuu));
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  padding: 2.5px 8px;
  border-radius: 3px;
  letter-spacing: 2px;
  border: 1px solid hsl(var(--color-sumi));
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.inst-text {
  font-size: 13px;
  color: hsl(var(--color-text-dark));
  letter-spacing: 1px;
}

/* Calligraphic Button Contents */
.btn-content {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  text-align: left;
  width: 100%;
  padding: 2px 4px;
}

.btn-emoji {
  font-size: 22px;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.4));
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 28px;
}

.btn-texts {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}

.btn-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.btn-subtitle {
  font-size: 10.5px;
  font-weight: 400;
  opacity: 0.88;
  letter-spacing: 1px;
  margin-top: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ==========================================================================
   8. Difficulty Button & Portal Tabs Custom Styles
   ========================================================================== */
.btn-difficulty {
  border-width: 2px;
  font-size: 14.5px;
  padding: 11px 20px;
  letter-spacing: 2px;
  transition: all 0.25s ease;
}

.btn-normal {
  background: hsl(var(--color-pine));
  border-color: hsl(var(--color-sumi));
  box-shadow: 0 4px 10px hsla(var(--color-pine) / 0.3);
}
.btn-normal:hover {
  background: hsl(var(--color-sumi));
  color: #a8ffa8;
  border-color: hsl(var(--color-pine));
  box-shadow: 0 6px 15px hsla(var(--color-pine) / 0.5);
}

.btn-hard {
  background: #2b3a4a; /* Slate Blue Metallic */
  color: #fff;
  border-color: hsl(var(--color-sumi));
  box-shadow: 0 4px 10px rgba(43, 58, 74, 0.4);
}
.btn-hard:hover {
  background: hsl(var(--color-sumi));
  color: #d4e3ff;
  border-color: #5b7ba8;
  box-shadow: 0 6px 15px rgba(91, 123, 168, 0.6);
}

.btn-lunatic {
  background: hsl(var(--color-shuu));
  border-color: hsl(var(--color-sumi));
  box-shadow: 0 4px 10px hsla(var(--color-shuu) / 0.3);
  animation: pulseLunaticBorder 1.5s ease-in-out infinite alternate;
}
.btn-lunatic:hover {
  background: hsl(var(--color-sumi));
  color: #ff9e9e;
  border-color: hsl(var(--color-shuu));
  box-shadow: 0 6px 15px hsla(var(--color-shuu) / 0.6);
}

@keyframes pulseLunaticBorder {
  0% { box-shadow: 0 4px 10px hsla(var(--color-shuu) / 0.3); border-color: hsl(var(--color-sumi)); }
  100% { box-shadow: 0 4px 18px hsla(var(--color-shuu) / 0.65); border-color: #ff3c24; }
}

/* Leaderboard Tabs Style (Portal) */
.leaderboard-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 16px;
  border-bottom: 2px dashed rgba(0, 0, 0, 0.1);
  padding-bottom: 12px;
}

.tab-btn {
  background: rgba(0, 0, 0, 0.03);
  border: 1.5px solid hsl(var(--color-sumi));
  color: hsl(var(--color-text-dark));
  font-family: var(--font-traditional);
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 1px;
}

.tab-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  transform: translateY(-0.5px);
}

.tab-btn.active {
  background: hsl(var(--color-sumi));
  color: hsl(var(--color-washi));
  border-color: hsl(var(--color-shuu));
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.tab-btn.active[data-difficulty="normal"] {
  border-color: #3b7c55;
}
.tab-btn.active[data-difficulty="hard"] {
  border-color: #356b9c;
}
.tab-btn.active[data-difficulty="lunatic"] {
  border-color: hsl(var(--color-shuu));
}

/* Landscape orientation for mobile */
@media (max-height: 480px) {
  .menu-card {
    padding: 16px 20px;
    border-radius: 4px;
    max-width: 480px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    text-align: left;
  }
  
  .menu-card::before {
    inset: 4px;
  }

  .brand {
    margin-bottom: 0;
  }
  
  .game-title {
    font-size: 24px;
  }
  
  .instructions-card {
    margin-bottom: 0;
    flex-grow: 1;
    padding: 10px;
  }
  
  .glow-btn {
    width: auto;
    padding: 10px 20px;
    font-size: 13.5px;
  }

  .game-over-card {
    flex-direction: column;
    padding: 16px;
  }

  .game-over-title {
    font-size: 22px;
    margin-bottom: 8px;
  }

  .result-stats {
    margin-bottom: 8px;
    gap: 12px;
  }
}

/* ==========================================================================
   SNS Share & Result Saving Styles
   ========================================================================== */
.share-section {
  width: 100%;
  margin-top: 14px;
  margin-bottom: 12px;
  padding: 10px 0;
  border-top: 1px dotted hsla(var(--color-gold) / 0.3);
  text-align: center;
}

.share-title {
  font-family: var(--font-traditional);
  font-size: 13px;
  color: hsl(var(--color-gold));
  margin: 0 0 10px 0;
  letter-spacing: 3px;
  text-shadow: 0 0 6px hsla(var(--color-gold) / 0.3);
}

.sns-share-wrapper {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  width: 100% !important;
  justify-content: center !important;
}

.btn-sns {
  flex: 1 !important;
  width: auto !important;
  min-width: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 13px !important;
  padding: 8px 4px !important;
  letter-spacing: 0px !important;
  border-radius: 4px !important;
  transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
  white-space: nowrap !important;
}

/* X (formerly Twitter) brand styling */
.btn-x {
  background: #000000 !important;
  color: #ffffff !important;
  border: 1.5px solid #333333 !important;
}
.btn-x:hover {
  background: #14171a !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.4) !important;
  transform: translateY(-2px);
}

/* LINE brand styling */
.btn-line {
  background: #06C755 !important;
  color: #ffffff !important;
  border: 1.5px solid #05b04b !important;
}
.btn-line:hover {
  background: #05b04b !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 15px rgba(6, 199, 85, 0.5) !important;
  transform: translateY(-2px);
}

/* Save Image premium styling - Wafuu Charcoal & Gold */
.btn-save {
  background: hsl(var(--color-sumi-light)) !important;
  color: hsl(var(--color-washi)) !important;
  border: 2px solid hsl(var(--color-gold)) !important;
  box-shadow: 0 0 8px hsla(var(--color-gold) / 0.25) !important;
}
.btn-save:hover {
  background: hsl(var(--color-gold)) !important;
  color: hsl(var(--color-sumi)) !important;
  border-color: hsl(var(--color-sumi)) !important;
  box-shadow: 0 0 18px hsla(var(--color-gold) / 0.65) !important;
  transform: translateY(-2px);
}

/* Native Share premium styling - Mystic Purple & Silver */
.btn-native {
  background: #23122c !important;
  color: #ebd3ff !important;
  border: 1.5px solid #a34deb !important;
}
.btn-native:hover {
  background: #461b61 !important;
  color: #ffffff !important;
  border-color: #ebd3ff !important;
  box-shadow: 0 0 15px rgba(163, 77, 235, 0.6) !important;
  transform: translateY(-2px);
}

/* Hide helper class */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Footer & Footer Links (for Game Page layout)
   ========================================================================== */
footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  padding: 10px;
  background: rgba(12, 12, 14, 0.85); /* Sumi black with transparency */
  z-index: 100;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 15px;
  flex-wrap: wrap;
  margin-top: 5px;
}

.footer-links a {
  color: hsl(var(--color-text-muted));
  text-decoration: none;
  font-size: 12px;
}

.footer-links a:hover {
  color: hsl(var(--color-shuu));
  text-decoration: underline;
}



/* Core Layout Fixes for Mobile */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

/* Advertisement Visibility & Centering Helpers */
.ad-mobile-only, .ad-pc-only {
  width: 100%;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}
.ad-mobile-only iframe, .ad-pc-only iframe {
  max-width: 100% !important;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .ad-pc-only { display: none !important; }
  .ad-mobile-only { display: flex !important; }
}
@media (min-width: 769px) {
  .ad-mobile-only { display: none !important; }
  .ad-pc-only { display: flex !important; }
}
