/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e2b96f;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --check-color: #4ade80;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

body {
  font-family: 'Segoe UI', 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  background: linear-gradient(180deg, #0d0d1f 0%, var(--bg) 100%);
  border-bottom: 1px solid #2a2a4a;
}

.logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--accent);
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

/* ===== Main ===== */
main { flex: 1; max-width: 1100px; margin: 0 auto; padding: 2rem 1.2rem; width: 100%; }

/* ===== Game Grid (home) ===== */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.game-card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.game-card-banner {
  width: 100%;
  aspect-ratio: 16/9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  position: relative;
  overflow: hidden;
}

.game-card-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.5) 100%);
}

.game-card-emoji {
  font-size: 3.5rem;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
  z-index: 1;
}

.game-card-banner-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  text-align: center;
  padding: 0 1rem;
  z-index: 1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  line-height: 1.3;
}

.game-card-body {
  padding: 1rem 1.2rem 1.2rem;
}

.game-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
}

.game-card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.progress-bar-wrap {
  margin-top: 0.9rem;
  background: #2a2a4a;
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--check-color);
  transition: width 0.4s ease;
}

.progress-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* ===== Game Detail ===== */
#detail-view { display: none; }

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 1.2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.back-btn {
  background: #2a2a4a;
  border: none;
  color: var(--text);
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.back-btn:hover { background: #3a3a6a; }

.detail-title-block h1 {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
}
.detail-title-block p { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.3rem; }

.total-progress {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.2rem 1.5rem;
  margin-bottom: 1.8rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}

.total-progress-text {
  font-size: 1rem;
  font-weight: 600;
}

.total-progress-bar-wrap {
  flex: 1;
  min-width: 120px;
  background: #2a2a4a;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.total-progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4ade80, #22d3ee);
  transition: width 0.4s ease;
}

.total-progress-pct {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}

.reset-btn {
  background: transparent;
  border: 1px solid #444;
  color: var(--text-muted);
  padding: 0.35rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.reset-btn:hover { border-color: #e05; color: #e05; }

/* ===== Category / Tips ===== */
.category-block {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 1.2rem;
  overflow: hidden;
}

.category-header {
  padding: 0.85rem 1.3rem;
  background: var(--surface2);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.category-header:hover { background: #1e2a4a; }

.expand-all-btn {
  background: transparent;
  border: 1px solid #3a3a6a;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.expand-all-btn:hover { border-color: var(--accent); color: var(--accent); }
.expand-all-btn.active { background: rgba(226,185,111,0.12); border-color: var(--accent); color: var(--accent); }

.category-progress-badge {
  font-size: 0.75rem;
  background: #2a2a4a;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  color: var(--text-muted);
}

.category-progress-badge.done {
  background: rgba(74,222,128,0.2);
  color: var(--check-color);
}

.category-body { padding: 0.5rem 0; }

.tip-item {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 0.65rem 1.3rem;
  transition: background 0.12s;
}
.tip-item:hover { background: rgba(255,255,255,0.03); }

.tip-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid #444;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: all 0.15s;
  background: transparent;
  cursor: pointer;
}
.tip-item.checked .tip-checkbox {
  background: var(--check-color);
  border-color: var(--check-color);
}

.tip-content { flex: 1; min-width: 0; }

.tip-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.tip-text {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  transition: color 0.15s;
  cursor: pointer;
}
.tip-item.checked .tip-text {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: #555;
}

/* Detail expand button */
.detail-toggle {
  flex-shrink: 0;
  background: #2a2a4a;
  border: 1px solid #3a3a6a;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 1px;
  padding: 0;
}
.detail-toggle:hover, .detail-toggle.open {
  background: #3a3a6a;
  color: var(--accent);
  border-color: var(--accent);
}

/* Detail content */
.tip-detail {
  margin-top: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Reference links */
.links-section {
  margin: 0.4rem 1.3rem 1rem;
  padding: 0.7rem 1rem;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  border: 1px solid #2a2a4a;
}
.links-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.links-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.ref-link {
  display: inline-block;
  font-size: 0.78rem;
  color: #7eb8f7;
  background: rgba(100,160,255,0.1);
  border: 1px solid rgba(100,160,255,0.2);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.ref-link:hover {
  background: rgba(100,160,255,0.2);
  border-color: rgba(100,160,255,0.4);
  color: #aad4ff;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid #2a2a4a;
}

/* ===== Chat Widget ===== */
#chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
}

#chat-fab {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a6fa5, #6a4fa5);
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#chat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,0.5); }

#chat-panel {
  display: none;
  flex-direction: column;
  width: 340px;
  height: 480px;
  background: #1a1a2e;
  border: 1px solid #2a2a4a;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  background: #16213e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}
#chat-header-info { display: flex; flex-direction: column; gap: 0.1rem; }
#chat-title { font-weight: 700; font-size: 0.95rem; }
#chat-subtitle { font-size: 0.72rem; color: var(--text-muted); }
#chat-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.15s;
}
#chat-close:hover { color: var(--text); }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scroll-behavior: smooth;
}

.chat-msg { display: flex; }
.chat-msg.user  { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: 82%;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, #4a6fa5, #6a4fa5);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant .chat-bubble {
  background: #252540;
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-bubble.loading {
  color: var(--text-muted);
  font-style: italic;
}
.chat-bubble.loading::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-left: 6px;
  animation: blink 1s infinite;
  vertical-align: middle;
}
@keyframes blink { 0%,100%{opacity:0.2} 50%{opacity:1} }

#chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-top: 1px solid #2a2a4a;
  background: #16213e;
  flex-shrink: 0;
  align-items: flex-end;
}
#chat-input {
  flex: 1;
  background: #252540;
  border: 1px solid #3a3a6a;
  border-radius: 10px;
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
}
#chat-input:focus { outline: none; border-color: #5a5aaa; }
#chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a6fa5, #6a4fa5);
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
#chat-send:not(:disabled):hover { opacity: 0.85; }

/* ===== Responsive ===== */
@media (max-width: 500px) {
  .logo { font-size: 1.5rem; }
  .detail-title-block h1 { font-size: 1.3rem; }
  .tip-item { padding: 0.6rem 1rem; }
  .category-header { padding: 0.7rem 1rem; }
}
