/* ===========================
   デザインシステム
   =========================== */
:root {
  /* カラーパレット (ライトモード) */
  --bg-primary: #f8fafe;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f1f5f9;

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #6c63ff;
  --accent-primary-hover: #5a52e0;
  --accent-secondary: #0d9488;
  --accent-tertiary: #db2777;
  --accent-warning: #d97706;

  --border-color: #e2e8f0;
  --border-accent: #6c63ff22;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 20px rgba(108, 99, 255, 0.1);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===========================
   リセット・ベース
   =========================== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* 背景のグラデーション装飾 */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 600px;
  background: radial-gradient(ellipse at 50% -20%, rgba(108, 99, 255, 0.05) 0%, transparent 80%);
  pointer-events: none;
  z-index: 0;
}

/* ===========================
   レイアウト
   =========================== */
.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ===========================
   トップナビゲーション
   =========================== */
.top-nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-nav-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--accent-primary);
}

/* ===========================
   ヘッダー
   =========================== */
.header {
  padding: 32px 20px 24px;
  text-align: center;
  position: relative;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo-icon {
  font-size: 2rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.logo h1 {
  font-size: 1.6rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* ===========================
   カード
   =========================== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.card-icon {
  font-size: 1.2rem;
}

.card-info {
  background: linear-gradient(135deg, #ffffff, #f0fdfa);
  border-color: rgba(13, 148, 136, 0.2);
}

.card-summary {
  background: linear-gradient(135deg, #ffffff, #f5f3ff);
  border-color: rgba(108, 99, 255, 0.2);
}

/* ===========================
   フォーム
   =========================== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  padding: 12px 50px 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.1rem;
  font-family: var(--font-family);
  font-weight: 700;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  -moz-appearance: textfield;
}

.input-wrapper input::-webkit-outer-spin-button,
.input-wrapper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-wrapper input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}

.input-suffix {
  position: absolute;
  right: 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: none;
}

/* ===========================
   トグルスイッチ
   =========================== */
.toggle-section {
  margin-bottom: 24px;
  padding: 16px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.toggle-label {
  cursor: pointer;
  flex: 1;
}

.toggle-text {
  display: block;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

.toggle-desc {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #cbd5e1;
  border-radius: 28px;
  transition: background 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--accent-primary);
}

.toggle-switch input:checked+.toggle-slider::before {
  transform: translateX(24px);
}

/* ===========================
   ボタン
   =========================== */
.btn-generate {
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent-primary), #5147d9);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-family);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
}

.btn-generate:hover {
  background: linear-gradient(135deg, var(--accent-primary-hover), #6358e8);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(108, 99, 255, 0.4);
}

.btn-generate:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 1.2rem;
}

/* ===========================
   卓構成情報
   =========================== */
.config-info {
  margin-top: 24px;
}

.config-details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.config-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #f0fdfa;
  border: 1px solid rgba(13, 148, 136, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: #0f766e;
}

.config-badge.star-badge {
  background: #fffbeb;
  border-color: rgba(217, 119, 6, 0.2);
  color: #b45309;
}

/* ===========================
   エクスポートセクション
   =========================== */
.export-section {
  margin-top: 24px;
}

.card-export {
  background: linear-gradient(135deg, #ffffff, #f0fdf4);
  border-color: rgba(22, 163, 74, 0.2);
}

.export-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-export {
  flex: 1;
  min-width: 200px;
  padding: 12px 20px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.btn-copy {
  background: #f0fdfa;
  color: #0d9488;
  border-color: rgba(13, 148, 136, 0.3);
}

.btn-copy:hover {
  background: #ccfbf1;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.15);
}

.btn-download {
  background: #f5f3ff;
  color: #6c63ff;
  border-color: rgba(108, 99, 255, 0.3);
}

.btn-download:hover {
  background: #ede9fe;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108, 99, 255, 0.15);
}

.copy-feedback {
  margin-top: 12px;
  padding: 10px 16px;
  background: rgba(0, 212, 170, 0.1);
  border: 1px solid rgba(0, 212, 170, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===========================
   結果セクション
   =========================== */
.result-section {
  margin-top: 24px;
}

.round-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.round-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  animation: slideUp 0.4s ease forwards;
  opacity: 0;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.round-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.round-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.round-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-primary), #5147d9);
  border-radius: 50%;
  font-weight: 900;
  font-size: 0.95rem;
  color: white;
}

.round-title {
  font-size: 1rem;
  font-weight: 700;
}

.tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.table-cell {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  transition: all 0.3s ease;
}

.table-cell:hover {
  border-color: var(--accent-primary-hover);
  background: white;
  box-shadow: var(--shadow-sm);
}

.table-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-players {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.player-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  background: #f5f3ff;
  border: 1px solid rgba(108, 99, 255, 0.2);
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  color: #4f46e5;
}

.player-badge.star {
  background: #fffbeb;
  border-color: rgba(217, 119, 6, 0.2);
  color: #b45309;
}

.player-badge.guest {
  background: #fff1f2;
  border-color: rgba(225, 29, 72, 0.2);
  color: #e11d48;
  box-shadow: 0 0 0 1px rgba(225, 29, 72, 0.1);
}

/* ===========================
   サマリーセクション
   =========================== */
.summary-section {
  margin-top: 24px;
}

.summary-content {
  overflow-x: auto;
}

.summary-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}

.summary-table thead th {
  background: var(--bg-input);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

.summary-table thead th:first-child {
  border-radius: var(--radius-sm) 0 0 0;
  text-align: left;
}

.summary-table thead th:last-child {
  border-radius: 0 var(--radius-sm) 0 0;
}

.summary-table tbody td {
  padding: 10px 14px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 500;
}

.summary-table tbody td:first-child {
  text-align: left;
  font-weight: 700;
}

.summary-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.summary-table tbody tr:last-child td {
  border-bottom: none;
}

.summary-table tbody tr:last-child td:first-child {
  border-radius: 0 0 0 var(--radius-sm);
}

.summary-table tbody tr:last-child td:last-child {
  border-radius: 0 0 var(--radius-sm) 0;
}

.count-high {
  color: var(--accent-secondary);
}

.count-low {
  color: var(--accent-tertiary);
}

.count-zero {
  color: var(--accent-tertiary);
  font-weight: 900;
}

.star-row td {
  color: var(--accent-warning) !important;
  opacity: 0.7;
}

/* 同卓マトリクス */
.matrix-section {
  margin-top: 24px;
}

.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.78rem;
}

.matrix-table th,
.matrix-table td {
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  min-width: 36px;
}

.matrix-table thead th {
  background: #f8fafc;
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  border-bottom: 2px solid var(--border-color);
}

.matrix-table tbody th {
  background: #f8fafc;
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  position: sticky;
  left: 0;
  border-right: 2px solid var(--border-color);
}

.matrix-table .self-cell {
  background: var(--bg-card-hover);
  color: var(--text-muted);
}

.matrix-table .high-encounter {
  color: var(--accent-warning);
  font-weight: 700;
}

/* ===========================
   非表示ユーティリティ
   =========================== */
.hidden {
  display: none !important;
}

/* ===========================
   フッター
   =========================== */
.footer {
  text-align: center;
  padding: 24px 20px;
  color: var(--text-muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--border-color);
  margin-top: 40px;
}

/* ===========================
   レスポンシブ
   =========================== */
@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .logo h1 {
    font-size: 1.3rem;
  }

  .card {
    padding: 20px;
  }

  .tables-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toggle-group {
    flex-direction: column;
    align-items: flex-start;
  }

  .matrix-table {
    font-size: 0.7rem;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 4px 5px;
    min-width: 28px;
  }
}

@media (max-width: 400px) {
  .tables-grid {
    grid-template-columns: 1fr;
  }
}