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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-emphasis: #1f6feb;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 480px;
  margin: 0 auto;
  padding: 8px;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

header { text-align: center; padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
header h1 { font-size: 18px; color: var(--text); font-weight: 600; }

/* PT登録 */
#team-section { margin-bottom: 10px; }

.team-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}

.team-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.team-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.team-actions {
  display: flex;
  gap: 4px;
}

.team-slots { display: flex; gap: 4px; margin-bottom: 8px; }

.slot {
  flex: 1;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.slot:hover { border-color: var(--text-secondary); }

.slot.filled {
  border-color: var(--border);
  font-size: 10px;
  color: var(--text);
  word-break: break-all;
  line-height: 1.2;
  padding: 2px;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

.slot-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.15s;
}
.slot-delete svg { width: 10px; height: 10px; }
.slot:hover .slot-delete,
.slot:focus-within .slot-delete { opacity: 1; }

.slot.selected-atk { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(248,81,73,0.3); }
.slot.selected-def { border-color: var(--success); box-shadow: 0 0 0 2px rgba(63,185,80,0.3); }
.slot.drop-target { border-color: var(--accent); border-style: dashed; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: border-color 0.15s;
}
.icon-btn svg { width: 16px; height: 16px; stroke: var(--text-secondary); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { border-color: var(--text-secondary); }
.icon-btn:hover svg { stroke: var(--text); }
.team-clear-btn:hover svg { stroke: var(--danger); }
.team-clear-btn:hover { border-color: var(--danger); }

/* インライン検索 */
.team-search-wrapper {
  position: relative;
}

.team-search {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.team-search::placeholder { color: var(--text-tertiary); }
.team-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.3); }

.team-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.team-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.team-search-item:last-child { border-bottom: none; }
.team-search-item:hover, .team-search-item.highlighted {
  background: var(--surface2);
}
.team-search-item .item-name { font-weight: 500; }
.team-search-item .item-stats {
  font-size: 10px;
  color: var(--text-secondary);
  margin-left: 8px;
}
.team-search-item .item-types {
  display: flex;
  gap: 3px;
  margin-left: auto;
  flex-shrink: 0;
}

/* 攻防パネル */
#battle-section { margin-bottom: 10px; }

.battle-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.battle-side {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.side-label {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#attacker-panel .side-label { color: var(--danger); }
#defender-panel .side-label { color: var(--success); }

.pokemon-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.pokemon-sprite {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
  flex-shrink: 0;
  background: var(--surface2);
  border-radius: 50%;
}

.pokemon-header-info { flex: 1; min-width: 0; }

.pokemon-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pokemon-types { display: flex; gap: 4px; }

.base-stats {
  display: flex;
  gap: 3px;
  margin-bottom: 6px;
  font-size: 9px;
  color: var(--text-secondary);
}
.bs-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 1px;
}
.bs-label { font-weight: 600; color: var(--text-tertiary); }
.bs-val { font-weight: 600; color: var(--text); font-size: 10px; }

.type-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 12px;
  color: #fff;
  font-weight: 600;
}

.mega-toggle {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  margin-bottom: 6px;
  transition: background 0.15s;
}
.mega-toggle:hover { background: rgba(88,166,255,0.1); }
.mega-toggle.active { background: var(--accent-emphasis); color: #fff; border-color: var(--accent-emphasis); }

.stat-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.stat-row label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text);
  width: 100%;
  font-weight: 500;
}
.hint {
  font-size: 9px;
  color: var(--text-tertiary);
  font-weight: normal;
  margin-left: 2px;
}
.stat-row input[type="number"] {
  width: 48px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 3px 4px;
  font-size: 12px;
  text-align: center;
}
.stat-row input[type="number"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.3); }
.stat-row select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 3px 4px;
  font-size: 12px;
}
.stat-row select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.3); }

#swap-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 18px;
  padding: 8px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  align-self: center;
  margin-top: 20px;
  transition: border-color 0.15s, color 0.15s;
}
#swap-btn:hover { border-color: var(--text-secondary); color: var(--text); }

/* 技セクション */
#move-section { margin-bottom: 10px; }

.move-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.move-btn {
  padding: 5px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}
.move-btn:hover { border-color: var(--text-secondary); background: var(--surface2); }
.move-btn.selected { border-color: var(--accent); background: var(--accent-emphasis); color: #fff; }

.move-search-wrapper { position: relative; }

#move-search {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
#move-search::placeholder { color: var(--text-tertiary); }
#move-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.3); }

.move-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.move-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.move-dropdown-item:last-child { border-bottom: none; }
.move-dropdown-item:hover, .move-dropdown-item.highlighted {
  background: var(--surface2);
}

.move-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  padding: 0 4px;
}

/* オプション */
#options-section {
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
}
.option-check {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--text-secondary);
}
.option-check input[type="checkbox"] { accent-color: var(--accent); }
.option-check select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 2px 4px;
  font-size: 12px;
  margin-left: 4px;
}

/* 結果 */
#result-section { margin-bottom: 10px; }

#result-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.result-empty { color: var(--text-tertiary); font-size: 13px; }

.result-damage {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.result-percent { font-size: 16px; margin: 4px 0; color: var(--text-secondary); }
.result-ko { font-size: 14px; font-weight: 600; }
.result-ko.ko-1 { color: var(--danger); }
.result-ko.ko-2 { color: #f0883e; }
.result-ko.ko-3 { color: var(--warning); }
.result-ko.ko-4 { color: var(--text-secondary); }

.result-type-eff {
  font-size: 12px;
  margin-top: 6px;
  color: var(--text-tertiary);
}

.damage-bar {
  width: 100%;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  margin: 10px 0;
  overflow: hidden;
}
.damage-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

/* 一括計算 */
#bulk-calc-btn {
  width: 100%;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#bulk-calc-btn:hover { border-color: var(--text-secondary); color: var(--text); }

#bulk-results {
  margin-top: 8px;
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bulk-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.bulk-row:last-child { border-bottom: none; }
.bulk-row:nth-child(odd) { background: var(--surface); }
.bulk-row:nth-child(even) { background: var(--bg); }

/* モーダル */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 8px;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

.modal-header {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.modal-header input {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.modal-header input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.3); }

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.pokemon-list {
  overflow-y: auto;
  flex: 1;
  padding: 4px;
}

.pokemon-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 14px;
}
.pokemon-list-item:hover { background: var(--surface2); }
.pokemon-list-item .poke-types { display: flex; gap: 3px; margin-left: auto; }

/* Gemmaモーダル */
.gemma-body { padding: 12px; }
#gemma-file { margin-bottom: 8px; }
#gemma-preview img { max-width: 100%; border-radius: var(--radius); margin: 8px 0; }
#gemma-status { font-size: 13px; color: var(--text-secondary); margin: 8px 0; }

.hidden { display: none !important; }

/* タイプカラー */
.type-ノーマル { background: #a8a878; }
.type-ほのお { background: #f08030; }
.type-みず { background: #6890f0; }
.type-でんき { background: #f8d030; color: #1a1a1a; }
.type-くさ { background: #78c850; }
.type-こおり { background: #98d8d8; color: #1a1a1a; }
.type-かくとう { background: #c03028; }
.type-どく { background: #a040a0; }
.type-じめん { background: #e0c068; color: #1a1a1a; }
.type-ひこう { background: #a890f0; }
.type-エスパー { background: #f85888; }
.type-むし { background: #a8b820; color: #1a1a1a; }
.type-いわ { background: #b8a038; }
.type-ゴースト { background: #705898; }
.type-ドラゴン { background: #7038f8; }
.type-あく { background: #705848; }
.type-はがね { background: #b8b8d0; color: #1a1a1a; }
.type-フェアリー { background: #ee99ac; }

/* ダメージバーカラー */
.bar-green { background: var(--success); }
.bar-yellow { background: var(--warning); }
.bar-orange { background: #f0883e; }
.bar-red { background: var(--danger); }
