:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-page: #0b0f17;
  --bg-card: #111827;
  --bg-surface: #1a2333;
  --bg-elevated: #232f44;
  --border-color: rgba(255, 255, 255, 0.1);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;

  --theme-blue: #0ea5e9;
  --theme-blue-soft: rgba(14, 165, 233, 0.22);
  --span-gold: #f59e0b;
  --span-gold-soft: rgba(245, 158, 11, 0.24);
  --drag-indigo: #818cf8;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, 0.16);
  --danger: #ef4444;

  --header-bg: rgba(11, 15, 23, 0.9);
  --header-border: rgba(255, 255, 255, 0.08);
  --footer-bg: #080b11;
  --footer-border: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-surface: #f1f5f9;
  --bg-elevated: #e2e8f0;
  --border-color: rgba(15, 23, 42, 0.11);
  --text-main: #0f172a;
  --text-muted: #475569;

  --theme-blue: #0284c7;
  --theme-blue-soft: rgba(2, 132, 199, 0.18);
  --span-gold: #d97706;
  --span-gold-soft: rgba(217, 119, 6, 0.2);
  --drag-indigo: #4f46e5;
  --accent: #059669;
  --accent-soft: rgba(5, 150, 105, 0.12);
  --danger: #dc2626;

  --header-bg: rgba(255, 255, 255, 0.92);
  --header-border: rgba(15, 23, 42, 0.08);
  --footer-bg: #f1f5f9;
  --footer-border: rgba(15, 23, 42, 0.08);
}

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

body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

.hilos-badge-daily {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--theme-blue-soft);
  color: var(--theme-blue);
}

.hilos-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-pill {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
  font-family: var(--font-main);
}

.btn-pill.active, .btn-pill:hover {
  background: var(--theme-blue);
  border-color: var(--theme-blue);
  color: #ffffff;
}

.btn-icon-sq {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hilos-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.hilos-layout-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 1.35rem;
  align-items: start;
}

.hilos-theme-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
  text-align: center;
}

.hilos-theme-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.hilos-theme-title {
  margin: 0.25rem 0 0;
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
}

.hilos-active-word {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.hilos-active-word.status-theme { color: var(--theme-blue); }
.hilos-active-word.status-span { color: var(--span-gold); }
.hilos-active-word.status-bonus { color: var(--accent); }
.hilos-active-word.status-err { color: var(--danger); }

.hilos-board-wrap {
  position: relative;
  width: 100%;
  max-width: 390px;
  margin: 0 auto;
  aspect-ratio: 6 / 8;
  touch-action: none;
  user-select: none;
}

.hilos-svg-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.hilos-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  gap: 6px;
}

.hilos-cell {
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--bg-surface);
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: clamp(1rem, 3.6vw, 1.32rem);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  padding: 0;
}

.hilos-cell.is-dragging {
  background: var(--drag-indigo);
  color: #ffffff;
  transform: scale(1.06);
}

.hilos-cell.is-found-theme {
  background: var(--theme-blue);
  color: #ffffff;
}

.hilos-cell.is-found-span {
  background: var(--span-gold);
  color: #111827;
}

.hilos-cell.is-hinted {
  border: 2.5px dashed var(--theme-blue);
  box-shadow: 0 0 0 3px var(--theme-blue-soft);
}

.hilos-board-actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.hilos-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  border-radius: 10px;
  padding: 0.48rem 0.85rem;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
  font-family: var(--font-main);
}

.hilos-btn.primary { background: var(--theme-blue); border-color: var(--theme-blue); color: #fff; }
.hilos-btn.hint-ready { background: var(--accent); border-color: var(--accent); color: #fff; }
.hilos-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Side info panel */
.hilos-side-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.hilos-meter-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.hilos-meter-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.hilos-meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--theme-blue), var(--accent));
  width: 0%;
  transition: width 0.25s ease;
}

.hilos-found-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.hilos-chip {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.28rem 0.55rem;
  border-radius: 8px;
  background: var(--theme-blue-soft);
  color: var(--theme-blue);
}

.hilos-chip.span {
  background: var(--span-gold-soft);
  color: var(--span-gold);
}

.hilos-chip.pending {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px dashed var(--border-color);
}

.hilos-practice-bar {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  background: var(--theme-blue-soft);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
}

.hilos-practice-bar.open { display: flex; }

/* Modals */
.hilos-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.hilos-modal-backdrop.open { display: flex; }

.hilos-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  max-width: 470px;
  width: 100%;
  padding: 1.35rem;
  max-height: 90vh;
  overflow-y: auto;
}

.hilos-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.hilos-modal-title { margin: 0; font-family: var(--font-heading); font-size: 1.2rem; }
.hilos-modal-close { border: 1px solid var(--border-color); background: var(--bg-surface); color: var(--text-main); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }

.hilos-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.hilos-stat-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.65rem 0.4rem;
  text-align: center;
}

.hilos-stat-num { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 800; }
.hilos-stat-lbl { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

.hilos-share-preview {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  white-space: pre-wrap;
  margin-bottom: 1rem;
}

.hilos-modal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.hilos-action-btn {
  flex: 1 1 120px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-family: var(--font-main);
  font-weight: 700;
  cursor: pointer;
}
.hilos-action-btn.primary { background: var(--theme-blue); border-color: var(--theme-blue); color: #fff; }

.hilos-countdown-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hilos-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 3000;
}
.hilos-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .hilos-layout-split { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .hilos-card { padding: 0.9rem 0.75rem; }
  .hilos-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
