/* ================================================================
   CloseWord Design System — Heartopia cozy theme
   Core: pink/blue/purple soft candy colors on cream background
   ================================================================ */

/* --- CSS Variables (tokens) --- */
body[data-theme] {
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Quicksand', sans-serif;
  --font-accent: 'Nunito', sans-serif;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s ease;

  --btn-radius: var(--radius-full);
  --btn-padding: 0.7rem 1.5rem;
  --btn-padding-lg: 0.9rem 2rem;
  --btn-padding-sm: 0.45rem 1rem;
  --btn-font-size: 0.98rem;
  --btn-shadow: 0 6px 20px var(--shadow);
  --btn-shadow-hover: 0 10px 32px var(--shadow);
}

body[data-theme="core"] {
  --primary: #F8A5B8;
  --primary-light: #FFCAD4;
  --primary-dark: #E8899C;
  --secondary: #7BC8F6;
  --secondary-light: #A5DDFB;
  --secondary-dark: #5AADE0;
  --accent: #C9A0DC;
  --accent-light: #DFC5EC;
  --accent-dark: #A87DC2;
  --gold: #F5D76E;
  --success: #8ED16C;
  --success-dark: #6DB855;
  --warning: #F5916E;
  --bg-main: #FFF9F5;
  --bg-gradient: linear-gradient(135deg, #FFF9F5 0%, #F0F8FF 50%, #FFF5F8 100%);
  --card-bg: #FFFFFF;
  --border: #F0E6EB;
  --shadow: rgba(248, 165, 184, 0.15);
  --text-dark: #5D4E60;
  --text-medium: #6B5C70;
  --text-light: #807084;
}

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

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

body {
  font-family: var(--font-body);
  color: var(--text-dark);
  background: var(--bg-main);
  background-image: var(--bg-gradient);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout Shells --- */
body[data-shell="article"] .site-main { max-width: 900px; }
body[data-shell="hub"] .site-main { max-width: 1100px; }
body[data-shell="explorer"] .site-main { max-width: 1400px; }

.site-main {
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md) var(--space-3xl);
}

/* --- Header (frosted glass) --- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-md);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-decoration: none;
  display: flex; align-items: center; gap: 6px;
}

/* --- Navigation (pill style) --- */
.main-nav {
  display: flex; align-items: center; gap: 4px;
}

.nav-link, .nav-btn {
  padding: 0.4rem 1rem;
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.nav-link:hover, .nav-btn:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.nav-link.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  box-shadow: inset 0 -2px 0 0 var(--primary-dark);
}

.nav-btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.badge-new {
  background: var(--success);
  color: #FFF;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
  margin-left: 2px;
}

/* --- Game Container --- */
.game-container {
  animation: fadeIn 0.3s ease;
}

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

.game-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: var(--space-xs);
}

.game-date {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: var(--space-xs);
}

.game-subtitle {
  color: var(--text-light);
  font-size: 1.05rem;
  max-width: 500px;
  margin: 0 auto var(--space-md);
}

.game-meta {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
}

.meta-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-medium);
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

/* --- Guess Input Form --- */
.guess-form {
  max-width: 500px; margin: 0 auto var(--space-md);
}

.input-group {
  display: flex; gap: 8px;
}

.guess-input {
  flex: 1;
  padding: 0.85rem 1.2rem;
  font-family: var(--font-body);
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--card-bg);
  color: var(--text-dark);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.guess-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(248, 165, 184, 0.2);
}

.input-hint {
  font-size: 0.82rem;
  color: var(--warning);
  margin-top: 4px;
  min-height: 1.2em;
  text-align: center;
}

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: var(--btn-padding);
  font-family: var(--font-body);
  font-size: var(--btn-font-size);
  font-weight: 600;
  border: none;
  border-radius: var(--btn-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  color: #FFFFFF;
  box-shadow: var(--btn-shadow);
}

.btn-primary:hover { box-shadow: var(--btn-shadow-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: linear-gradient(135deg, var(--secondary-light) 0%, var(--secondary) 100%);
  color: #FFFFFF;
  box-shadow: var(--btn-shadow);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary-dark);
}

.btn-outline:hover {
  background: var(--primary);
  color: #FFFFFF;
}

.btn-sm { padding: var(--btn-padding-sm); font-size: 0.85rem; }
.btn-lg { padding: var(--btn-padding-lg); font-size: 1.1rem; }

.btn:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none;
  box-shadow: none;
}

/* --- Game Controls --- */
.game-controls {
  display: flex; justify-content: center; gap: 8px;
  margin-bottom: var(--space-lg); flex-wrap: wrap;
}

/* --- Guess List --- */
.guess-list {
  max-width: 600px; margin: 0 auto;
}

.guess-empty {
  text-align: center;
  color: var(--text-light);
  padding: var(--space-xl) 0;
}

.guess-empty p { margin-bottom: var(--space-md); }

.starter-words {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
}

.starter-chip {
  padding: 0.4rem 0.9rem;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--card-bg);
  color: var(--text-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.starter-chip:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-light);
  transform: translateY(-2px);
}

/* --- Guess Row --- */
.guess-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--border);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.guess-rank {
  font-weight: 700;
  font-size: 0.85rem;
  min-width: 42px;
  text-align: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.rank-hot { background: #D4EDDA; color: #155724; }
.rank-warm { background: #FFF3CD; color: #856404; }
.rank-mild { background: #FFE8D0; color: #8B5E00; }
.rank-cold { background: #EEEEEE; color: #888; }

.guess-word {
  flex: 1;
  font-weight: 600;
}

.guess-bar {
  flex: 0 0 80px;
  height: 6px;
  background: #EEE;
  border-radius: 3px;
  overflow: hidden;
}

.guess-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.bar-hot { background: var(--success); }
.bar-warm { background: var(--gold); }
.bar-mild { background: var(--warning); }
.bar-cold { background: #CCC; }

.guess-rank-text {
  font-size: 0.8rem;
  color: var(--text-light);
  min-width: 50px;
  text-align: right;
}

/* --- Win Modal --- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
  padding: var(--space-md);
}

.modal-overlay.open { display: flex; }

.modal-content {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  max-width: 500px; width: 100%;
  max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.win-modal { text-align: center; }

.win-title {
  font-family: var(--font-display);
  font-size: 2.2rem;
  margin-bottom: var(--space-sm);
}

.win-word { font-size: 1.2rem; color: var(--text-medium); margin-bottom: var(--space-md); }
.win-stats { margin-bottom: var(--space-md); color: var(--text-light); }
.win-share {
  background: #F8F9FA;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  font-family: monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  text-align: left;
  margin-bottom: var(--space-lg);
  max-height: 200px; overflow-y: auto;
}

.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.win-countdown { margin-top: var(--space-md); font-size: 0.85rem; color: var(--text-light); }

.modal-close {
  position: absolute; top: 12px; right: 16px;
  font-size: 1.6rem; font-weight: 300;
  background: none; border: none; cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}

.modal-close:hover { color: var(--text-dark); }

/* --- Modal Tabs --- */
.modal-tabs {
  display: flex; gap: 4px;
  margin-bottom: var(--space-lg);
  border-bottom: 2px solid var(--border);
}

.modal-tab {
  padding: 0.5rem 1.2rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-fast);
}

.modal-tab.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary-dark);
}

.modal-body { display: none; }
.modal-body.active { display: block; }

.modal-body ol, .modal-body ul { padding-left: 1.5rem; }
.modal-body li { margin-bottom: 0.5rem; }
.modal-body dt { font-weight: 700; margin-top: var(--space-md); }
.modal-body dd { color: var(--text-medium); margin-left: 0; }

.chip-hot, .chip-warm, .chip-cold {
  padding: 1px 6px; border-radius: var(--radius-full);
  font-size: 0.85rem; font-weight: 600;
}
.chip-hot { background: #D4EDDA; }
.chip-warm { background: #FFF3CD; }
.chip-cold { background: #EEEEEE; }

/* --- Stats --- */
.stats-tabs {
  display: flex; gap: 4px;
  justify-content: center;
  margin-bottom: var(--space-xl);
}

.stats-tab {
  padding: 0.5rem 1.5rem;
  font-family: var(--font-body);
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}

.stats-tab.active {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.stats-content { display: none; }
.stats-content.active { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  text-align: center;
  box-shadow: 0 4px 12px var(--shadow);
}

.stat-number {
  display: block;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
}

.guess-distribution {
  max-width: 400px; margin: 0 auto;
}

.dist-bar-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
}

.dist-label {
  min-width: 40px;
  font-size: 0.82rem;
  text-align: right;
  color: var(--text-light);
}

.dist-bar {
  flex: 1;
  height: 22px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  min-width: 2px;
  transition: width 0.3s ease;
}

.dist-count {
  min-width: 24px;
  font-size: 0.82rem;
  color: var(--text-medium);
}

/* --- Settings --- */
.setting-row {
  margin-bottom: var(--space-md);
  font-size: 1rem;
}

.setting-row label {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
}

.setting-row select {
  padding: 0.4rem 0.8rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 2px;
  margin-left: 24px;
}

/* --- Multiplayer Page --- */
.multiplayer-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
  max-width: 700px;
  margin: 0 auto;
}

.mp-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
  box-shadow: 0 4px 16px var(--shadow);
}

.mp-card-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-sm);
}

.mp-card h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin-bottom: var(--space-sm);
  color: var(--text-dark);
}

.mp-card p {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: var(--space-md);
}

/* --- Toast --- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 2000;
  padding: 0.7rem 1.5rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-full);
  background: var(--text-dark);
  color: #FFF;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.toast.show { opacity: 1; }

/* --- Footer --- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-md);
  text-align: center;
  background: rgba(255,255,255,0.7);
}

.footer-inner {
  max-width: 900px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: var(--space-sm);
  font-size: 0.85rem;
  color: var(--text-light);
}

.footer-nav { display: flex; gap: 16px; }

.footer-link {
  background: none; border: none;
  color: var(--text-light);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-link:hover { color: var(--primary-dark); }

/* --- Page Visibility --- */
.page { display: none; }
.page.active { display: block; }

/* --- Dark Mode --- */
body.dark {
  --bg-main: #1A1A2E;
  --bg-gradient: linear-gradient(135deg, #1A1A2E 0%, #16213E 50%, #1A1A2E 100%);
  --card-bg: #242444;
  --border: #3A3A5C;
  --text-dark: #E8E0F0;
  --text-medium: #C0B8D0;
  --text-light: #9088A0;
  --shadow: rgba(0,0,0,0.3);
}

body.dark .site-header {
  background: rgba(26,26,46,0.92);
}

body.dark .guess-input {
  background: #2A2A4A;
  border-color: #3A3A5C;
  color: #E8E0F0;
}

body.dark .guess-row { background: rgba(36,36,68,0.88); }
body.dark .rank-cold { background: #333355; color: #888; }
body.dark .guess-empty .starter-chip { background: #2A2A4A; border-color: #3A3A5C; }
body.dark .win-share { background: #1E1E3A; }
body.dark .site-footer { background: rgba(26,26,46,0.7); }
body.dark .modal-content { background: #242444; }
body.dark .toast { background: #3A3A5C; }

/* --- High Contrast --- */
body.highcontrast {
  --primary: #FF6B35;
  --primary-light: #FFA07A;
  --primary-dark: #D4521E;
  --secondary: #2196F3;
  --secondary-light: #64B5F6;
  --secondary-dark: #1565C0;
  --accent: #9C27B0;
  --border: #757575;
  --bg-main: #FAFAFA;
  --card-bg: #FFFFFF;
  --text-dark: #212121;
  --text-medium: #424242;
  --text-light: #616161;
}

/* --- Responsive --- */
@media (max-width: 1120px) {
  .header-inner { height: auto; flex-wrap: wrap; padding: 8px 0; }
  .main-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
}

@media (max-width: 768px) {
  .site-main { padding: var(--space-md) var(--space-sm) var(--space-2xl); }
  .game-title { font-size: 1.5rem; }
  .game-subtitle { font-size: 0.95rem; }
  .input-group { flex-direction: column; gap: 8px; }
  .guess-input { font-size: 1rem; padding: 0.75rem 1rem; min-width: 0; }
  .game-meta { gap: 4px; }
  .meta-badge { font-size: 0.7rem; padding: 2px 8px; }
  .game-controls { gap: 4px; flex-wrap: wrap; }
  .game-controls .btn { font-size: 0.78rem; padding: 0.35rem 0.7rem; }
  .guess-row { padding: 8px 10px; font-size: 0.88rem; gap: 6px; }
  .guess-rank { min-width: 36px; font-size: 0.75rem; }
  .guess-word { font-size: 0.88rem; }
  .guess-bar { flex: 0 0 50px; height: 4px; }
  .guess-rank-text { font-size: 0.7rem; min-width: 36px; }
  .win-actions { flex-direction: column; }
  .win-actions .btn { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-sm); }
  .stat-card { padding: var(--space-md); }
  .stat-number { font-size: 1.6rem; }
  .footer-inner { flex-direction: column; text-align: center; gap: 4px; }
  .modal-content { padding: var(--space-lg); max-width: 95vw; margin: var(--space-sm); }
  .starter-words { gap: 4px; }
  .starter-chip { font-size: 0.78rem; padding: 0.3rem 0.6rem; }
  .logo { font-size: 1.1rem; }
  .nav-link, .nav-btn { font-size: 0.78rem; padding: 0.3rem 0.7rem; }
  .nav-btn-icon { width: 30px; height: 30px; font-size: 0.95rem; }
  .header-inner { height: auto; min-height: 44px; padding: 6px var(--space-sm); }
}

@media (max-width: 400px) {
  .game-meta { flex-direction: column; align-items: center; }
  .game-title { font-size: 1.3rem; }
  .btn { font-size: 0.88rem; padding: 0.6rem 1rem; }
  .guess-row { padding: 6px 8px; }
  .header-inner { padding: 4px var(--space-sm); }
}

/* --- Loading Spinner --- */
.loading-spinner {
  padding: var(--space-3xl) 0;
}

.loading-spinner p {
  position: relative;
  padding-top: 3rem;
}

.loading-spinner p::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  width: 40px; height: 40px;
  margin-left: -20px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Accessibility --- */
:focus-visible {
  outline: 2px solid var(--primary-dark);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
