:root {
  --navy: #0A1628;
  --teal: #0D9488;
  --teal-light: #14B8A6;
  --amber: #F59E0B;
  --amber-light: #FCD34D;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #1E293B;
  --text-muted: #64748B;
  --danger: #EF4444;
  --success: #10B981;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(10,22,40,0.08);
  --shadow-lg: 0 8px 32px rgba(10,22,40,0.14);
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.center-content { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100vh - 64px); }
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-2 { margin-top: 2rem; }
.highlight { color: var(--teal); }

/* Header */
.site-header {
  background: var(--navy);
  color: white;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; }
.logo { color: white; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.nav-hint { color: rgba(255,255,255,0.5); font-size: 0.85rem; }
.main-content { padding: 32px 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; border: none;
  font-size: 0.95rem; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: all 0.2s;
  font-family: inherit;
}
.btn-primary { background: var(--teal); color: white; }
.btn-primary:hover { background: var(--teal-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13,148,136,0.3); }
.btn-outline { background: transparent; color: var(--teal); border: 2px solid var(--teal); }
.btn-outline:hover { background: var(--teal); color: white; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--border); }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; border-radius: 6px; background: var(--border); color: var(--text); text-decoration: none; border: none; cursor: pointer; font-family: inherit; }
.btn-danger { background: var(--danger) !important; color: white !important; }
.btn-experiment { width: 100%; justify-content: center; background: var(--amber); color: var(--navy); }
.btn-experiment:hover { background: var(--amber-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(245,158,11,0.4); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.9rem; color: var(--text-muted); }
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 1rem; font-family: inherit;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--teal); }
.form-group input[type="range"] { width: 100%; accent-color: var(--teal); }
.range-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.required { color: var(--danger); }
.error-msg { color: var(--danger); font-size: 0.9rem; margin-bottom: 12px; padding: 10px; background: #FEF2F2; border-radius: 8px; }

/* Entry Page */
.entry-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 48px 40px;
  width: 100%; max-width: 480px;
}
.entry-hero { text-align: center; margin-bottom: 32px; }
.flask-icon { font-size: 3rem; margin-bottom: 12px; }
.entry-hero h1 { font-size: 1.6rem; color: var(--navy); }
.subtitle { color: var(--text-muted); margin-top: 8px; }
.entry-info { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border); }
.entry-info h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 8px; }
.entry-info ul { padding-left: 18px; color: var(--text-muted); font-size: 0.88rem; line-height: 1.7; }

/* Level Selection */
.page-header { text-align: center; margin-bottom: 32px; }
.page-header h2 { font-size: 1.5rem; }
.page-header p { color: var(--text-muted); margin-top: 4px; }

.level-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.level-card {
  background: var(--surface); border-radius: var(--radius);
  border: 2px solid var(--border); padding: 24px;
  cursor: pointer; transition: all 0.2s;
}
.level-card:hover { border-color: var(--teal); transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.level-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  background: var(--teal); color: white; font-size: 0.8rem; font-weight: 700; margin-bottom: 10px;
}
.level-badge.level-2 { background: var(--amber); color: var(--navy); }
.level-badge.level-3 { background: var(--navy); }
.level-card h3 { font-size: 1.2rem; margin-bottom: 12px; }
.level-params { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.param-chip { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 3px 10px; font-size: 0.78rem; }
.level-stats { display: flex; gap: 12px; margin-bottom: 12px; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); }
.stat-value { font-size: 0.9rem; font-weight: 600; }
.stat-value.warning { color: var(--danger); }
.level-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }

/* Game Page */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: white; padding: 12px 20px;
  border-radius: var(--radius); margin-bottom: 20px;
}
.game-title { display: flex; align-items: center; gap: 12px; }
.level-tag {
  padding: 3px 12px; border-radius: 20px;
  background: var(--teal); color: white; font-size: 0.82rem; font-weight: 700;
}
.level-tag.level-2 { background: var(--amber); color: var(--navy); }
.level-tag.level-3 { background: rgba(255,255,255,0.15); }
.player-name { font-weight: 600; }
.player-id { font-size: 0.8rem; opacity: 0.65; margin-left: 4px; }
.game-meta { display: flex; gap: 20px; font-size: 0.88rem; align-items: center; }
.trial-counter { font-size: 0.9rem; }
.trial-counter.warning strong { color: var(--amber); }

.game-layout { display: grid; grid-template-columns: 340px 1fr; gap: 20px; }
.input-panel, .result-panel {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 20px;
}
.panel-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--navy); }

.best-yield-display {
  margin-top: 20px; padding: 16px; background: linear-gradient(135deg, var(--navy), #1e3a5f);
  border-radius: 10px; color: white; text-align: center; font-size: 1rem;
}
.best-val { font-size: 2rem; font-weight: 700; color: var(--amber); }
.trophy { font-size: 1.4rem; }

.chart-container { height: 220px; margin-bottom: 16px; }
.table-scroll { overflow-x: auto; max-height: 320px; overflow-y: auto; }
.trial-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.trial-table th { background: var(--bg); padding: 8px 10px; text-align: left; font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.trial-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.trial-table tr:hover td { background: #F0FDFA; }
.trial-table .high-yield { background: #ECFDF5; font-weight: 600; color: var(--success); }
.trial-table .best-row td { background: #FEF9C3 !important; }
.no-data { text-align: center; color: var(--text-muted); padding: 24px !important; }

/* Comment section */
.comment-section { margin: 16px 0; text-align: left; }
.comment-section label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.95rem; }
.comment-section textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: 0.9rem;
  resize: vertical; transition: border-color 0.2s;
}
.comment-section textarea:focus { outline: none; border-color: var(--teal); }
.comment-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* Spinner */
.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-content {
  background: white; border-radius: var(--radius); padding: 40px;
  max-width: 400px; width: 90%; text-align: center; box-shadow: var(--shadow-lg);
}
.modal-content h2 { font-size: 1.5rem; margin-bottom: 12px; }
.modal-content p { margin-bottom: 8px; color: var(--text-muted); }
.modal-content strong { color: var(--teal); font-size: 1.2rem; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }

/* Result Page */
.result-page { max-width: 800px; margin: 0 auto; }
.result-header { text-align: center; margin-bottom: 24px; }
.result-header h1 { font-size: 2rem; }
.result-player { color: var(--text-muted); margin-top: 4px; }
.result-score-card {
  background: linear-gradient(135deg, var(--navy), #1e3a5f);
  color: white; border-radius: var(--radius); padding: 32px;
  text-align: center; margin-bottom: 32px;
}
.score-label { font-size: 0.9rem; opacity: 0.7; margin-bottom: 4px; }
.score-value { font-size: 3.5rem; font-weight: 700; color: var(--amber); }
.score-trials { margin-top: 8px; opacity: 0.7; }
.comparison-section { background: var(--surface); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; border: 1px solid var(--border); }
.comparison-section h2 { margin-bottom: 16px; }
.bo-comment { margin-top: 16px; padding: 14px; background: var(--bg); border-radius: 8px; color: var(--text-muted); text-align: center; }
.result-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* Leaderboard */
.lb-header { text-align: center; margin-bottom: 20px; }
.lb-header h1 { font-size: 1.8rem; }
.lb-code { color: var(--text-muted); margin-top: 4px; }
.lb-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.lb-tab { padding: 8px 20px; border-radius: 8px; border: 2px solid var(--border); background: transparent; cursor: pointer; font-family: inherit; font-size: 0.95rem; transition: all 0.2s; }
.lb-tab.active { background: var(--teal); color: white; border-color: var(--teal); }
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th { background: var(--navy); color: white; padding: 12px 16px; text-align: left; }
.lb-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.lb-table tr:hover td { background: #F0FDFA; }
.lb-table .rank-1 td { background: #FEF9C3; }
.lb-table .rank-2 td { background: #F1F5F9; }
.lb-table .rank-3 td { background: #FFF7ED; }
.lb-table .bo-row td { background: #F0F9FF; color: var(--text-muted); border-bottom: 2px dashed var(--border); }
.lb-table .rank-cell { font-weight: 700; font-size: 1.1rem; }
.lb-table .yield-cell { font-weight: 700; color: var(--teal); font-size: 1.05rem; }
.lb-actions { display: flex; gap: 12px; margin-top: 20px; }
.fullscreen-lb .lb-header h1 { font-size: 2.4rem; }
.fullscreen-lb .lb-table { font-size: 1.1rem; }
.fullscreen-lb .lb-table th, .fullscreen-lb .lb-table td { padding: 16px 20px; }

/* Admin */
.admin-section { background: var(--surface); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; border: 1px solid var(--border); }
.admin-section h2 { margin-bottom: 16px; font-size: 1.1rem; }
.admin-form .form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.admin-form .form-row .form-group { flex: 1; min-width: 140px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 16px; }
.admin-table th { background: var(--bg); padding: 10px 12px; text-align: left; border-bottom: 2px solid var(--border); }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.admin-table .inactive { opacity: 0.4; }
.msg { padding: 10px 14px; border-radius: 8px; background: #ECFDF5; color: var(--success); font-size: 0.9rem; margin-top: 8px; }
.msg.error { background: #FEF2F2; color: var(--danger); }

/* True max bar */
.true-max-bar {
  background: linear-gradient(135deg, var(--navy), #1e3a5f);
  color: white; border-radius: 8px; padding: 10px 18px;
  margin-bottom: 12px; font-size: 0.95rem;
}
.true-max-bar strong { color: var(--amber); font-size: 1.2rem; }
.achieve-cell { color: var(--text-muted); font-size: 0.9rem; }
.fullscreen-lb .true-max-bar { font-size: 1.1rem; padding: 12px 20px; }

/* Reaction Info Panel */
.reaction-info-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.reaction-info-panel summary {
  cursor: pointer;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--teal);
  font-size: 0.95rem;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.reaction-info-panel summary::-webkit-details-marker { display: none; }
.reaction-info-panel summary::before {
  content: '▶';
  font-size: 0.7rem;
  transition: transform 0.2s;
}
.reaction-info-panel[open] summary::before { transform: rotate(90deg); }
.reaction-info-body {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}
.reaction-diagram {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}
.reaction-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}
.reaction-species {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}
.reaction-species.substrate { background: #dbeafe; color: #1e40af; }
.reaction-species.product { background: #dcfce7; color: #166534; }
.reaction-arrow { color: var(--text-muted); font-size: 0.9rem; white-space: nowrap; }
.long-arrow { letter-spacing: 2px; }
.reaction-op { font-size: 1.2rem; color: var(--text-muted); }
.reaction-conditions {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.cond-sep { margin: 0 6px; color: var(--border); }
.molecule {
  text-align: center;
}
.mol-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.mol-structure {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 1.1rem;
}
.mol-ring { color: #1e40af; }
.mol-sub { font-size: 0.75rem; color: var(--text-muted); text-align: left; line-height: 1.2; }
.mol-op { color: var(--text-muted); }
.reaction-vars h4 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.var-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.var-table tr { border-bottom: 1px solid var(--border); }
.var-table tr:last-child { border-bottom: none; }
.var-table td { padding: 7px 8px; vertical-align: top; }
.var-name { font-weight: 600; white-space: nowrap; padding-right: 12px; color: var(--text); width: 200px; }
.reaction-note {
  margin-top: 14px;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.6;
  border-left: 3px solid var(--teal);
  padding-left: 10px;
}

/* Responsive */
@media (max-width: 900px) {
  .level-cards { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .game-header { flex-direction: column; gap: 8px; align-items: flex-start; }
}
@media (max-width: 600px) {
  .entry-card { padding: 28px 20px; }
  .game-meta { font-size: 0.8rem; }
  .score-value { font-size: 2.5rem; }
}
