@charset "UTF-8";

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  touch-action: manipulation;
}

#top-flash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease-out;
}
#top-flash.active {
  opacity: 1;
  transition: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  gap: 8px;
}

/* ヘッダー（倍率・ゲーム数・プリセット選択・加算/減算モード） */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.step-group {
  display: flex;
  background: var(--surface);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
  gap: 2px;
  flex-shrink: 0;
}

.step-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 7px;
  cursor: pointer;
}
.step-btn.active {
  background: var(--accent);
  color: #0f172a;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: flex-end;
}

/* ヘッダー統合型ゲーム数エリア（入力ボタン・総G・個人G） */
.game-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px 8px 3px 4px;
  flex-shrink: 0;
}

.g-input-btn {
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: var(--accent);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.g-input-btn:active {
  transform: scale(0.95);
}

.g-inline-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.g-stat {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.g-stat-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
}
.g-stat-val {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.g-stat-val.accent {
  color: var(--accent);
}

.preset-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 6px;
  font-size: 12px;
  font-weight: 700;
  outline: none;
  min-width: 72px;
  max-width: 170px;
  flex: 1 1 80px;
  text-overflow: ellipsis;
}
.preset-select:focus {
  border-color: var(--accent);
}

.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.mode-btn.minus {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
  color: #fca5a5;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.35);
}

/* カウンターグリッド（見切れ防止：margin: auto 0 による安全スクロール） */
.counter-wrap {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 2px 0;
}

.counter-grid {
  width: 100%;
  display: grid;
  gap: 10px;
  margin: auto 0;
}
.counter-grid.cols-1 { grid-template-columns: repeat(1, 1fr); }
.counter-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.counter-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.counter-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.role-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 102px;
  padding: 10px 6px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--role-color, #94a3b8);
  box-shadow: inset 0 0 18px color-mix(in srgb, var(--role-color, #94a3b8) 14%, transparent);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.06s ease, background-color 0.08s ease;
}
.role-btn:active {
  transform: scale(0.95);
  background: color-mix(in srgb, var(--role-color, #94a3b8) 25%, var(--surface));
}
.role-btn.minus-active {
  border-style: dashed;
}

.role-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--role-color, #f8fafc);
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-count {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.role-prob {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* フッター */
.footer {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 48px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.nav-btn:active {
  transform: scale(0.97);
}
.nav-btn.primary {
  flex: 2;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: #38bdf8;
  color: #ffffff;
}
.nav-btn.sub {
  flex: 1;
  font-size: 13px;
}
.nav-btn.danger-outline {
  width: 52px;
  flex: none;
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.35);
}

/* 横画面（ランドスケープ）でのコンパクト最適化 */
@media (orientation: landscape) and (max-height: 500px) {
  .app {
    gap: 6px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .role-btn {
    height: 82px;
    padding: 6px 4px;
  }
  .role-count {
    font-size: 24px;
  }
  .nav-btn {
    height: 40px;
  }
}

/* モーダル共通 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.modal-backdrop.open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 500px;
  max-height: 88dvh;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0;
}
.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.btn-save {
  flex: 1;
  height: 46px;
  border-radius: 11px;
  border: none;
  background: var(--accent);
  color: #0f172a;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.btn-cancel {
  height: 46px;
  padding: 0 18px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
input[type="number"],
input[type="text"],
select:not(.preset-select) {
  width: 100%;
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 9px;
  color: #ffffff;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 700;
  outline: none;
}
input:focus, select:focus {
  border-color: var(--accent);
}

/* プリセット管理ボックス */
.preset-manage-box {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.preset-actions {
  display: flex;
  gap: 6px;
}
.preset-action-btn {
  flex: 1;
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.preset-action-btn.new {
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--accent);
}
.preset-action-btn.del {
  border-color: rgba(239, 68, 68, 0.45);
  color: #f87171;
}

.quick-row {
  display: flex;
  gap: 8px;
}
.quick-btn {
  flex: 1;
  padding: 9px 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.preview-box {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
}
.preview-box strong {
  font-size: 20px;
  color: var(--accent);
}

.add-role-btn {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid #22c55e;
  color: #4ade80;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.role-edit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.role-edit-card {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.role-edit-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.role-edit-top input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.role-edit-top input[type="text"] {
  flex: 1;
  padding: 7px 10px;
  font-size: 14px;
}
.role-edit-top select {
  width: 82px;
  padding: 7px 6px;
  font-size: 13px;
  flex-shrink: 0;
}
.del-role-btn {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.prob-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.prob-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.prob-item span {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
}
.prob-item input {
  padding: 6px 8px;
  font-size: 13px;
  text-align: right;
}

/* 設定推測結果 */
.result-summary {
  background: rgba(37, 99, 235, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.result-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
}
.result-summary .best {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 4px;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bar-label {
  width: 46px;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}
.bar-track {
  flex: 1;
  height: 22px;
  background: #0f172a;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 5px;
  transition: width 0.3s ease;
}
.bar-fill.top {
  background: linear-gradient(90deg, #16a34a, #4ade80);
}
.bar-pct {
  width: 54px;
  text-align: right;
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
