:root,
html[data-theme="dark"] {
  --theme-color: #FF6033;
  --theme-color-rgb: 255, 96, 51;
  --bg-primary: #000000;
  --bg-secondary: #111111;
  --bg-card: #161616;
  --text-primary: #ffffff;
  --text-secondary: #dddddd;
  --text-muted: rgba(255, 255, 255, 0.54);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --badge-bg: #161616;
  --badge-text: #ffffff;
  --widget-bg: #161616;
  --activity-bg-0: #111111;
}

/* Light theme overrides */
html[data-theme="light"] {
  --theme-color: #E54D26;
  --theme-color-rgb: 229, 77, 38;
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-card: #ffffff;
  --text-primary: #111111;
  --text-secondary: #444444;
  --text-muted: rgba(0, 0, 0, 0.6);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --badge-bg: #f0f0f0;
  --badge-text: #111111;
  --widget-bg: #f9f9f9;
  --activity-bg-0: #eeeeee;
}

html {
  transition: background-color 0.4s ease, color 0.4s ease;
}

*,
*::before,
*::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

html,
body {
  position: relative;
  padding: 0;
  margin: 0;
}

body {
  font-size: 16px;
  line-height: 1.5;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
}

a {
  color: var(--theme-color);
}

h1 {
  font-size: 3em;
  line-height: 1.2;
}

h2 {
  font-size: 2.5em;
  line-height: 1.25;
  margin: 0.75em 0 0.5em;
}

main {
  margin: 0 auto;
  max-width: 1200px;
  padding: 0 40px;
  box-sizing: border-box;
}

header,
section,
footer {
  margin: 40px 0;
}

/* Accessibility: Skip link */
.skip-link {
  position: absolute;
  top: -9999px;
  left: -9999px;
  z-index: 999;
  padding: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: bold;
  border: 2px solid var(--theme-color);
}

.skip-link:focus {
  top: 0;
  left: 0;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.avatar {
  border: 4px solid var(--text-muted);
  border-radius: 50%;
  width: 20%;
  margin-right: 40px;
  height: auto;
}

.header-content {
  width: 100%;
  min-width: 0;
}

header h1 {
  line-height: 1.2;
  margin: 0;
}

.subtitle {
  margin: 1em 0;
}

.subtitle span.dot {
  font-size: 14px;
  opacity: 0.5;
}

.subtitle span[role="img"] {
  vertical-align: middle;
  font-size: 1.5em;
}

.contacts a {
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  margin-right: 8px;
  margin-bottom: 8px;
  display: inline-flex;
  font-size: 14px;
  align-items: center;
  vertical-align: middle;
  transition: background 0.2s ease;
}

html[data-theme="light"] .contacts a {
  background: rgba(0, 0, 0, 0.06);
}

.contacts a:hover {
  background: rgba(255, 255, 255, 0.125);
}

html[data-theme="light"] .contacts a:hover {
  background: rgba(0, 0, 0, 0.09);
}

.contacts a:focus {
  outline: 2px solid var(--theme-color);
}

.contacts a:active {
  background: rgba(255, 255, 255, 0.075);
}

html[data-theme="light"] .contacts a:active {
  background: rgba(0, 0, 0, 0.04);
}

.contacts .icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  margin-right: 8px;
}

.contacts img {
  max-width: 100%;
  max-height: 100%;
}

/* Widgets */
.branding {
  margin-top: -0.25em;
  margin-bottom: 2em;
}

.widget {
  --preloader-color: var(--theme-color);
}

.widget+.widget {
  margin-top: 16px;
}

codersrank-summary {
  --bg-color: transparent;
  --badge-bg-color: var(--badge-bg);
  --badge-text-color: var(--badge-text);
  --badges-padding: 0px;
  --badge-padding: 8px;
  --badge-margin: 16px;
  --badge-border-radius: 8px;
  --badge-rank-font-size: 16px;
  --badge-technology-font-size: 18px;
  --badge-location-font-size: 16px;
  --badge-icon-size: 32px;
  --badge-border: 1px solid var(--border-subtle);
  --badge-box-shadow: none;
}

.activity-widget {
  padding: 8px;
  border-radius: 8px;
  background: var(--widget-bg);
}

codersrank-activity {
  --bg-color-0: var(--activity-bg-0);
  --bg-color-1: rgba(var(--theme-color-rgb), 0.25);
  --bg-color-2: rgba(var(--theme-color-rgb), 0.5);
  --bg-color-3: rgba(var(--theme-color-rgb), 0.75);
  --bg-color-4: rgba(var(--theme-color-rgb), 1);
  --label-text-color: var(--text-muted);
  --svg-width: 1080px;
  display: flex;
  justify-content: flex-end;
  overflow: hidden;
  padding-top: 100px;
  margin-top: -100px;
}

codersrank-skills-chart {
  --label-text-color: var(--text-muted);
  --chart-bg-color: var(--widget-bg);
  --chart-border-radius: 8px;
  --axis-bg-color: transparent;
  --label-font-size: 12px;
  overflow: hidden;
}

codersrank-portfolio,
codersrank-work-experience,
codersrank-education {
  --item-bg-color: var(--bg-card);
  --item-border-radius: 8px;
  --item-spacing: 16px;
  --item-padding: 16px;
  --logo-size: 64px;
  --tag-bg-color: rgba(255, 255, 255, 0.075);
}

html[data-theme="light"] codersrank-portfolio,
html[data-theme="light"] codersrank-work-experience,
html[data-theme="light"] codersrank-education {
  --tag-bg-color: rgba(0, 0, 0, 0.07);
}

codersrank-portfolio {
  --grid-columns: 2;
  --link-text-color: var(--theme-color);
  --link-bg-color: rgba(255, 255, 255, 0.1);
  --link-hover-bg-color: rgba(255, 255, 255, 0.125);
  --link-active-bg-color: rgba(255, 255, 255, 0.075);
  --link-border-radius: 8px;
  --link-padding: 4px 8px;
  --link-text-transform: none;
  --link-font-weight: 500;
  --link-margin: 8px;
}

html[data-theme="light"] codersrank-portfolio {
  --link-bg-color: rgba(0, 0, 0, 0.06);
  --link-hover-bg-color: rgba(0, 0, 0, 0.09);
  --link-active-bg-color: rgba(0, 0, 0, 0.04);
}

/* Footer */
footer {
  text-align: center;
  opacity: 0.65;
  color: var(--text-muted);
}

/* Dynamic Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 24px 0 40px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  border: 1px solid var(--border-subtle);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:focus-within {
  outline: 2px solid var(--theme-color);
}

.stat-number {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--theme-color);
  display: block;
}

.stat-label {
  font-size: 14px;
  opacity: 0.6;
  margin-top: 4px;
  color: var(--text-muted);
}

/* Blog section */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.blog-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  margin: 8px 0;
  border: 1px solid var(--border-subtle);
  transition: transform 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
  height: calc(100% - 18px);
}

.blog-card:hover {
  transform: translateY(-4px);
  border-color: rgba(var(--theme-color-rgb), 0.4);
}

.blog-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 12px;
}

.blog-card h3 {
  font-size: 1.1rem;
  margin: 0 0 8px;
  line-height: 1.3;
  flex-grow: 0;
}

.blog-card h3 a {
  color: var(--text-primary);
  text-decoration: none;
}

.blog-card h3 a:hover {
  color: var(--theme-color);
}

.blog-card p {
  font-size: 0.9rem;
  opacity: 0.8;
  margin: 0 0 12px;
  flex-grow: 1;
  display: -webkit-box;
  line-clamp: 3;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
  color: var(--text-secondary);
}

.blog-card a.read-more {
  color: var(--theme-color);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  margin-top: auto;
  align-self: flex-start;
}

.blog-card a.read-more:hover {
  text-decoration: underline;
}

.view-all-btn {
  display: inline-block;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.2s ease;
}

html[data-theme="light"] .view-all-btn {
  background: rgba(0, 0, 0, 0.06);
}

.view-all-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

html[data-theme="light"] .view-all-btn:hover {
  background: rgba(0, 0, 0, 0.09);
}

/* Media queries */
@media (max-width: 768px) {
  header {
    display: block;
  }

  .avatar {
    width: 160px;
    margin-bottom: 20px;
  }

  codersrank-portfolio,
  codersrank-work-experience,
  codersrank-education {
    --grid-columns: 1;
    --item-spacing: 8px;
    --logo-size: 48px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .blog-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .blog-card {
    padding: 14px;
  }

  .blog-card img {
    height: 120px;
  }
}

@media (max-width: 640px) {
  main {
    padding-left: 20px;
    padding-right: 20px;
  }

  h1 {
    font-size: 2em;
  }

  h2 {
    font-size: 1.5em;
  }

  .widget+.widget {
    margin-top: 8px;
  }

  codersrank-summary {
    --badge-margin: 8px;
  }

  codersrank-activity {
    --svg-width: 640px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

html[data-theme="light"] .theme-toggle {
  background: rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.theme-toggle:hover {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.15);
}

html[data-theme="light"] .theme-toggle:hover {
  background: rgba(0, 0, 0, 0.12);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--theme-color);
  outline-offset: 4px;
}

/* Icons inside toggle */
.theme-toggle svg {
  width: 24px;
  height: 24px;
  position: absolute;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-primary);
}

.theme-toggle .sun-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.theme-toggle .moon-icon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* When in light mode: show sun, hide moon */
html[data-theme="light"] .theme-toggle .sun-icon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

html[data-theme="light"] .theme-toggle .moon-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

/* Optional: Add a subtle animation on toggle */
.theme-toggle:active {
  transform: scale(0.95);
}