:root {
  --bg-color: #080b12;
  --panel-bg: #121824;
  --border-color: #26334d;
  --gold: #f6c85f;
  --cyan: #38ef7d;
  --blue: #38bdf8;
  --red: #ff3366;
}

* { 
  box-sizing: border-box; 
  user-select: none; 
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  margin: 0; 
  padding: 0; 
}

body {
  background-color: var(--bg-color);
  color: #e2e8f0;
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', 'Sawarabi Mincho', serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 6px;
  touch-action: manipulation;
  overflow-x: hidden;
}

header { 
  text-align: center; 
  margin-bottom: 4px; 
}

h1 {
  font-size: 18px;
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(246, 200, 95, 0.6);
}

.sub { 
  font-size: 10px; 
  color: #718096; 
  letter-spacing: 1px; 
}

#game-wrapper {
  position: relative;
  width: 100%;
  max-width: 960px;
  border: 1px solid var(--border-color);
  background: #000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.9);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 11px;
  flex-wrap: wrap;
  gap: 4px;
}

.hud-left { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  flex-wrap: wrap; 
}

#hud-status {
  color: #718096;
}

.stage-tag {
  background: #1e283d;
  color: var(--gold);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: bold;
  border: 1px solid #334466;
  font-size: 11px;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 180px;
}

.eval-label {
  font-weight: bold;
  letter-spacing: 0.05em;
}

#eval-value {
  font-variant-numeric: tabular-nums;
}

.eval-bar {
  position: relative;
  width: 180px;
  height: 8px;
  background: rgba(128, 128, 128, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.eval-bar-center {
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.55);
  z-index: 1;
}

#eval-fill {
  position: absolute;
  top: 0;
  height: 100%;
  transition: left 0.25s ease, width 0.25s ease;
}

.eval-fill-plus {
  background: #f0b429;
}

.eval-fill-minus {
  background: #ef476f;
}

.hud-right { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
}

.stock-label {
  font-size: 10px; 
  color: #64748b;
}

.stock-box { 
  display: flex; 
  gap: 4px; 
}

.stock-item {
  width: 32px;
  height: 38px;
  background: #182030;
  border: 1px solid #314261;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: bold;
  color: #a0aec0;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.stock-item.active {
  border-color: #38ef7d;
  background: #14352b;
  color: #fff;
  box-shadow: 0 0 8px rgba(56, 239, 125, 0.4);
  transform: translateY(-2px);
}

.stock-item.gyoku { 
  border-color: var(--gold); 
  color: var(--gold); 
}

.stock-count {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 9px;
  font-weight: bold;
  color: #38bdf8;
  line-height: 1;
}

.stock-num { 
  position: absolute; 
  bottom: 1px; 
  right: 2px; 
  font-size: 8px; 
  color: #64748b; 
}

#canvas-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #070a10;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#footer-bar {
  background: var(--panel-bg);
  border-top: 1px solid var(--border-color);
  padding: 4px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: #94a3b8;
}

.keys { 
  display: none; 
}

@media (min-width: 768px) {
  .keys { display: block; }
}

.keys span {
  background: #1c2538;
  color: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid #334363;
  font-family: monospace;
  font-size: 9px;
  margin: 0 1px;
}

#zone-alert {
  color: var(--gold); 
  font-weight: bold;
}

#touch-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  background: #0d121c;
  border-top: 1px solid #1f2a3f;
  touch-action: none;
}

.stick-area {
  position: relative;
  width: 110px;
  height: 110px;
  background: rgba(30, 42, 64, 0.4);
  border: 2px solid rgba(56, 239, 125, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stick-knob {
  position: absolute;
  width: 48px;
  height: 48px;
  background: radial-gradient(circle, #38ef7d 0%, #165b38 100%);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(56, 239, 125, 0.5);
  pointer-events: none;
  transform: translate(0px, 0px);
}

.action-pad {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.action-row-sub {
  display: flex;
  gap: 6px;
}

.action-row-main {
  display: flex;
  gap: 10px;
}

.t-btn {
  border-radius: 8px;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  border: none;
  outline: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s, filter 0.08s;
}

.t-btn:active {
  transform: scale(0.92);
  filter: brightness(1.25);
}

.t-btn-sub {
  min-width: 52px;
  height: 34px;
  padding: 0 6px;
  background: #1b263b;
  border: 1px solid #33496f;
  font-size: 11px;
  color: #cbd5e1;
}

.t-btn-aigoma {
  border-color: #38bdf8;
  color: #bae6fd;
  background: #0c2d48;
}

.t-btn-jump {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1e3a5f;
  border: 2px solid #4a88d9;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(74, 136, 217, 0.4);
}

.t-btn-blink {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: radial-gradient(circle, #10b981 0%, #065f46 100%);
  border: 2px solid #34d399;
  font-size: 15px;
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.5);
  color: #fff;
}

/* ========================================================
   詰み演出モーダル（軽量GPUアクセラレーション仕様）
   ======================================================== */
#modal-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 100;
  padding: 16px;
  overflow: hidden;
  background: #000000;
  animation: modal-fade-black 0.45s ease-out forwards;
}

@keyframes modal-fade-black {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

/* ハイカジ風・回転集中線（GPU回転合成） */
.sunburst {
  position: absolute;
  width: 220vmax;
  height: 220vmax;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(
    from 0deg,
    rgba(246, 200, 95, 0.28) 0deg 8deg,
    transparent 8deg 18deg
  );
  mask-image: radial-gradient(circle, rgba(0, 0, 0, 1) 20%, rgba(0, 0, 0, 0) 70%);
  -webkit-mask-image: radial-gradient(circle, rgba(0, 0, 0, 1) 20%, rgba(0, 0, 0, 0) 70%);
  animation: rotate-sunburst 14s linear infinite;
  pointer-events: none;
  z-index: 1;
  display: none;
  will-change: transform;
}

@keyframes rotate-sunburst {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.win-mode .sunburst {
  display: block;
}

.lose-mode .sunburst {
  display: none;
}

#modal-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* 手前(大・透明) → 奥(等倍・着地) への高速GPUズームコンテナ */
#tsumi-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  will-change: transform, opacity;
  transform: translateZ(0);
  animation: tsumi-slam 0.55s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes tsumi-slam {
  0% {
    transform: scale(3.5);
    opacity: 0;
  }
  60% {
    transform: scale(0.95);
    opacity: 1;
  }
  80% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1.0);
    opacity: 1;
  }
}

/* 「詰み」文字：文字形状に沿った鮮鋭エッジブルーム */
#modal-tsumi-text {
  position: relative;
  z-index: 1;
  font-size: clamp(70px, 16vw, 120px);
  font-weight: 900;
  letter-spacing: 16px;
  margin-left: 16px; /* letter-spacingのセンタリング補正 */
  line-height: 1;
  text-align: center;
  user-select: none;
  will-change: transform;
  transform: translateZ(0);
}

/* 勝利時：黄金の文字形状エッジブルーム */
.win-mode #modal-tsumi-text {
  background: linear-gradient(180deg, #ffffff 0%, #fff9db 25%, #f6c85f 65%, #b45309 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1.2px rgba(255, 255, 255, 0.85);
  filter: 
    drop-shadow(0 0 2px #ffffff)
    drop-shadow(0 0 6px #f6c85f)
    drop-shadow(0 0 16px rgba(245, 158, 11, 0.85));
}

/* 敗北時：白を排した暗めの深紅〜黒赤グラデーションと血紅のエッジブルーム */
.lose-mode #modal-tsumi-text {
  background: linear-gradient(180deg, #d90429 0%, #9b111e 30%, #4a000a 70%, #150003 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1px rgba(255, 51, 85, 0.65);
  filter: 
    drop-shadow(0 0 2px #ff1e56)
    drop-shadow(0 0 6px #b91c1c)
    drop-shadow(0 0 16px rgba(153, 27, 27, 0.75));
}

#modal-desc { 
  font-size: 13px; 
  color: #94a3b8; 
  margin-bottom: 20px; 
  max-width: 440px; 
  line-height: 1.6;
  opacity: 0;
  animation: modal-sub-fade 0.35s ease-out 0.4s forwards;
}

.btn-action {
  border-radius: 6px;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  opacity: 0;
  animation: modal-sub-fade 0.35s ease-out 0.4s forwards;
  transition: all 0.15s ease;
}

@keyframes modal-sub-fade {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.win-mode .btn-action {
  background: #1a1608;
  border: 1.5px solid var(--gold);
  color: var(--gold);
  box-shadow: 0 0 16px rgba(246, 200, 95, 0.35);
}

.win-mode .btn-action:hover { 
  background: var(--gold); 
  color: #000; 
  box-shadow: 0 0 24px rgba(246, 200, 95, 0.7);
}

.lose-mode .btn-action {
  background: #1c080e;
  border: 1.5px solid var(--red);
  color: #ff8da1;
  box-shadow: 0 0 16px rgba(255, 51, 102, 0.35);
}

.lose-mode .btn-action:hover { 
  background: var(--red); 
  color: #fff; 
  box-shadow: 0 0 24px rgba(255, 51, 102, 0.7);
}

/* ========================================================
   タイトル画面
   ======================================================== */
#title-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 90;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(10, 12, 24, 0.82) 0%, rgba(0, 0, 0, 0.94) 78%);
}

.title-piece {
  width: 92px;
  height: 100px;
  background: linear-gradient(180deg, #f7d774 0%, #dfa93f 100%);
  clip-path: polygon(50% 0%, 100% 30%, 88% 100%, 12% 100%, 0% 30%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 46px;
  font-weight: bold;
  color: #3a2a00;
  margin-bottom: 18px;
}

.title-logo {
  font-size: 54px;
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(246, 200, 95, 0.45);
  margin-bottom: 10px;
}

.title-sub {
  color: #94a3b8;
  font-size: 14px;
  margin-bottom: 30px;
}

.title-btn {
  background: #1a1608;
  border: 1.5px solid var(--gold);
  color: var(--gold);
  box-shadow: 0 0 16px rgba(246, 200, 95, 0.35);
  font-size: 17px;
  padding: 13px 42px;
}

.title-btn:hover {
  background: var(--gold);
  color: #000;
  box-shadow: 0 0 24px rgba(246, 200, 95, 0.7);
}

.title-keys {
  color: #64748b;
  font-size: 12px;
  margin-top: 26px;
}

/* ========================================================
   エンディング（エンドロール）
   ======================================================== */
#ending-overlay {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 95;
  overflow: hidden;
  background: #000;
  text-align: center;
}

#ending-roll {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  animation: ending-roll-up 30s linear 0.5s forwards;
}

@keyframes ending-roll-up {
  to { top: -230%; }
}

.ending-head {
  font-size: 40px;
  letter-spacing: 10px;
  color: var(--gold);
  margin-bottom: 8px;
}

.ending-game-title {
  font-size: 18px;
  letter-spacing: 4px;
  color: #e2e8f0;
  margin-bottom: 56px;
}

.ending-block {
  margin-bottom: 40px;
}

.ending-role {
  font-size: 13px;
  letter-spacing: 3px;
  color: #94a3b8;
  margin-bottom: 6px;
}

.ending-name {
  font-size: 19px;
  color: #fff;
}

.ending-final {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  animation: modal-sub-fade 1.2s ease-out 27s forwards;
  pointer-events: none;
}

.ending-thanks {
  font-size: 26px;
  letter-spacing: 5px;
  color: var(--gold);
  margin-bottom: 12px;
}

.ending-copy {
  color: #94a3b8;
  font-size: 13px;
}

.ending-btn {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 26px;
  margin: 0 auto;
  width: fit-content;
  z-index: 2;
  background: #1a1608;
  border: 1.5px solid var(--gold);
  color: var(--gold);
  box-shadow: 0 0 16px rgba(246, 200, 95, 0.35);
  animation-delay: 1.2s;
}

.ending-btn:hover {
  background: var(--gold);
  color: #000;
}

/* 持ち駒欄の到着ポップ */
.stock-box.pop {
  animation: stock-pop 0.3s ease;
}

@keyframes stock-pop {
  30% { transform: scale(1.1); }
}
