/* ─── 自動計番 v3 ─── */
.auto-calc-section {
  margin-top: 1.5rem;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.ac-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.ac-head h3 { margin: 0.25rem 0; font-size: 1.1rem; color: var(--ink); }
.ac-head .eyebrow { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 0; }
.ac-head p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }

/* ─── 手牌顯示區（頂部） ─── */
.ac-hand-display {
  margin-bottom: 1rem;
  padding: 0.8rem;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--soft);
}
.ac-hand-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.ac-hand-head h4 { margin: 0; font-size: 0.9rem; color: var(--ink); }
.ac-tile-counter {
  font-size: 0.85rem; font-weight: bold; color: var(--muted);
  padding: 0.15rem 0.5rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.ac-counter-full { color: var(--accent); border-color: var(--accent); background: var(--soft); }
.ac-counter-over { color: var(--red); border-color: var(--red); }
.ac-hand-tiles {
  display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center;
  min-height: 50px; padding: 0.3rem 0;
}
.ac-hand-hint { color: var(--muted); font-size: 0.85rem; opacity: 0.6; }
.ac-hand-label {
  font-size: 0.65rem; color: var(--accent-strong); background: var(--panel);
  border: 1px solid var(--line); border-radius: 4px; padding: 0.1rem 0.3rem;
  margin-right: 0.2rem; font-weight: bold;
}
.ac-hand-label-flower { color: var(--gold); border-color: rgba(178, 139, 48, 0.3); }
.ac-hand-tile {
position: relative; display: inline-flex;
}
.ac-hand-tile-click {
cursor: pointer;
transition: transform 0.1s, opacity 0.1s;
}
.ac-hand-tile-click:hover {
transform: translateY(-3px);
opacity: 0.7;
}
.ac-hand-tile-click:active {
transform: scale(0.9);
}
.ac-hand-display .mahjong-tile,
.ac-hand-tiles .mahjong-tile {
  width: 48px !important; height: 62px !important;
  flex: 0 0 auto !important;
}
.ac-hand-tile .mahjong-tile img,
.ac-hand-display .mahjong-tile img {
  width: 100%; height: 100%; object-fit: contain;
}
.ac-hand-tile .ac-tile-remove {
  position: absolute; top: -6px; right: -6px;
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff; border: none; border-radius: 50%;
  font-size: 0.6rem; cursor: pointer; line-height: 1; padding: 0;
  opacity: 0; transition: opacity 0.15s;
}
.ac-hand-tile:hover .ac-tile-remove { opacity: 1; }
.ac-hand-meld {
  display: inline-flex; flex-direction: column; align-items: center;
  gap: 1px; margin: 0 0.15rem;
}
.ac-hand-meld-type { font-size: 0.55rem; color: var(--muted); }
.ac-hand-note { margin: 0.4rem 0 0; font-size: 0.75rem; color: var(--muted); text-align: center; }
.ac-note-ready { color: var(--accent); font-weight: bold; }

/* ─── 模式切換 ─── */
.ac-mode-toggle { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.ac-mode-label {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.9rem; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; font-size: 0.85rem; background: var(--bg); color: var(--ink); transition: all 0.15s;
}
.ac-mode-label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }
.ac-mode-label input { display: none; }

/* ─── 選牌器 ─── */
.ac-tile-picker {
  display: flex; flex-direction: column; gap: 0.3rem;
  margin-bottom: 1rem; padding: 0.6rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.ac-picker-row {
  display: flex; flex-wrap: wrap; gap: 0.25rem;
}
.ac-picker-tile {
  position: relative; display: inline-flex; flex-direction: column; align-items: center;
  padding: 2px; border: 2px solid transparent; border-radius: 6px;
  background: var(--tile); cursor: pointer; transition: all 0.15s;
  min-height: auto; /* override global button min-height: 44px */
}
.ac-tile-picker .mahjong-tile {
  width: 48px !important; height: 62px !important;
  flex: 0 0 auto !important;
}
.ac-tile-picker .mahjong-tile img {
width: 100%; height: 100%; object-fit: contain;
}
.ac-picker-tile:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.ac-picker-tile.ac-picker-active { border-color: var(--accent); background: var(--soft); }
.ac-picker-tile.ac-picker-max { opacity: 0.4; cursor: not-allowed; }
.ac-picker-tile.ac-picker-max:hover { transform: none; box-shadow: none; }
.ac-picker-count {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-size: 0.6rem; font-weight: bold;
  border-radius: 50%; line-height: 1;
}

/* ─── 放置區域 ─── */
.ac-zones { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 1rem; }
.ac-zone {
  padding: 0.6rem; border: 1px dashed var(--line); border-radius: 8px;
  min-height: 56px; background: var(--panel);
}
.ac-zone h4 { margin: 0 0 0.4rem; font-size: 0.85rem; color: var(--ink); }
.ac-zone h4 small { color: var(--muted); font-weight: normal; }
.ac-zone-tiles {
  display: flex; flex-wrap: wrap; gap: 0.25rem; min-height: 44px; align-items: center;
}
.ac-zone-hint { color: var(--muted); font-size: 0.8rem; opacity: 0.6; }
.ac-zone-suit-label {
  font-size: 0.65rem; color: var(--accent-strong); background: var(--panel);
  border: 1px solid var(--line); border-radius: 4px; padding: 0.1rem 0.3rem;
  margin-right: 0.2rem; font-weight: bold;
}
.ac-tile-wrapper { position: relative; display: inline-flex; }
.ac-zones .mahjong-tile {
  width: 48px !important; height: 62px !important;
  flex: 0 0 auto !important;
}
.ac-zones .mahjong-tile img {
width: 100%; height: 100%; object-fit: contain;
}
.ac-tile-remove {
  position: absolute; top: -6px; right: -6px;
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff; border: none; border-radius: 50%;
  font-size: 0.6rem; cursor: pointer; line-height: 1; padding: 0;
  opacity: 0; transition: opacity 0.15s;
}
.ac-tile-wrapper:hover .ac-tile-remove { opacity: 1; }

/* ─── 明牌組合 ─── */
.ac-meld-group {
  position: relative; display: inline-flex; align-items: center; gap: 2px;
  padding: 0.3rem; border: 1px solid var(--line); border-radius: 6px; background: var(--tile);
}
.ac-meld-group .mahjong-tile {
  width: 48px !important; height: 62px !important;
  flex: 0 0 auto !important;
}
.ac-meld-group .mahjong-tile img {
width: 100%; height: 100%; object-fit: contain;
}
.ac-meld-type { font-size: 0.6rem; color: var(--muted); margin-bottom: 2px; }

/* ─── 條件選項 ─── */
.ac-conditions { margin-bottom: 1rem; }
.ac-conditions h4 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--ink); }
.ac-cond-grid { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.ac-cond-item { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; color: var(--ink); cursor: pointer; }
.ac-cond-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.ac-cond-item select {
  padding: 0.2rem 0.4rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--ink); font-size: 0.8rem;
}

/* ─── 結果區域 ─── */
.ac-result { border-top: 1px solid var(--line); padding-top: 1rem; }
.ac-result-total { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.8rem; }
.ac-result-total > span { font-size: 0.85rem; color: var(--muted); }
.ac-result-total > strong { font-size: 2rem; font-weight: bold; color: var(--accent); }
.ac-result-total > p { margin: 0; font-size: 0.8rem; color: var(--muted); }
.ac-result-patterns { display: flex; flex-direction: column; gap: 0.5rem; }
.ac-result-empty { color: var(--muted); font-size: 0.85rem; margin: 0; opacity: 0.6; }
.ac-calling-section { padding: 0.5rem; }
.ac-calling-section h4 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--text); }
.ac-calling-tiles { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.ac-calling-tile { display: inline-block; padding: 0.2rem 0.4rem; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; font-size: 0.8rem; }
.ac-result-group { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.ac-result-group-title { margin: 0; padding: 0.3rem 0.6rem; background: var(--bg); font-size: 0.75rem; color: var(--muted); }
.ac-result-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 0.6rem; border-top: 1px solid var(--line);
}
.ac-result-row:first-of-type { border-top: none; }
.ac-result-name { font-size: 0.85rem; color: var(--ink); }
.ac-result-fan { font-size: 0.85rem; font-weight: bold; color: var(--accent); white-space: nowrap; }

/* ─── 花牌區 ─── */
.ac-zone-flowers { border-color: var(--gold); border-style: solid; }

/* ─── 響應式 ─── */
@media (max-width: 480px) {
  .ac-mode-toggle { flex-direction: column; }
  .ac-cond-grid { flex-direction: column; }

  .ac-tile-picker { padding: 0.3rem; }
  .ac-picker-row { 
    gap: 0; 
    justify-content: space-between;
  }
  .ac-picker-tile { 
    padding: 1px; 
    border-width: 1.5px;
    flex: 1 1 0;
    max-width: calc(100% / 9);
  }

  /* tile-image: 142:185 ratio */
  .ac-tile-picker .mahjong-tile.tile-image {
    width: 40px !important;
    height: auto !important;
    min-height: 60px !important;
    flex: 0 0 40px !important;
    overflow: visible !important;
  }
  .ac-hand-display .mahjong-tile.tile-image,
  .ac-hand-tiles .mahjong-tile.tile-image,
  .ac-zones .mahjong-tile.tile-image,
  .ac-meld-group .mahjong-tile.tile-image {
    width: 40px !important;
    height: 58px !important;
    flex: 0 0 40px !important;
    overflow: hidden !important;
  }
  .ac-tile-picker .mahjong-tile.tile-image img,
  .ac-hand-display .mahjong-tile.tile-image img,
  .ac-hand-tiles .mahjong-tile.tile-image img,
  .ac-zones .mahjong-tile.tile-image img,
  .ac-meld-group .mahjong-tile.tile-image img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
  }

  /* tile-sprite: 31:45 ratio */
  .ac-tile-picker .mahjong-tile.tile-sprite {
    width: 32px !important;
    height: auto !important;
    min-height: 55px !important;
    flex: 0 0 32px !important;
    overflow: visible !important;
  }
  .ac-hand-display .mahjong-tile.tile-sprite,
  .ac-hand-tiles .mahjong-tile.tile-sprite,
  .ac-zones .mahjong-tile.tile-sprite,
  .ac-meld-group .mahjong-tile.tile-sprite {
    width: 32px !important;
    height: 52px !important;
    flex: 0 0 32px !important;
    overflow: hidden !important;
  }
  .ac-tile-picker .mahjong-tile.tile-sprite img,
  .ac-hand-display .mahjong-tile.tile-sprite img,
  .ac-hand-tiles .mahjong-tile.tile-sprite img,
  .ac-zones .mahjong-tile.tile-sprite img,
  .ac-meld-group .mahjong-tile.tile-sprite img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
  }

  /* base mahjong-tile (no class) */
  .ac-tile-picker .mahjong-tile:not(.tile-image):not(.tile-sprite) {
    width: 32px !important;
    height: 58px !important;
    flex: 0 0 32px !important;
  }
  .ac-hand-display .mahjong-tile:not(.tile-image):not(.tile-sprite),
  .ac-hand-tiles .mahjong-tile:not(.tile-image):not(.tile-sprite),
  .ac-zones .mahjong-tile:not(.tile-image):not(.tile-sprite),
  .ac-meld-group .mahjong-tile:not(.tile-image):not(.tile-sprite) {
    width: 32px !important;
    height: 52px !important;
    flex: 0 0 32px !important;
  }
}

/* 食糊牌按鈕 */
.ac-tile-win-btn {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 10px;
  padding: 1px 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.ac-tile-wrapper:hover .ac-tile-win-btn {
  opacity: 1;
}
.ac-tile-win-btn:hover {
  background: #c0392b;
}

/* 食糊牌顯示 */
.ac-hand-tile-win {
  border: 2px solid #e74c3c !important;
  box-shadow: 0 0 8px rgba(231, 76, 60, 0.5);
  position: relative;
}
.ac-hand-tile-win::after {
  content: "糊";
  position: absolute;
  top: -8px;
  right: -8px;
  background: #e74c3c;
  color: white;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 4px;
}
