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

body {
  background-color: #121212;
  color: #ffffff;
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  padding: 15px;
}

.tier-container {
  max-width: 1000px;
  margin: 0 auto;
}

.header-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}

.title-area {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.header-tools h1 {
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 0.5px;
}

.btn-group {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s;
  text-decoration: none;
}

.btn:hover {
  opacity: 0.85;
}

.btn-back {
  background-color: #333;
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
}

.btn-reset {
  background-color: #4a4a4a;
  color: #fff;
}

.btn-save {
  background-color: #ff9ebb;
  color: #121212;
}

.btn-add {
  background-color: #2196F3;
  color: #fff;
}

/* ティア表領域全体ラッパー */
.tier-table-wrapper {
  background-color: #000;
  border: 2px solid #000;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 編集可能タイトル部分 */
.tier-table-title-container {
  background-color: #181a29;
  padding: 10px;
  text-align: center;
  border-bottom: 2px solid #000;
}

.tier-table-title {
  width: 100%;
  background: transparent;
  border: 1px dashed transparent;
  color: #ffffff;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  padding: 4px;
  outline: none;
  border-radius: 4px;
  box-sizing: border-box;
}

.tier-table-title:hover,
.tier-table-title:focus {
  border-color: #ff9ebb;
  background: rgba(255, 255, 255, 0.05);
}

/* ティア表本体デザイン */
.tier-table {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background-color: #000;
}

/* ティア行全体 */
.tier-row {
  display: flex;
  align-items: stretch;
  min-height: 60px;
  height: auto;
  width: 100%;
  background-color: #1a1a1a;
}

/* 編集可能なティア名ラベル */
.tier-label {
  width: 100px;
  min-width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  text-align: center;
  color: #000;
  padding: 5px;
  line-height: 1.2;
  box-sizing: border-box;
  cursor: text;
  outline: none;
  word-break: break-all;
  user-select: text;
  transition: box-shadow 0.2s;
  flex-shrink: 0;
}

.tier-label:focus {
  box-shadow: inset 0 0 0 2px #000;
  background-image: linear-gradient(rgba(255,255,255,0.2), rgba(255,255,255,0.2));
}

/* モンスタードロップエリア */
.tier-dropzone {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  padding: 5px;
  min-height: 60px;
  height: auto;
  transition: background-color 0.2s;
  user-select: none;
  box-sizing: border-box;
}

.tier-dropzone.drag-over {
  background-color: rgba(255, 255, 255, 0.15);
}

.tier-dropzone .monster-card {
  transition: transform 0.15s ease;
}

/* 行操作コントロールエリア */
.tier-row-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  background-color: #222;
  border-left: 1px solid #000;
  flex-shrink: 0;
}

.row-move-btn {
  background: #3a3a3a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 4px;
  width: 26px;
  height: 20px;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.row-move-btn:hover:not(:disabled) {
  background: #555;
}

.row-color-select {
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 4px;
  width: 26px;
  height: 22px;
  font-size: 10px;
  cursor: pointer;
  text-align: center;
  padding: 0;
}

.row-color-select option {
  background-color: #222;
  color: #fff;
}

.row-delete-btn {
  background: #ff5252;
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 26px;
  height: 20px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-delete-btn:hover:not(:disabled) {
  opacity: 0.8;
}

/* 未配置プール */
.pool-section {
  margin-top: 20px;
  background-color: #1a1a1a;
  border-radius: 6px;
  padding: 12px;
}

.pool-section h2 {
  font-size: 14px;
  color: #aaa;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.pool-dropzone {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  min-height: 100px;
  background-color: #121212;
  border: 1px dashed #333;
  border-radius: 4px;
  gap: 2px;
  padding: 4px;
}

/* モンスターカード */
.monster-card {
  width: 60px;
  height: 60px;
  border-radius: 4px;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}

.monster-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  display: block;
}

.no-image-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: rgba(255, 182, 193, 0.12);
  border: 1.5px dashed #ffb6c1;
  border-radius: 4px;
  color: #ff9ebb;
  font-size: clamp(7px, 1.8vw, 9px);
  font-weight: bold;
  letter-spacing: -0.2px;
  white-space: nowrap;
  box-sizing: border-box;
  padding: 0 1px;
  text-align: center;
  user-select: none;
  overflow: hidden;
  animation: pulse-no-img 2s infinite ease-in-out;
}

@keyframes pulse-no-img {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50% { opacity: 1; transform: scale(0.97); }
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 4px;
  background-size: cover;
  background-position: center;
  display: none;
  opacity: 0.8;
  transform: translate(-50%, -50%);
  box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.drop-placeholder {
  width: 60px;
  height: 60px;
  border: 2px dashed #ff9ebb;
  background-color: rgba(255, 158, 187, 0.2);
  border-radius: 4px;
  flex-shrink: 0;
  pointer-events: none;
  animation: pulse-placeholder 1s infinite alternate;
}

@keyframes pulse-placeholder {
  0% { opacity: 0.5; transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}

/* ==========================================
   画像書き出し（エクスポート）専用スタイル
   ========================================== */
body.is-exporting,
body.is-exporting .tier-container {
  height: auto !important;
  overflow: visible !important;
}

.tier-table-wrapper.exporting {
  width: 1000px !important;
  max-width: none !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  border-radius: 0 !important;
}

.tier-table-wrapper.exporting .tier-table {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

.tier-table-wrapper.exporting .tier-row {
  min-height: 80px !important;
  height: auto !important;
  overflow: visible !important;
}

.tier-table-wrapper.exporting .tier-label {
  width: 140px !important;
  min-width: 140px !important;
  font-size: 16px !important;
}

.tier-table-wrapper.exporting .tier-dropzone {
  height: auto !important;
  min-height: 80px !important;
  overflow: visible !important;
  flex-wrap: wrap !important;
}

.tier-table-wrapper.exporting .monster-card {
  width: 70px !important;
  height: 70px !important;
  flex-shrink: 0 !important;
}

.tier-table-wrapper.exporting .tier-row-controls {
  display: none !important;
}

/* スマホ向け（幅600px以下）：上下分離・独立スクロール修正版 */
@media (max-width: 600px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  body {
    padding: 8px 8px 0 8px;
  }

  .tier-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    box-sizing: border-box;
  }

  .header-tools {
    flex-shrink: 0;
    margin-bottom: 6px;
  }

  .header-tools h1 {
    font-size: 15px;
  }

  /* 上部ラッパー：高さを柔軟にしつつ最小高さを0にリセット */
  .tier-table-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
    overflow: hidden;
  }

  .tier-table-title-container {
    flex-shrink: 0;
    padding: 6px;
  }

  .tier-table-title {
    font-size: 14px;
  }

  /* ティア表本体：確実に行追加時にスクロールするように設定 */
  .tier-table {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .tier-row {
    min-height: 50px;
    height: auto !important;
    flex-shrink: 0;
  }

  .tier-label {
    width: 60px;
    min-width: 60px;
    font-size: 10px;
    padding: 2px;
  }

  .tier-dropzone {
    min-height: 50px;
    height: auto !important;
    padding: 2px;
    gap: 2px;
  }

  .tier-dropzone .monster-card,
  .pool-dropzone .monster-card,
  .drag-ghost,
  .drop-placeholder {
    width: 44px !important;
    height: 44px !important;
  }

  /* 下部：未配置プール（固定＆独立スクロール） */
  .pool-section {
    flex-shrink: 0;
    margin-top: 0;
    padding: 8px;
    background-color: #1a1a1a;
    border-top: 2px solid #333;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.7);
    z-index: 100;
  }

  .pool-section h2 {
    font-size: 11px;
    margin-bottom: 4px;
  }

  .pool-dropzone {
    max-height: 190px;
    overflow-y: auto !important;
    overflow-x: hidden;
    background-color: #121212;
    padding: 4px;
    gap: 2px;
    -webkit-overflow-scrolling: touch;
  }
}
/* --- 未配置タタのT1~T4切り替えボタン用スタイル --- */
.pool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

.pool-header h2 {
  margin: 0;
}

.tier-switch-group {
  display: flex;
  gap: 6px;
}

.btn-tier-switch {
  padding: 4px 10px;
  background-color: #333333;
  color: #ffffff;
  border: 1px solid #555555;
  border-radius: 4px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-tier-switch:active {
  transform: scale(0.95);
  background-color: #4CAF50;
}
