/* ============================
   スマートフォンモード専用CSS
   横向き（Landscape）前提の1画面レイアウト
   ============================ */

/* --- CSS Variables (PC版から踏襲) --- */
:root {
  --bg-primary: #c8e6c9;
  --bg-secondary: #a5d6a7;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f8e9;
  --surface: #ffffff;
  --surface-light: #e8f5e9;

  --accent-primary: #4fc3f7;
  --accent-primary-hover: #81d4fa;
  --accent-secondary: #ff8a65;
  --accent-glow: rgba(79, 195, 247, 0.3);

  --tile-red: #ef5350;
  --tile-blue: #42a5f5;
  --tile-black: #455a64;
  --tile-orange: #ffa726;

  --text-primary: #1b5e20;
  --text-secondary: #388e3c;
  --text-muted: #81c784;

  --border-subtle: rgba(27, 94, 32, 0.15);
  --shadow-lg: 0 20px 60px rgba(27, 94, 32, 0.15);
  --shadow-md: 0 8px 30px rgba(27, 94, 32, 0.1);
  --shadow-sm: 0 2px 10px rgba(27, 94, 32, 0.05);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: #2a1811;
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* ============================
   全体レイアウト（CSS Grid）
   ┌─────────────────────┬──────┐
   │      ヘッダー        │      │
   ├─────────────────────┤ 右   │
   │      場エリア        │ パネ │
   │                     │ ル   │
   ├─────────────────────┴──────┤
   │         手札バー            │
   └────────────────────────────┘
   ============================ */
.mobile-layout {
  display: grid;
  grid-template-columns: 1fr 52px;
  grid-template-rows: 28px 1fr 54px;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* ============================
   ヘッダー
   ============================ */
.mobile-header {
  grid-column: 1 / 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 10;
}

.mobile-header .btn-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}

.mobile-header .badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.mobile-header .badge.joker-on {
  background: rgba(255, 138, 101, 0.15);
  color: var(--accent-secondary);
  border: 1px solid rgba(255, 138, 101, 0.3);
}

.mobile-header .stock-badge {
  background: rgba(255, 255, 255, 0.8);
  color: #2e7d32;
  border: 1px solid rgba(76, 175, 80, 0.4);
}

/* ============================
   右パネル（ボタン集約）
   ============================ */
.right-panel {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 1px 2px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  gap: 0;
  overflow: hidden;
}

.btn-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px 0;
  width: 100%;
}

.btn-group + .btn-group {
  border-top: 1px solid var(--border-subtle);
}

.btn-group-label {
  font-size: 0.45rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* --- 丸型アイコンボタン --- */
.circle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1.5px solid var(--border-subtle);
  background: var(--surface);
  cursor: pointer;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
  flex-shrink: 0;
  position: relative;
}

.circle-btn:active {
  transform: scale(0.92);
}

/* サイズバリエーション */
.circle-btn.btn-sm {
  width: 30px;
  height: 30px;
  font-size: 0.75rem;
}

.circle-btn.btn-md {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
}

/* ドローボタン（緑色） */
.circle-btn.draw-btn {
  background: linear-gradient(135deg, #4caf50, #388e3c);
  border-color: #2e7d32;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(56, 142, 60, 0.4);
}

.circle-btn.draw-btn:active {
  box-shadow: 0 1px 3px rgba(56, 142, 60, 0.3);
}

/* ドローボタンのバッジ（+1, +3, +5） */
.draw-badge {
  position: absolute;
  bottom: -2px;
  right: -4px;
  background: #fff;
  color: #2e7d32;
  font-size: 0.45rem;
  font-weight: 800;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #2e7d32;
  line-height: 1;
}

/* ソートボタン（数字表示） */
.circle-btn.sort-btn {
  font-size: 0.55rem;
  font-weight: 900;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1;
}

/* ユーティリティボタン（アイコン表示） */
.circle-btn.util-btn {
  font-size: 0.9rem;
}

/* ============================
   場エリア
   ============================ */
.mobile-field {
  grid-column: 1;
  grid-row: 2;
  padding: 6px 8px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.mobile-field-sets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: flex-start;
  align-content: flex-start;
}

/* --- セット --- */
.field-set {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 4px;
  background: var(--surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: 5px;
  min-height: 42px;
}

.field-set.invalid {
  border-color: rgba(239, 83, 80, 0.6);
  background: rgba(239, 83, 80, 0.08);
}

.field-set-label {
  font-size: 0.5rem;
  color: var(--text-muted);
  margin-right: 2px;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  line-height: 1;
  opacity: 0.7;
}

.field-set-type {
  font-size: 0.45rem;
  color: var(--text-muted);
  margin-left: 3px;
  flex-shrink: 0;
  opacity: 0.5;
}

/* ============================
   タイル（共通）
   ============================ */
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 38px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 800;
  color: #333;
  user-select: none;
  position: relative;
  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 2px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: outline var(--transition-fast);
}

/* タイルカラー */
.tile.tile-red { color: #d32f2f; }
.tile.tile-blue { color: #1976d2; }
.tile.tile-black { color: #212121; }
.tile.tile-orange { color: #f57c00; }
.tile.tile-joker { color: #7b1fa2; font-size: 1rem; }

/* タイル選択状態 (引いた直後の緑よりも優先するため !important を付与) */
.tile.selected {
  outline: 3px solid #fdd835 !important;
  outline-offset: 1px;
  box-shadow: 0 0 10px rgba(253, 216, 53, 0.6) !important;
  z-index: 50;
}

/* タイル引いた直後のハイライト (選択中と区別するためグリーンに変更) */
.tile.just-drawn {
  border-color: #4caf50 !important;
  outline: 2px solid #4caf50;
  outline-offset: 1px;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.4);
}

/* --- Compact タイル --- */
.compact-tiles .tile {
  width: 24px;
  height: 32px;
  font-size: 0.72rem;
  border-radius: 3px;
}

.compact-tiles .field-set {
  gap: 1px;
  padding: 2px 3px;
  min-height: 36px;
}

/* --- Tiny タイル --- */
.tiny-tiles .tile {
  width: 20px;
  height: 28px;
  font-size: 0.62rem;
  border-radius: 3px;
}

.tiny-tiles .field-set {
  gap: 1px;
  padding: 2px 2px;
  min-height: 32px;
}

/* ============================
   手札バー
   ============================ */
.hand-bar {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: linear-gradient(180deg, #442410, #5c351b);
  border-top: 3px solid #3c200c;
  overflow-x: auto;
  overflow-y: hidden;
}

.hand-tiles {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 0;
}

.hand-tiles::-webkit-scrollbar {
  height: 3px;
}
.hand-tiles::-webkit-scrollbar-track {
  background: transparent;
}
.hand-tiles::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}

.hand-count {
  font-size: 0.6rem;
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 35px;
  text-align: right;
}

/* 縦向き設定: オーバーレイを消し、レイアウトを許可 */
@media (orientation: portrait) {
  .mobile-layout {
    grid-template-columns: 1fr 48px; /* パネルを少し狭く */
  }
}

/* ============================
   モーダル（設定・通知・クリア）
   ============================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  width: 100%;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
}

.modal-heading {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #039be5);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* 設定行 */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  cursor: pointer;
}

.setting-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* トグルスイッチ */
.toggle-switch { position: relative; flex-shrink: 0; }
.toggle-input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  display: block; width: 44px; height: 24px;
  background: #a5d6a7; border-radius: 20px;
  position: relative; cursor: pointer;
  transition: background-color var(--transition-fast);
}
.toggle-thumb {
  display: block; width: 18px; height: 18px;
  background: #fff; border-radius: 50%;
  position: absolute; top: 3px; left: 3px;
  transition: transform var(--transition-fast);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-input:checked + .toggle-track {
  background: var(--accent-primary);
}
.toggle-input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
}

/* セット数ボタン */
.set-count-options {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  width: 100%;
}

.set-count-btn {
  flex: 1;
  min-width: 36px;
  padding: 0.3rem 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.set-count-btn.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

/* ============================
   新規セット追加ゾーン（タップ操作用）
   ============================ */
.new-set-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 42px;
  border: 2px dashed rgba(79, 195, 247, 0.4);
  border-radius: 5px;
  color: var(--accent-primary);
  font-size: 1.2rem;
  opacity: 0;
  transition: opacity var(--transition-fast);
  cursor: pointer;
}

/* タイル選択中のみ表示 */
.has-selection .new-set-zone {
  opacity: 1;
}

/* ============================
   設定画面
   ============================ */
.mobile-settings-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background: var(--bg-primary);
  padding: 1rem;
}

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.2rem 1.5rem;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
}

/* 言語ボタン */
.lang-btn {
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--text-secondary);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.lang-btn.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

/* ジョーカーオフバッジ */
.badge.joker-off {
  background: rgba(158, 158, 158, 0.15);
  color: #9e9e9e;
  border: 1px solid rgba(158, 158, 158, 0.3);
}

/* 通知ダイアログ */
.notify-dialog {
  text-align: center;
  max-width: 300px;
}

.notify-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.notify-message {
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text-primary);
}

/* 場エリアの背景色 */
.mobile-field {
  background: var(--bg-primary);
}
