/* ============================
   チュートリアル 共通CSS
   ============================ */

/* --- CSS Variables (ゲーム本体と統一) --- */
:root {
  --tut-bg: #c8e6c9;
  --tut-surface: #ffffff;
  --tut-text: #1b5e20;
  --tut-text-secondary: #388e3c;
  --tut-accent: #4fc3f7;
  --tut-border: rgba(27, 94, 32, 0.15);
  --tut-radius: 14px;
  --tut-shadow: 0 20px 60px rgba(27, 94, 32, 0.15);
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--tut-bg);
  color: var(--tut-text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ============================
   言語切替ボタン
   ============================ */
.tut-lang-btn {
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--tut-border);
  background: var(--tut-surface);
  color: var(--tut-text-secondary);
  transition: background 0.2s, color 0.2s;
}
.tut-lang-btn.active {
  background: var(--tut-accent);
  color: #fff;
  border-color: var(--tut-accent);
}

/* ============================
   チュートリアル ダイアログ
   ============================ */
.tutorial-container {
  background: var(--tut-surface);
  border-radius: var(--tut-radius);
  width: 100%;
  max-width: 700px;
  padding: 2rem;
  box-shadow: var(--tut-shadow);
  text-align: center;
}

.tutorial-header {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--tut-text);
  margin-bottom: 1.5rem;
}

/* ============================
   ステップ表示
   ============================ */
.tutorial-steps { position: relative; }

.tutorial-step {
  display: none;
  animation: tutFadeIn 0.4s ease-out;
}
.tutorial-step.active { display: block; }

@keyframes tutFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- アニメーション領域 --- */
.step-animation {
  width: 100%;
  min-height: 200px;
  background: linear-gradient(180deg, #f1f8e9, #e8f5e9);
  border: 2px solid var(--tut-border);
  border-radius: 12px;
  margin-bottom: 1.2rem;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* --- テキスト --- */
.step-desc {
  font-size: 1rem;
  color: var(--tut-text);
  line-height: 1.7;
  margin-bottom: 1.2rem;
}

/* ============================
   ナビゲーション
   ============================ */
.tutorial-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.nav-btn {
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s, opacity 0.15s;
}
.nav-btn:active { transform: scale(0.96); }

.nav-prev {
  background: #f5f5f5;
  color: #666;
}
.nav-next, .nav-start {
  background: linear-gradient(135deg, #0288d1, #01579b);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(2, 136, 209, 0.4);
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
.nav-prev[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.tutorial-dots {
  display: flex;
  gap: 6px;
}
.tutorial-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
  transition: background 0.3s, transform 0.3s;
}
.tutorial-dots .dot.active {
  background: var(--tut-text-secondary);
  transform: scale(1.3);
}

/* ============================
   ミニ盤面（タイル表示用）
   ============================ */
.tut-board {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tut-field {
  background: var(--tut-bg);
  border: 1.5px solid var(--tut-border);
  border-radius: 8px;
  min-height: 60px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  position: relative;
}

.tut-field-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--tut-text-secondary);
  position: absolute;
  top: -10px;
  left: 10px;
  background: var(--tut-surface);
  padding: 0 4px;
}

.tut-hand {
  background: linear-gradient(180deg, #442410, #5c351b);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 50px;
}

.tut-hand-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
  position: absolute;
  top: -10px;
  left: 10px;
  background: #5c351b;
  padding: 0 4px;
  border-radius: 3px;
}

.tut-exit-btn {
  font-size: 0.8rem;
  padding: 6px 16px;
  background: #2c3e50; /* Solid dark background */
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff !important; /* Force white text */
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.tut-exit-btn:hover {
  background: #34495e;
  border-color: #fff;
}

.lang-toggle {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px;
  border-radius: 4px;
}

.tut-set-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 40px;
  border: 2px dashed rgba(79, 195, 247, 0.5);
  border-radius: 5px;
  color: var(--tut-accent);
  font-size: 1.2rem;
  font-weight: 700;
}

/* ============================
   タイル（ゲーム本体と同じ見た目）
   ============================ */
.tut-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 42px;
  border-radius: 5px;
  font-size: 0.95rem;
  font-weight: 800;
  user-select: none;
  flex-shrink: 0;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 40%, rgba(0,0,0,0.08) 100%),
    #e8d5b5;
  border: 1px solid #c9bda8;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  position: relative;
  z-index: 1;
}

.tut-tile.red   { color: #d32f2f; }
.tut-tile.blue  { color: #1976d2; }
.tut-tile.black { color: #212121; }
.tut-tile.orange { color: #f57c00; }

.tut-tile.selected {
  outline: 3px solid #fdd835;
  outline-offset: 1px;
  box-shadow: 0 0 10px rgba(253, 216, 53, 0.6);
  z-index: 50;
}

/* ============================
   カーソル / 指アイコン
   ============================ */
.tut-cursor {
  position: absolute;
  font-size: 2.5rem;
  z-index: 100;
  pointer-events: none;
  filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.5));
}

/* ============================
   アニメーション定義
   ============================ */

/* --- Step 1: 目的 (タイルが場に移動) --- */
@keyframes goalMove {
  0%   { transform: translateY(0); opacity: 1; }
  40%  { transform: translateY(-60px); opacity: 0.8; }
  60%  { transform: translateY(-60px); opacity: 0; }
  100% { transform: translateY(0); opacity: 0; }
}
.anim-goal-1 { animation: goalMove 3s ease-in-out 0.2s infinite; }
.anim-goal-2 { animation: goalMove 3s ease-in-out 0.8s infinite; }
.anim-goal-3 { animation: goalMove 3s ease-in-out 1.4s infinite; }

@keyframes goalClear {
  0%, 70% { opacity: 0; transform: scale(0.5); }
  85%     { opacity: 1; transform: scale(1.2); }
  100%    { opacity: 1; transform: scale(1); }
}
.anim-clear { animation: goalClear 3s ease-in-out infinite; font-size: 2rem; }

/* --- Step 2 PC: ドラッグ (タイルが持ち上がり場に移動) --- */
@keyframes dragTile {
  0%   { transform: translate(0, 0) scale(1); }
  15%  { transform: translate(0, -8px) scale(1.15); }
  50%  { transform: translate(120px, -70px) scale(1.15); }
  65%  { transform: translate(120px, -70px) scale(1); }
  80%  { transform: translate(120px, -70px) scale(1); opacity: 0; }
  81%  { transform: translate(0, 0) scale(1); opacity: 0; }
  100% { transform: translate(0, 0) scale(1); opacity: 1; }
}
.anim-drag { animation: dragTile 3.5s ease-in-out infinite; }

/* PC版ドラッグのカーソル - tut-hand内の相対位置 */
@keyframes dragCursorRel {
  0%   { transform: translate(0, 0); }
  15%  { transform: translate(0, -8px); }
  50%  { transform: translate(120px, -80px); }
  65%  { transform: translate(120px, -80px); }
  80%  { transform: translate(120px, -80px); opacity: 0; }
  81%  { transform: translate(0, 0); opacity: 0; }
  100% { transform: translate(0, 0); opacity: 1; }
}
.anim-drag-cursor {
  position: absolute;
  left: 10px;
  top: 10px;
  font-size: 2rem;
  animation: dragCursorRel 3.5s ease-in-out infinite;
}

/* --- Step 2 Mobile: タップ (選択 → 移動) --- */
@keyframes tapSelect {
  0%, 10%  { outline: 1px solid #c9bda8; box-shadow: none; }
  20%, 60% { outline: 3px solid #fdd835; box-shadow: 0 0 10px rgba(253,216,53,0.6); }
  70%      { transform: translateY(-60px); opacity: 0; }
  71%      { transform: translateY(0); opacity: 0; }
  100%     { transform: translateY(0); opacity: 1; outline: 1px solid #c9bda8; box-shadow: none; }
}
.anim-tap { animation: tapSelect 4s ease-in-out infinite; }

/* スマホ版タップ指 — 親要素(タイル)に対する相対位置 */
@keyframes tapFingerRel {
  0%   { transform: translate(8px, 30px); opacity: 0; }
  5%   { transform: translate(8px, 30px); opacity: 1; }
  15%  { transform: translate(8px, 30px); opacity: 1; font-size: 1.8rem; }
  20%  { transform: translate(8px, 30px); opacity: 1; font-size: 2rem; }
  35%  { transform: translate(8px, -40px); opacity: 1; }
  45%  { transform: translate(8px, -40px); opacity: 1; font-size: 1.8rem; }
  50%  { transform: translate(8px, -40px); opacity: 0; }
  100% { transform: translate(8px, 30px); opacity: 0; }
}
.anim-tap-finger-rel {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 2rem;
  z-index: 100;
  pointer-events: none;
  filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.5));
  animation: tapFingerRel 4s ease-in-out infinite;
}

/* --- Step 3: 複数選択 --- */
@keyframes multiSelect1 { 0%,15% { outline: 1px solid #c9bda8; box-shadow: none; } 20%,90% { outline: 3px solid #fdd835; box-shadow: 0 0 8px rgba(239, 216, 53, 0.8); } 100% { outline: 1px solid #c9bda8; box-shadow: none; } }
@keyframes multiSelect2 { 0%,30% { outline: 1px solid #c9bda8; box-shadow: none; } 35%,90% { outline: 3px solid #fdd835; box-shadow: 0 0 8px rgba(239, 216, 53, 0.8); } 100% { outline: 1px solid #c9bda8; box-shadow: none; } }
@keyframes multiSelect3 { 0%,45% { outline: 1px solid #c9bda8; box-shadow: none; } 50%,90% { outline: 3px solid #fdd835; box-shadow: 0 0 8px rgba(239, 216, 53, 0.8); } 100% { outline: 1px solid #c9bda8; box-shadow: none; } }
.anim-multi-1 { animation: multiSelect1 4s ease-in-out infinite; }
.anim-multi-2 { animation: multiSelect2 4s ease-in-out infinite; }
.anim-multi-3 { animation: multiSelect3 4s ease-in-out infinite; }

/* PC版の選択範囲ボックス — タイル3枚を囲む (親div内) */
@keyframes rectGrowFixed {
  0%, 10% { width: 0; height: 0; opacity: 0; transform: translate(0, 50px); }
  25%     { width: 114px; height: 48px; opacity: 1; transform: translate(-4px, -3px); }
  85%     { width: 114px; height: 48px; opacity: 1; transform: translate(-4px, -3px); }
  100%    { width: 0; height: 0; opacity: 0; transform: translate(0, 50px); }
}
.anim-rect {
  position: absolute;
  left: 0;
  top: 0;
  border: 3px solid #4fc3f7;
  background: rgba(79, 195, 247, 0.15);
  border-radius: 4px;
  animation: rectGrowFixed 4s ease-in-out infinite;
  pointer-events: none;
  z-index: 10;
}

/* --- Step 4 PC: ズーム --- */
@keyframes zoomPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.4); }
}
.anim-zoom { animation: zoomPulse 2.5s ease-in-out infinite; }

@keyframes btnGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(79,195,247,0); }
  50%      { box-shadow: 0 0 15px rgba(79,195,247,0.7); }
}
.anim-glow { animation: btnGlow 2s ease-in-out infinite; }

/* --- Step 5 PC: ソート（バラバラ → 整列） --- */
/* tiles in tut-board row should align perfectly horizontally */
@keyframes sortA {
  0%, 30%  { transform: translate(-54px, 10px); }
  50%, 100% { transform: translate(18px, 0); }
}
@keyframes sortB {
  0%, 30%  { transform: translate(-18px, -10px); }
  50%, 100% { transform: translate(-18px, 0); }
}
@keyframes sortC {
  0%, 30%  { transform: translate(18px, 10px); }
  50%, 100% { transform: translate(-54px, 0); }
}
@keyframes sortD {
  0%, 30%  { transform: translate(54px, -10px); }
  50%, 100% { transform: translate(54px, 0); }
}
.anim-sort-a { animation: sortA 3s ease-in-out infinite alternate; left: 50%; top: 4px; margin-left: -16px; }
.anim-sort-b { animation: sortB 3s ease-in-out infinite alternate; left: 50%; top: 4px; margin-left: -16px; }
.anim-sort-c { animation: sortC 3s ease-in-out infinite alternate; left: 50%; top: 4px; margin-left: -16px; }
.anim-sort-d { animation: sortD 3s ease-in-out infinite alternate; left: 50%; top: 4px; margin-left: -16px; }

/* --- Step 4 Mobile: パネルボタン光る --- */
@keyframes panelHighlight {
  0%, 100% { background: var(--tut-surface); }
  50%      { background: #e3f2fd; box-shadow: 0 0 12px rgba(79,195,247,0.5); }
}
.anim-panel-1 { animation: panelHighlight 2s ease-in-out 0s infinite; }
.anim-panel-2 { animation: panelHighlight 2s ease-in-out 0.5s infinite; }
.anim-panel-3 { animation: panelHighlight 2s ease-in-out 1s infinite; }

.tut-panel-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--tut-border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--tut-text);
  width: 100%;
}

.tut-panel-btn .icon { font-size: 1.2rem; }

/* ============================
   レスポンシブ
   ============================ */

/* スマホ横向き */
@media (max-height: 480px) {
  body { padding: 0.5rem; }
  .tutorial-container { padding: 1rem; }
  .tutorial-header { font-size: 1rem; margin-bottom: 0.8rem; }
  .step-animation { min-height: 120px; padding: 0.5rem; }
  .step-desc { font-size: 0.8rem; margin-bottom: 0.8rem; line-height: 1.4; }
  .tut-tile { width: 24px; height: 32px; font-size: 0.75rem; }
  .tut-cursor { font-size: 1.8rem; }
  .anim-tap-finger-rel { font-size: 1.5rem; }
}

/* 小さいスマホ */
@media (max-width: 480px) {
  .tutorial-container { padding: 1.2rem; }
  .step-animation { min-height: 150px; }
  .tut-tile { width: 28px; height: 36px; font-size: 0.85rem; }
}
