/* ==========================================================
   Brand Kochi 2D MMORPG - Master CSS
   Path: public/css/style.css
   ========================================================== */

:root {
  --bg-dark: #070a0f;
  --bg-panel: rgba(11, 15, 23, 0.85);
  --bg-panel-solid: #0d121c;
  --accent-gold: #c59b27;
  --accent-gold-light: #dfb743;
  --accent-blue: #0ea5e9;
  --accent-cyan: #38bdf8;
  --accent-green: #2ecc71;
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --border-gold: rgba(197, 155, 39, 0.4);
  --font-mincho: "Shippori Mincho", "Hiragino Mincho ProN", serif;
  --font-sans: "Inter", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* フォーム要素はスマホで確実に文字選択・タッチ入力できるように解放 */
input, textarea, select {
  user-select: text !important;
  -webkit-user-select: auto !important;
  -webkit-touch-callout: default !important;
  touch-action: manipulation !important;
  font-size: 16px !important; /* iOS自動ズーム防止 */
}

button {
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation !important;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-sans);
  color: var(--text-main);
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ==========================================================
   HUD Header (Top Navigation)
   ========================================================== */
#hud-header {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 30;
  pointer-events: none;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border-gold);
  padding: 8px 16px;
  border-radius: 20px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 8px #2ecc71;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.brand-logo-text {
  font-family: var(--font-mincho);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.05em;
  color: var(--accent-gold-light);
}

.online-counter {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-left: 4px;
}

/* 🪙 所持金ステータスバーバッジ */
.wallet-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(18, 24, 36, 0.9);
  border: 1.5px solid var(--accent-gold);
  color: var(--accent-gold-light);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 6px 14px;
  border-radius: 20px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 8px rgba(197, 155, 39, 0.3);
  letter-spacing: 0.03em;
}

.hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.hud-btn {
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
}
.hud-btn:hover {
  border-color: var(--accent-gold);
  background: rgba(197, 155, 39, 0.15);
  color: var(--accent-gold-light);
}

/* ==========================================================
   Modals (Customizer, Help, Mobile Chat, Start Modal, Shop)
   ========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}
.modal-overlay.active {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--bg-panel-solid);
  border: 1.5px solid var(--accent-gold);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100dvh - 36px);
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(197, 155, 39, 0.25);
  pointer-events: auto;
  box-sizing: border-box;
  overflow: hidden;
}

.modal-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(223, 183, 67, 0.3);
  padding-bottom: 8px;
  flex-shrink: 0;
}

.modal-header-bar .modal-title {
  margin: 0;
  border-bottom: none;
  padding-bottom: 0;
  text-align: left;
  font-size: 1.15rem;
}

.modal-top-close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.modal-top-close-btn:hover, .modal-top-close-btn:active {
  background: #ef4444;
  border-color: #ef4444;
}

.modal-body-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 4px;
  margin-bottom: 8px;
}

.modal-title {
  font-family: var(--font-mincho);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-gold-light);
  margin-bottom: 14px;
  text-align: center;
  border-bottom: 1px solid rgba(223, 183, 67, 0.3);
  padding-bottom: 8px;
  flex-shrink: 0;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px;
}

.modal-actions {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: #080c14;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  font-size: 16px !important; /* iOSズーム防止 */
  user-select: text !important;
  -webkit-user-select: auto !important;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent-gold);
  background: #0d1420;
}

.avatar-preview-box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 90px;
  background: #080c14;
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  margin-bottom: 16px;
}

.avatar-preview-canvas {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.option-pill {
  background: #0d1420;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 6px;
  border-radius: 6px;
  text-align: center;
  font-size: 0.82rem;
  cursor: pointer;
}
.option-pill.active {
  background: rgba(197, 155, 39, 0.25);
  border-color: var(--accent-gold);
  color: var(--accent-gold-light);
  font-weight: 600;
}

.color-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s;
}
.color-dot.active {
  border-color: #ffffff;
  transform: scale(1.15);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-gold) 0%, #8c6b12 100%);
  color: #070a0f;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-primary:hover {
  background: var(--accent-gold-light);
  box-shadow: 0 4px 12px rgba(197, 155, 39, 0.4);
}

/* Mobile Dedicated Chat Modal Box */
.mobile-chat-box {
  max-width: 420px;
  padding: 20px;
}
.mobile-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.quick-phrases {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.quick-phrase-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 16px;
  cursor: pointer;
}
.quick-phrase-btn:active {
  background: var(--accent-gold);
  color: #000;
}
.mobile-emote-selector {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
  margin-bottom: 12px;
}
.mobile-emote-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 1.4rem;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

/* ==========================================================
   Mobile Controls & Responsive Optimization (スマホ完全対応)
   ========================================================== */
#mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  display: none;
}

@media (max-width: 900px), (pointer: coarse) {
  #mobile-controls {
    display: block;
  }
  
  #hud-header {
    top: max(6px, env(safe-area-inset-top));
    left: 6px;
    right: 6px;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    z-index: 35;
  }

  .brand-badge {
    padding: 3px 6px;
    border-radius: 12px;
    gap: 4px;
    flex-shrink: 1;
    overflow: hidden;
  }
  .brand-logo-text {
    font-size: 0.75rem;
    white-space: nowrap;
  }
  .online-counter {
    display: none; /* スマホでは接続数テキストを非表示にして省スペース化 */
  }

  #playerHpContainer {
    padding: 2px 6px !important;
    gap: 4px !important;
    flex-shrink: 0;
  }
  #playerHpContainer div {
    width: 44px !important;
  }
  #playerHpText {
    font-size: 0.68rem !important;
  }

  .wallet-badge {
    padding: 3px 6px !important;
    font-size: 0.75rem !important;
    border-radius: 12px !important;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .hud-actions {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
  }
  .hud-btn {
    padding: 4px 6px !important;
    font-size: 0.72rem !important;
    border-radius: 6px !important;
    white-space: nowrap;
  }
  /* スマホで余分なボタンを非表示・アイコン化 */
  #btnAudioToggle {
    display: none; /* 音声切り替えはガイド内に集約し省スペース化 */
  }

  /* 🗺️ ミニマップ（スマホでは右上にコンパクトに収める） */
  #minimapContainer {
    top: max(44px, calc(env(safe-area-inset-top) + 38px)) !important;
    right: 6px !important;
    width: 104px !important;
    height: 80px !important;
    z-index: 20 !important;
  }
  #minimapCanvas {
    width: 100px !important;
    height: 76px !important;
  }
}

#joystick-zone {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 14px;
  width: 100px;
  height: 100px;
  pointer-events: auto;
}

.joystick-base {
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  position: relative;
  backdrop-filter: blur(4px);
}

.joystick-stick {
  width: 40px;
  height: 40px;
  background: radial-gradient(circle, var(--accent-gold-light) 0%, var(--accent-gold) 100%);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px rgba(197, 155, 39, 0.5);
  pointer-events: none;
}

.mobile-action-btns {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.mobile-act-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1.5px solid var(--accent-gold);
  color: #fff;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  cursor: pointer;
  touch-action: manipulation !important;
}
