/* ==========================================================
   FFXIV Tier Maker (Phase 3-F) - THE CHALLENGE themed redesign
   pom-plan と同じトーンで統一（上部グラデ + ゴールドアクセント）
========================================================== */

.tiermaker-page {
  --tm-bg:        var(--bg, #0a0a0a);
  --tm-bg-2:      var(--bg-2, #111);
  --tm-bg-3:      var(--bg-3, #161616);
  --tm-line:      var(--line, rgba(255,255,255,0.08));
  --tm-line-2:    var(--line-2, rgba(255,255,255,0.15));
  --tm-accent:    var(--accent, #f0c060);
  --tm-accent-2:  var(--accent-2, #d4a04a);
  --tm-white:     var(--white, #f5f3ee);
  --tm-text-2:    var(--text-2, #c8c5bd);
  --tm-text-3:    var(--text-3, #888);
  --tm-text-4:    var(--text-4, #666);
  --tm-alert:     #ff6666;

  --tm-font-mono: "Roboto Mono", "SF Mono", Menlo, Consolas, monospace;

  /* 上部グラデーション (pom-plan と同じ) */
  background: linear-gradient(
    180deg,
    #2a2a2e 0%,
    #1a1a1d 20%,
    #0a0a0a 45%,
    #0a0a0a 100%
  );
  background-attachment: fixed;
  color: var(--tm-text-2);
  min-height: 100vh;
  padding: 24px 20px 80px;
  box-sizing: border-box;
  position: relative;

  /* サイズ設定 (PC 180px / Mobile 110px) */
  --img-width: 180px;
  --img-ratio: 386 / 686;
}

body:has(.tiermaker-page) {
  background: linear-gradient(
    180deg,
    #2a2a2e 0%,
    #1a1a1d 20%,
    #0a0a0a 45%,
    #0a0a0a 100%
  );
  background-attachment: fixed;
  margin: 0;
}

@media (max-width: 600px) {
  .tiermaker-page { --img-width: 110px; padding: 16px 10px 60px; }
}

/* ========== ヘッダー警告 ========== */
.tiermaker-page .recommend-alert {
  max-width: 1280px;
  margin: 0 auto 16px;
  padding: 10px 14px;
  background: var(--tm-bg-2);
  border: 1px solid var(--tm-line);
  border-left: 3px solid var(--tm-accent);
  color: var(--tm-accent);
  font-size: 11px;
  line-height: 1.6;
  letter-spacing: 0.02em;
  text-align: center;
  box-sizing: border-box;
}

/* ========== コントロールボタン群 ========== */
.tiermaker-page .controls {
  max-width: 1280px;
  margin: 0 auto 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  position: sticky;
  top: 10px;
  z-index: 1000;
}

.tiermaker-page .btn-main {
  padding: 10px 18px;
  font-family: var(--font-ui, "Noto Sans JP", sans-serif);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border: 1px solid var(--tm-line-2);
  background: var(--tm-bg-2);
  color: var(--tm-text-2);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}
.tiermaker-page .btn-main:hover {
  border-color: var(--tm-accent);
  color: var(--tm-accent);
}
.tiermaker-page .btn-main:disabled {
  opacity: 0.4; cursor: not-allowed;
}

.tiermaker-page .btn-save {
  background: var(--tm-bg-3);
}
.tiermaker-page .btn-x {
  background: var(--tm-accent);
  color: var(--tm-bg);
  border-color: var(--tm-accent);
  font-weight: 600;
}
.tiermaker-page .btn-x:hover {
  background: var(--tm-accent-2);
  border-color: var(--tm-accent-2);
  color: var(--tm-bg);
}
.tiermaker-page .btn-reset {
  color: var(--tm-alert);
  border-color: rgba(255, 102, 102, 0.3);
}
.tiermaker-page .btn-reset:hover {
  border-color: var(--tm-alert);
  color: var(--tm-alert);
  background: rgba(255, 102, 102, 0.08);
}
.tiermaker-page .btn-help {
  color: var(--tm-text-3);
}
.tiermaker-page .btn-role {
  color: var(--tm-text-3);
}
.tiermaker-page .btn-role.active {
  background: rgba(100, 180, 100, 0.15);
  border-color: rgba(100, 180, 100, 0.6);
  color: #9fdf9f;
}

/* ========== キャプチャーエリア (Tier 本体) ========== */
.tiermaker-page #capture-area {
  max-width: 1280px;
  margin: 0 auto;
  background: #000;
  padding: 24px 20px;
  box-sizing: border-box;
  border: 1px solid var(--tm-line);
}

.tiermaker-page .tier-meta {
  margin-bottom: 16px;
  text-align: center;
}
.tiermaker-page .tier-title-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--tm-accent);
  font-size: 22px;
  font-weight: 500;
  text-align: center;
  margin-bottom: 6px;
  outline: none;
  line-height: 1.3;
  padding: 0;
  font-family: var(--font-ui, "Noto Sans JP", sans-serif);
  letter-spacing: 0.05em;
}
.tiermaker-page .tier-desc-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--tm-text-2);
  font-size: 13px;
  text-align: center;
  outline: none;
  resize: none;
  overflow: hidden;
  line-height: 1.6;
  padding: 0;
  font-family: inherit;
}
.tiermaker-page .tier-title-input::placeholder,
.tiermaker-page .tier-desc-input::placeholder {
  color: var(--tm-text-4);
}

.tiermaker-page .capture-title-text {
  color: var(--tm-accent);
  font-size: 22px;
  font-weight: 500;
  text-align: center;
  margin-bottom: 6px;
  line-height: 1.3;
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: 0.05em;
}
.tiermaker-page .capture-desc-text {
  color: var(--tm-text-2);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ========== Tier Board ========== */
.tiermaker-page .tier-board {
  border: 1px solid var(--tm-line);
}
.tiermaker-page .tier-row {
  display: flex;
  min-height: 120px;
  border-bottom: 1px solid var(--tm-line);
}
.tiermaker-page .tier-row:last-child {
  border-bottom: none;
}

.tiermaker-page .label {
  width: 50px;
  min-width: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #0a0a0a;
  cursor: text;
  letter-spacing: 0.05em;
  font-family: var(--tm-font-mono);
}
.tiermaker-page .rank-s { background: #ff7f7f; }
.tiermaker-page .rank-a { background: #ffbf7f; }
.tiermaker-page .rank-b { background: #ffff7f; }
.tiermaker-page .rank-c { background: #7fff7f; }
.tiermaker-page .rank-d { background: #7f9fff; }

.tiermaker-page .drop-zone {
  flex-grow: 1;
  display: flex;
  flex-wrap: wrap;
  padding: 6px;
  gap: 8px;
  align-content: flex-start;
  align-items: center;
  background: var(--tm-bg);
  min-height: 120px;
}

/* ========== カテゴリーコンテナ ========== */
.tiermaker-page .category-container {
  max-width: 1280px;
  margin: 24px auto 0;
}

.tiermaker-page .category-group {
  margin-bottom: 10px;
  background: var(--tm-bg-2);
  border: 1px solid var(--tm-line);
  overflow: hidden;
}

.tiermaker-page .category-header {
  background: var(--tm-bg-3);
  padding: 12px 16px;
  cursor: pointer;
  font-family: var(--font-ui, "Noto Sans JP", sans-serif);
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--tm-accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  user-select: none;
  transition: background 0.2s ease;
}
.tiermaker-page .category-header:hover {
  background: rgba(240, 192, 96, 0.08);
}
.tiermaker-page .category-header::after {
  content: '▼';
  font-size: 10px;
  color: var(--tm-text-4);
  transition: transform 0.2s ease;
}
.tiermaker-page .category-group.open .category-header::after {
  transform: rotate(180deg);
  color: var(--tm-accent);
}

.tiermaker-page .category-content {
  display: none;
  padding: 14px;
  flex-direction: column;
  gap: 20px;
}
.tiermaker-page .category-group.open .category-content {
  display: flex;
}

/* ========== ロールセクション ========== */
.tiermaker-page .role-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 2px solid var(--tm-line-2);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
.tiermaker-page .role-section-header img {
  height: 24px;
  width: auto;
}
.tiermaker-page .role-section-header span {
  font-family: var(--font-ui, "Noto Sans JP", sans-serif);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--tm-white);
}

.tiermaker-page .series-section {
  padding: 4px 0;
}
.tiermaker-page .series-title {
  font-family: var(--font-ui, "Noto Sans JP", sans-serif);
  font-size: 12px;
  color: var(--tm-accent);
  margin-bottom: 8px;
  font-weight: 500;
  letter-spacing: 0.08em;
  padding-left: 8px;
  border-left: 3px solid var(--tm-accent);
}
.tiermaker-page .series-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
}

/* ========== リストアイテム (カード) ========== */
.tiermaker-page .item-box {
  width: var(--img-width) !important;
  min-width: var(--img-width) !important;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  margin-bottom: 10px;
}
.tiermaker-page .item-wrapper {
  position: relative;
  width: 100%;
  height: calc(var(--img-width) * var(--img-ratio));
}
.tiermaker-page .item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid var(--tm-line-2);
  display: block;
  transition: filter 0.2s ease, opacity 0.2s ease;
}
.tiermaker-page .item-box.job-item {
  width: 75px !important;
  min-width: 75px !important;
}
.tiermaker-page .item-box.job-item .item-wrapper {
  width: 75px !important;
  height: 75px !important;
}
.tiermaker-page .item-box.job-item .item-img {
  object-fit: contain !important;
  opacity: 1 !important;
  visibility: visible !important;
}
.tiermaker-page .item-box.selected .item-wrapper .item-img {
  opacity: 0.35;
  filter: grayscale(1);
}
.tiermaker-page .item-text {
  position: absolute;
  bottom: 2px;
  right: 4px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 1px 1px 2px #000, -1px -1px 2px #000, 1px -1px 2px #000, -1px 1px 2px #000;
  pointer-events: none;
  z-index: 50;
  font-family: var(--font-ui, "Noto Sans JP", sans-serif);
}

/* ========== ランクボタン ========== */
.tiermaker-page .add-btns {
  display: flex;
  justify-content: space-between;
  gap: 1px;
}
.tiermaker-page .add-btns button {
  flex: 1;
  padding: 4px 0;
  font-size: 11px;
  border: none;
  cursor: pointer;
  color: #0a0a0a;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  transition: all 0.2s ease;
  font-family: var(--tm-font-mono);
  letter-spacing: 0.05em;
}
.tiermaker-page .add-btns button:hover {
  transform: translateY(-1px);
}
.tiermaker-page .add-btns button.active-rank {
  outline: 2px solid var(--tm-white);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
  z-index: 5;
}
.tiermaker-page .add-btns button.editing-rank {
  outline: 2px solid var(--tm-accent);
  box-shadow: 0 0 8px var(--tm-accent);
  z-index: 10;
  animation: tm-pulse-border 1.5s infinite;
}
@keyframes tm-pulse-border {
  0% { box-shadow: 0 0 4px var(--tm-accent); }
  50% { box-shadow: 0 0 12px var(--tm-accent); }
  100% { box-shadow: 0 0 4px var(--tm-accent); }
}

.tiermaker-page .rank-dots-container {
  display: flex;
  gap: 1px;
  margin-top: 2px;
  height: 4px;
  pointer-events: none;
}
.tiermaker-page .rank-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}
.tiermaker-page .dot-tank   { background: #4d94ff; box-shadow: 0 0 2px #000; }
.tiermaker-page .dot-healer { background: #4dff4d; box-shadow: 0 0 2px #000; }
.tiermaker-page .dot-dps    { background: #ff4d4d; box-shadow: 0 0 2px #000; }
.tiermaker-page .dot-none   { background: #fff;    box-shadow: 0 0 2px #000; }

/* ========== 削除ボタン (×) ========== */
.tiermaker-page .reset-item-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  background: var(--tm-alert);
  color: #fff;
  border-radius: 50%;
  border: 2px solid #0a0a0a;
  font-size: 13px;
  font-weight: 700;
  display: none;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease;
}
.tiermaker-page .reset-item-btn:hover {
  background: #ff8888;
  transform: scale(1.1);
}

/* ========== Tier 内画像 ========== */
.tiermaker-page .in-tier {
  position: relative;
  width: 180px !important;
  height: calc(180px * var(--img-ratio)) !important;
  cursor: grab;
  touch-action: none;
  margin: 4px;
}
.tiermaker-page .in-tier.job-item {
  width: 75px !important;
  height: 75px !important;
}
.tiermaker-page .in-tier.job-item .item-wrapper {
  width: 100% !important;
  height: 100% !important;
}
.tiermaker-page .in-tier.job-item .item-img {
  object-fit: contain !important;
}
.tiermaker-page .in-tier:active {
  cursor: grabbing;
}
.tiermaker-page .in-tier .item-wrapper {
  width: 100%;
  height: 100%;
  opacity: 1 !important;
  filter: none !important;
}

.tiermaker-page .sortable-ghost {
  opacity: 0.4;
  background: var(--tm-bg-3);
}

/* ========== ロールフラグ オーバーレイ ========== */
.tiermaker-page .role-flags-overlay {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  gap: 2px;
  padding: 3px;
  z-index: 999;
  pointer-events: none;
}
.tiermaker-page.role-mode-active .role-flags-overlay,
body.role-mode-active .tiermaker-page .role-flags-overlay {
  display: flex;
}

.tiermaker-page .role-btn {
  width: 22px;
  height: 22px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid var(--tm-line-2);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0.75;
  transition: all 0.15s ease;
  pointer-events: auto;
}
.tiermaker-page .role-btn img {
  width: 14px;
  height: 14px;
  pointer-events: none;
}
.tiermaker-page .role-btn:hover {
  opacity: 1;
  transform: scale(1.1);
  background: #000;
  border-color: var(--tm-white);
}
.tiermaker-page .role-btn.active {
  opacity: 1 !important;
  border-color: #4dff4d;
  background: #0a2a0a;
  box-shadow: 0 0 5px rgba(77, 255, 77, 0.4);
}
.tiermaker-page .role-btn.active img {
  filter: brightness(1.3);
}

/* ========== カードコントロール (コピー/削除) ========== */
.tiermaker-page .card-controls {
  position: absolute;
  top: 0;
  right: 0;
  display: none;
  gap: 3px;
  padding: 3px;
  z-index: 1000;
}
.tiermaker-page.role-mode-active .card-controls,
body.role-mode-active .tiermaker-page .card-controls {
  display: flex;
}

.tiermaker-page .card-ctrl-btn {
  width: 22px;
  height: 22px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border: 1px solid var(--tm-line-2);
  font-size: 15px;
  line-height: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0.75;
  transition: all 0.15s ease;
}
.tiermaker-page .card-ctrl-btn:hover {
  opacity: 1;
  background: #111;
  border-color: var(--tm-white);
}
.tiermaker-page .btn-clone {
  color: #4fc3f7;
}
.tiermaker-page .btn-del {
  color: var(--tm-alert);
}

/* ========== キャプチャフッター ========== */
.tiermaker-page .capture-footer {
  text-align: right;
  color: var(--tm-text-4);
  font-size: 10px;
  margin-top: 6px;
  letter-spacing: 0.05em;
}

/* ========== ページフッター (© SQUARE ENIX. 表示) ========== */
.tiermaker-page .tiermaker-footer {
  max-width: 1280px;
  margin: 32px auto 0;
  padding: 18px;
  text-align: center;
  font-size: 11px;
  color: var(--tm-text-4);
  border-top: 1px solid var(--tm-line);
  letter-spacing: 0.05em;
  line-height: 1.6;
}
.tiermaker-page .tiermaker-footer a {
  color: var(--tm-text-3);
  text-decoration: none;
  transition: color 0.2s ease;
}
.tiermaker-page .tiermaker-footer a:hover {
  color: var(--tm-accent);
}

/* ========== モーダル (ヘルプ / プレビュー) ========== */
.tiermaker-page #how-to-modal,
.tiermaker-page #help-modal,
#how-to-modal,
#help-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}

#how-to-modal .modal-content,
#help-modal .modal-content {
  background: #111;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  text-align: center;
  border: 1px solid rgba(240, 192, 96, 0.3);
  box-sizing: border-box;
  max-height: 90vh;
  overflow-y: auto;
  color: #c8c5bd;
}

#how-to-modal .modal-content h3,
#help-modal .modal-content h3 {
  color: #f0c060;
  margin: 0 0 16px;
  font-size: 14px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 500;
  font-family: "Noto Sans JP", sans-serif;
}

#how-to-modal .modal-link,
#help-modal .modal-link {
  background: #f0c060;
  color: #0a0a0a;
  padding: 12px 20px;
  text-decoration: none;
  display: block;
  font-weight: 600;
  margin-top: 18px;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  transition: background 0.2s ease;
}
#how-to-modal .modal-link:hover,
#help-modal .modal-link:hover {
  background: #d4a04a;
}

#how-to-modal .modal-sub-text {
  font-size: 11px;
  color: #888;
  margin-top: 10px;
  line-height: 1.6;
}

#how-to-modal #preview-placeholder img {
  max-height: 50vh;
  object-fit: contain;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

#help-modal .help-step {
  margin-bottom: 20px;
  text-align: left;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
  padding-bottom: 15px;
}
#help-modal .help-step:last-child {
  border-bottom: none;
}
#help-modal .help-step h4 {
  color: #f0c060;
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.1em;
  font-weight: 500;
}
#help-modal .help-step p {
  margin: 0;
  font-size: 12px;
  color: #c8c5bd;
  line-height: 1.7;
}
#help-modal .help-icon-demo {
  display: inline-flex;
  gap: 5px;
  background: #000;
  padding: 4px;
  margin-top: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
#help-modal .demo-btn {
  width: 20px;
  height: 20px;
  border: 1px solid var(--tm-line-2, rgba(255,255,255,0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

/* ========== レスポンシブ ========== */
@media (max-width: 600px) {
  .tiermaker-page .label {
    width: 40px;
    min-width: 40px;
    font-size: 16px;
  }
  .tiermaker-page .in-tier {
    width: 110px !important;
    height: calc(110px * var(--img-ratio)) !important;
  }
  .tiermaker-page .in-tier.job-item {
    width: 55px !important;
    height: 55px !important;
  }
  .tiermaker-page .tier-title-input {
    font-size: 16px;
  }
  .tiermaker-page .role-btn,
  .tiermaker-page .card-ctrl-btn {
    width: 18px;
    height: 18px;
    font-size: 12px;
  }
  .tiermaker-page .role-btn img {
    width: 12px;
    height: 12px;
  }
  .tiermaker-page .controls {
    top: 5px;
  }
  .tiermaker-page .btn-main {
    padding: 8px 14px;
    font-size: 10px;
  }
  .tiermaker-page #capture-area {
    padding: 16px 12px;
  }
}
