:root {
  /* 五色百人一首カラー */
  --color-blue: #3b82f6;
  --color-pink: #ec4899;
  --color-yellow: #eab308;
  --color-green: #22c55e;
  --color-orange: #f97316;

  /* ベースカラー */
  --bg-main: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.9);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;

  /* アクセント・ステータス */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #10b981;
  --success-hover: #059669;

  /* UI要素 */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  --radius-full: 9999px;
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, hsla(253,16%,7%,0.03) 0, transparent 50%), 
    radial-gradient(at 50% 0%, hsla(225,39%,30%,0.03) 0, transparent 50%), 
    radial-gradient(at 100% 0%, hsla(339,49%,30%,0.03) 0, transparent 50%);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
}

#app {
  max-width: 1024px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Header & Nav */
.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 2rem;
  gap: 1.5rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  margin-left: 0.5rem;
  background: linear-gradient(135deg, var(--text-main) 0%, #475569 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  display: inline-block;
  box-shadow: var(--shadow-sm);
}
.color-dot.blue { background-color: var(--color-blue); }
.color-dot.pink { background-color: var(--color-pink); }
.color-dot.yellow { background-color: var(--color-yellow); }
.color-dot.green { background-color: var(--color-green); }
.color-dot.orange { background-color: var(--color-orange); }

.app-nav {
  display: flex;
  gap: 0.5rem;
  background: white;
  padding: 0.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.nav-btn {
  background: transparent;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-size: 1rem;
}

.nav-btn:hover {
  background: var(--bg-main);
  color: var(--text-main);
}

.nav-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* Views & Cards */
.view {
  display: none;
  animation: fadeIn 0.4s ease-out forwards;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

.card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 0.5rem;
  display: inline-block;
}

.desc {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.95rem;
}

.btn.primary {
  background: var(--primary);
  color: white;
}
.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn.secondary {
  background: white;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn.secondary:hover:not(:disabled) {
  background: var(--bg-main);
}

.btn.success {
  background: var(--success);
  color: white;
}
.btn.success:hover:not(:disabled) {
  background: var(--success-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn.large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.action-bar {
  margin-top: 2rem;
  text-align: center;
}

/* Utility */
.hidden { display: none !important; }

/* Pulse Animation for CTA */
.pulse {
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* Student Grid (Checkboxes) */
.selection-actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.75rem;
}

.student-cb-wrapper {
  position: relative;
}

.student-cb {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.student-cb-label {
  display: block;
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.student-cb:checked ~ .student-cb-label {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

/* Match List */
.match-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.match-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.match-row:hover {
  box-shadow: var(--shadow-md);
}

.player-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.player-avatar {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  color: white;
  background: linear-gradient(135deg, #94a3b8, #64748b);
  box-shadow: var(--shadow-sm);
}

.player-rank {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-main);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
}

.vs {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text-muted);
  padding: 0 1rem;
  font-style: italic;
}

/* Radio Buttons as Winner Selectors */
.winner-select-group {
  display: flex;
  justify-content: center;
  gap: 2rem;
  width: 100%;
}

.winner-option {
  position: relative;
}

.winner-radio {
  position: absolute;
  opacity: 0;
}

.winner-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.winner-radio:checked ~ .winner-label {
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
}
.winner-radio:checked ~ .winner-label .player-avatar {
  background: linear-gradient(135deg, #10b981, #059669);
  transform: scale(1.1);
  box-shadow: var(--shadow-md);
}

/* Rank Table */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sort-controls select {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  background: white;
  cursor: pointer;
}

.table-container {
  overflow-x: auto;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.rank-table th,
.rank-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.rank-table th {
  background: var(--bg-main);
  font-weight: 700;
  color: var(--text-muted);
}

.rank-table tbody tr:hover {
  background: #f1f5f9;
}

.rank-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.875rem;
}
/* 級ごとの色分け (例) */
.rank-badge[data-rank*="級"] { background: #e0f2fe; color: #0284c7; }
.rank-badge[data-rank*="段"] { background: #fef9c3; color: #a16207; }
.rank-badge[data-rank*="名人"],
.rank-badge[data-rank*="クイーン"] { background: #fee2e2; color: #b91c1c; }

/* Profile */
.profile-selector {
  margin-bottom: 2rem;
}
.profile-selector select {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  width: 100%;
  max-width: 300px;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-box {
  background: white;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.stat-box h4 {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.stat-box .stat-val {
  font-size: 2rem;
  font-weight: 900;
  color: var(--primary);
}

.history-list {
  list-style: none;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: white;
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  border: 1px solid var(--border-color);
}
.history-item.win { border-left: 4px solid var(--success); }
.history-item.lose { border-left: 4px solid var(--color-pink); }
.history-result { font-weight: 900; width: 40px;}
.history-item.win .history-result { color: var(--success); }
.history-item.lose .history-result { color: var(--color-pink); }

/* Notice / Alert */
.notice {
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  font-weight: 700;
  text-align: center;
}
.notice.info {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: white;
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: zoomIn 0.2s ease-out;
}
@keyframes zoomIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal h3 { margin-bottom: 1rem; font-size: 1.5rem; }
.modal-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  justify-content: center;
}

/* Responsive */
@media (max-width: 640px) {
  .match-row {
    flex-direction: column;
    gap: 1rem;
  }
  .vs { padding: 0.5rem 0; }
  .winner-select-group {
    flex-direction: column;
    gap: 1rem;
  }
}
