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

html {
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #090b0b;
  color: #ffffff;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: transparent;
  pointer-events: none;
}

.hotspot {
  position: fixed;
  border-radius: 50%;
  z-index: -1;
  pointer-events: none;
  will-change: transform;
}

/* Glass Card Base Styles */
.glass-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  position: relative;
  overflow: visible;
}

.glass-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 4px;
  padding: 1px;
  background: radial-gradient(
    var(--shine-radius, 150px) circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
    rgba(255, 255, 255, 0.25) 0%,
    transparent 100%
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.glass-card:hover::before {
  opacity: 1;
}

/* Auto-rotating shine mode */
.shine-auto .glass-card::before {
  background: conic-gradient(
    from var(--shine-angle, 0deg),
    transparent 0deg,
    transparent 60deg,
    rgba(255, 255, 255, 0.2) 90deg,
    transparent 120deg,
    transparent 180deg,
    rgba(255, 255, 255, 0.2) 210deg,
    transparent 240deg,
    transparent 360deg
  );
  animation: shine-spin 6s linear infinite;
}

@keyframes shine-spin {
  to {
    --shine-angle: 360deg;
  }
}

@property --shine-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: true;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  margin: 1rem 1.5rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #5ac4be, var(--theme-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls-wrapper {
  position: relative;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.lang-toggle,
.theme-toggle,
.scheme-toggle,
.smoothing-toggle {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(12px);
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  white-space: nowrap;
}

.lang-toggle:hover,
.theme-toggle:hover,
.scheme-toggle:hover,
.smoothing-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

#portfolio-summary {
  text-align: center;
  margin-bottom: 2rem;
  padding: 2rem 1.5rem;
}

#portfolio-summary .label {
  display: block;
  font-size: 0.875rem;
  color: #9ca3af;
  margin-bottom: 0.25rem;
}

.summary-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1rem;
}

.total-value {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 2.5rem;
  font-weight: 500;
}

.change {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 1.25rem;
}

.percent {
  font-size: 0.875rem;
}

.badge {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

#holdings-section {
  margin-top: 2.5rem;
  padding: 1.5rem;
}

#holdings-section h2 {
  font-size: 0.75rem;
  font-weight: 400;
  color: rgba(156, 163, 175, 0.7);
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.holdings-bar {
  display: flex;
  height: 28px;
  gap: 2px;
  margin-bottom: 1rem;
}

.bar-segment {
  height: 100%;
  min-width: 4px;
  opacity: 0.8;
  transition: transform 0.5s, opacity 0.5s, filter 0.5s;
  -webkit-tap-highlight-color: transparent;
}

.bar-segment:last-child {
  border-radius: 0 6px 6px 0;
}

.bar-segment:first-child {
  border-radius: 6px 0 0 6px;
}

/* Dim non-highlighted segments */
#holdings-section[data-highlight] .bar-segment {
  opacity: 0.4;
  filter: grayscale(0.6);
}

/* Highlight matching segment */
#holdings-section[data-highlight] .bar-segment.highlighted {
  opacity: 1;
  filter: none;
  transform: scaleY(1.15);
}

.bar-segment:first-child {
  border-radius: 6px 0 0 6px;
}

.bar-segment:last-child {
  border-radius: 0 6px 6px 0;
}

.holdings-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.holding-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 0.25rem 0.625rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid color-mix(in srgb, var(--pill-color) 30%, transparent);
  border-radius: 9999px;
  transition: opacity 0.5s, filter 0.5s, transform 0.5s;
  -webkit-tap-highlight-color: transparent;
}

/* Dim non-highlighted pills */
#holdings-section[data-highlight] .holding-pill {
  opacity: 0.4;
  filter: grayscale(0.6);
}

/* Highlight matching pill */
#holdings-section[data-highlight] .holding-pill.highlighted {
  opacity: 1;
  filter: none;
  transform: scale(1.05);
}

.holding-ticker {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--pill-color);
}

.holding-value {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.6875rem;
  color: #9ca3af;
}

.holding-percent {
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--pill-color);
  background: color-mix(in srgb, var(--pill-color) 15%, transparent);
  padding: 0.125rem 0.375rem;
  border-radius: 9999px;
}

#chart-section {
  margin-top: 2.5rem;
  padding: 1.5rem;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

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

#chart-section h2 {
  font-size: 0.75rem;
  font-weight: 400;
  color: rgba(156, 163, 175, 0.7);
  text-transform: uppercase;
}

.period-selector {
  display: flex;
  gap: 0.5rem;
}

.period-btn {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: #9ca3af;
  padding: 0.25rem 0.625rem;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.period-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.period-btn.active {
  background: var(--theme-color);
  color: #ffffff;
}

#portfolio-chart {
  width: 100%;
  height: 300px;
  display: block;
  cursor: crosshair;
  transition: opacity 0.3s, filter 0.3s;
}

.chart-tooltip {
  position: absolute;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  pointer-events: none;
  font-size: 0.75rem;
  line-height: 1.4;
  backdrop-filter: blur(12px);
}

.chart-tooltip.hidden {
  display: none;
}

.tooltip-date {
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 0.25rem;
}

.tooltip-value {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

footer {
  text-align: center;
  padding: 2rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 3rem;
}

footer p {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.35);
}

/* Color Scheme Variables */
:root {
  --theme-color: #7c3aed;
  --color-up: #22c55e;
  --color-up-bg: rgba(34, 197, 94, 0.15);
  --color-down: #ff6b6b;
  --color-down-bg: rgba(255, 107, 107, 0.15);

  /* Gradient Background - Forest Theme */
  --gradient-bg:
    radial-gradient(circle at 15% 25%, rgba(12, 65, 65, 0.4) 0%, transparent 50%),
    radial-gradient(circle at 85% 70%, rgba(10, 50, 60, 0.35) 0%, transparent 50%),
    #020708;
}

[data-scheme="chinese"] {
  --color-up: #ff6b6b;
  --color-up-bg: rgba(255, 107, 107, 0.15);
  --color-down: #22c55e;
  --color-down-bg: rgba(34, 197, 94, 0.15);
}

/* Gain/Loss Colors */
.up {
  color: var(--color-up);
}

.down {
  color: var(--color-down);
}

.up.badge {
  background: var(--color-up-bg);
}

.down.badge {
  background: var(--color-down-bg);
}

/* Loading Spinner */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 23, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #334155;
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Mobile Responsive */
@media (max-width: 640px) {
  .total-value {
    font-size: 1.75rem;
  }

  .change {
    font-size: 1rem;
  }

  .summary-row {
    gap: 0.75rem;
  }

  main {
    padding: 1rem 0.75rem;
  }

  #chart-section {
    padding: 1rem 0;
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0 0.75rem;
  }

  header {
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
    margin: 0.5rem 0;
    border-radius: 0;
  }

  .header-controls-wrapper {
    width: 100%;
  }

  .header-controls {
    overflow-x: auto;
    padding: 0.25rem 0.75rem;
    justify-content: safe center;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-mask-image: linear-gradient(
      to right,
      transparent,
      black 20px,
      black calc(100% - 20px),
      transparent
    );
    mask-image: linear-gradient(
      to right,
      transparent,
      black 20px,
      black calc(100% - 20px),
      transparent
    );
  }

  .header-controls.scroll-start {
    -webkit-mask-image: linear-gradient(
      to right,
      black,
      black calc(100% - 20px),
      transparent
    );
    mask-image: linear-gradient(
      to right,
      black,
      black calc(100% - 20px),
      transparent
    );
  }

  .header-controls.scroll-end {
    -webkit-mask-image: linear-gradient(
      to right,
      transparent,
      black 20px,
      black
    );
    mask-image: linear-gradient(
      to right,
      transparent,
      black 20px,
      black
    );
  }

  .header-controls.scroll-start.scroll-end {
    -webkit-mask-image: none;
    mask-image: none;
  }

  .header-controls::-webkit-scrollbar {
    display: none;
  }
}

/* Account Selector */
.account-selector {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  padding: 0.375rem 1.5rem 0.375rem 0.75rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(12px);
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='rgba(255,255,255,0.5)' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 6rem;
}

.account-selector:disabled {
  cursor: default;
  opacity: 0.6;
}

.account-selector:hover {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

.account-selector option {
  background: #1a1a1a;
  color: #fff;
}

/* Password Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: 90%;
  max-width: 320px;
  padding: 1.5rem;
  text-align: center;
}

.modal-content h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.modal-account-name {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.modal-content input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #fff;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.modal-content input[type="password"]:focus {
  border-color: var(--theme-color);
}

.modal-error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.75rem;
}

.modal-error.hidden {
  display: none;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.modal-btn {
  flex: 1;
  padding: 0.625rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.8);
}

.modal-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.modal-btn.primary {
  background: var(--theme-color);
  border-color: var(--theme-color);
  color: #fff;
}

.modal-btn.primary:hover {
  filter: brightness(1.1);
}

/* Loading States */
.total-value,
.change,
.percent {
  transition: color 0.3s ease-out, background 0.3s ease-out;
}

.loading .total-value,
.loading .change,
.loading .percent {
  color: transparent;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

.loading .total-value {
  min-width: 180px;
  min-height: 1.2em;
  display: inline-block;
}

.loading .change {
  min-width: 80px;
  min-height: 1.2em;
  display: inline-block;
}

.loading .percent {
  min-width: 60px;
  min-height: 1.2em;
  display: inline-block;
}

.holdings-bar {
  transition: opacity 0.3s ease-out;
}

.loading .holdings-bar {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  animation: pulse 1.5s ease-in-out infinite;
}

.loading .holdings-bar .bar-segment {
  filter: grayscale(1);
}

.holdings-list {
  transition: opacity 0.3s ease-out;
}

.loading .holdings-list {
  opacity: 0;
}

#portfolio-chart {
  transition: opacity 0.3s ease-out, filter 0.3s ease-out;
}

#chart-section.loading #portfolio-chart {
  opacity: 0.3;
  filter: grayscale(1);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}
