
:root {
  --bg: #0b1020;
  --bg-soft: #0e1530;
  --surface: #111830;
  --text: #e8eefc;
  --muted: #9fb0d3;
  --accent: #5dd4c6;
  --accent-2: #7aa8ff;
  --ring-shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 42%;
  
  --gradient-1: #1a2448;
  --gradient-2: #131b35;
  --gradient-3: #0f1628;
  --gradient-4: #0c1322;
  --gradient-5: #0b1020;
  --gradient-6: #090d1b;
  --gradient-7: #070a15;
  --gradient-8: #05070f;
}

/* Light theme colors */
:root.light-theme,
:root[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-soft: #eef1f7;
  --surface: #ffffff;
  --text: #1a1d2e;
  --muted: #6b7280;
  --accent: #00a896;
  --accent-2: #4a90e2;
  --ring-shadow: 0 10px 30px rgba(0,0,0,.1);
  
  --gradient-1: #e8f0ff;
  --gradient-2: #ecf2f9;
  --gradient-3: #f0f4f9;
  --gradient-4: #f3f6fa;
  --gradient-5: #f5f7fb;
  --gradient-6: #f8f9fc;
  --gradient-7: #fafbfd;
  --gradient-8: #ffffff;
}

/* Auto light theme based on system preference */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f7fb;
    --bg-soft: #eef1f7;
    --surface: #ffffff;
    --text: #1a1d2e;
    --muted: #6b7280;
    --accent: #00a896;
    --accent-2: #4a90e2;
    --ring-shadow: 0 10px 30px rgba(0,0,0,.1);
    
    --gradient-1: #e8f0ff;
    --gradient-2: #ecf2f9;
    --gradient-3: #f0f4f9;
    --gradient-4: #f3f6fa;
    --gradient-5: #f5f7fb;
    --gradient-6: #f8f9fc;
    --gradient-7: #fafbfd;
    --gradient-8: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: linear-gradient(180deg, var(--gradient-1) 0%, var(--gradient-2) 15%, var(--gradient-3) 30%, var(--gradient-4) 45%, var(--gradient-5) 60%, var(--gradient-6) 75%, var(--gradient-7) 90%, var(--gradient-8) 100%);
  background-attachment: fixed;
  min-height: 100%;
}

body {
  height: 100%;
  background: transparent;
  color: var(--text);
  margin: 0;
  font: 16px/1.3 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden; clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

.wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 20px 20px;
  gap: 40px;
}

.card {
  width: min(750px, 92vw);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  box-shadow: var(--ring-shadow);
  padding: clamp(14px, 2vw, 20px);
}

:root.light-theme .card,
:root[data-theme="light"] .card {
  background: linear-gradient(180deg, rgba(0,0,0,0.02), rgba(0,0,0,0.01));
  border: 1px solid rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .card {
    background: linear-gradient(180deg, rgba(0,0,0,0.02), rgba(0,0,0,0.01));
    border: 1px solid rgba(0,0,0,0.1);
  }
}

.logo {
  height: clamp(80px, 8vw, 100px);
  width: auto;
  object-fit: contain;
  display: block;
}

.byline { 
  color: var(--muted); 
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 12px;
}

.controls {
  margin: 8px 0 12px 0;
}

.control { 
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.input-wrapper {
  position: relative;
  width: 100%;
}

input[type="text"] {
  width: 100%;
  background: #282b47;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 12px 44px 12px 12px;
  font-size: 16px;  /* Fixed at 16px to prevent iOS zoom */
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
  text-transform: uppercase;
  letter-spacing: .06em;
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(93,212,198,0.15);
}

:root.light-theme input[type="text"],
:root[data-theme="light"] input[type="text"] {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.15);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) input[type="text"] {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.15);
  }
}

.hint {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 2px;
  text-align: center;
}

.clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
}
.clear-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }

.ring-wrap { display: grid; place-items: center; padding: 8px; }

.ring {
  position: relative;
  width: clamp(240px, min(50vh, 65vw), 420px);
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  background: radial-gradient(60% 60% at 55% 45%, rgba(122,168,255,0.10) 0%, rgba(122,168,255,0.03) 40%, transparent 65%),
              radial-gradient(60% 60% at 45% 55%, rgba(93,212,198,0.12) 0%, rgba(93,212,198,0.03) 45%, transparent 70%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08), var(--ring-shadow);
  overflow: hidden;
  isolation: isolate;
}

:root.light-theme .ring,
:root[data-theme="light"] .ring {
  background: radial-gradient(60% 60% at 55% 45%, rgba(74,144,226,0.12) 0%, rgba(74,144,226,0.04) 40%, transparent 65%),
              radial-gradient(60% 60% at 45% 55%, rgba(0,168,150,0.15) 0%, rgba(0,168,150,0.05) 45%, transparent 70%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), var(--ring-shadow);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .ring {
    background: radial-gradient(60% 60% at 55% 45%, rgba(74,144,226,0.12) 0%, rgba(74,144,226,0.04) 40%, transparent 65%),
                radial-gradient(60% 60% at 45% 55%, rgba(0,168,150,0.15) 0%, rgba(0,168,150,0.05) 45%, transparent 70%);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), var(--ring-shadow);
  }
}

.glyph {
  position: absolute;
  left: 50%; top: 50%;
  transform-origin: center center;
  font-weight: 700;
  user-select: none;
  pointer-events: auto;
  text-shadow: 0 1px 0 rgba(0,0,0,.25);
  transition: transform 480ms cubic-bezier(.22,1,.36,1), opacity .2s ease;
  will-change: transform;
}

.glyph .bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--fs, 28px) * 1.2);
  height: calc(var(--fs, 28px) * 1.2);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.02));
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  font-size: var(--fs, 28px);
  line-height: 1;
  color: var(--text);
  padding-bottom: 0.08em;
}

:root.light-theme .glyph .bubble,
:root[data-theme="light"] .glyph .bubble {
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.85));
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .glyph .bubble {
    background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.85));
    border: 1px solid rgba(0,0,0,0.12);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  }
}

.center-btn {
  position: absolute;
  left: 50%; 
  top: 50%; 
  transform: translate(-50%, -50%);
  transform-origin: center center;
  width: clamp(60px, 12%, 90px);
  height: auto;
  cursor: pointer;
  transition: transform .18s ease, filter .2s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.center-btn:hover { 
  filter: brightness(1.1); 
  transform: translate(-50%, -50%) scale(1.05);
}
.center-btn:active { 
  filter: brightness(0.95);
  transform: translate(-50%, -50%) scale(.96); 
}

.footer { 
  margin-top: 10px; 
  color: var(--muted); 
  font-size: .88rem; 
  text-align: center;
}
.kbd { 
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; 
  background: rgba(255,255,255,0.08); 
  border: 1px solid rgba(255,255,255,0.14); 
  padding: 2px 6px; 
  border-radius: 6px; 
}

:root.light-theme .kbd,
:root[data-theme="light"] .kbd {
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .kbd {
    background: rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.12);
  }
}

.empty { color: var(--muted); text-align: center; opacity: .9; }

@media (prefers-reduced-motion: no-preference) {
  .ring.spin .glyph { transition-duration: 620ms; }
  .center-btn.bounce { animation: pop .28s ease; }
  @keyframes pop { 
    0% { transform: translate(-50%, -50%) scale(1); } 
    50% { transform: translate(-50%, -50%) scale(1.06); } 
    100% { transform: translate(-50%, -50%) scale(1); } 
  }
}

/* Mobile optimizations */
@media (max-width: 640px) {
  body {
    overflow-x: hidden;
  }
  
  .wrap {
    min-height: auto;
    justify-content: flex-start;
    padding: 20px 20px 80px;
    width: 100%;
    max-width: 100vw;
    gap: 24px;
  }
  
  .logo {
    height: 60px;
  }
  
  .card {
    width: 100%;
    max-width: 100%;
    padding: 14px;
    border-radius: 16px;
  }
  
  .byline {
    font-size: 0.85rem;
    margin-bottom: 10px;
  }
  
  .controls {
    margin: 8px 0 12px 0;
    width: 100%;
  }
  
  .control {
    width: 100%;
  }
  
  .input-wrapper {
    width: 100%;
  }
  
  input[type="text"] {
    width: 100%;
    padding: 12px 44px 12px 12px;
    font-size: 16px;
    border-radius: 12px;
  }
  
  .clear-btn {
    right: 4px;
    width: 38px;
    height: 38px;
  }
  
  .hint {
    font-size: 0.85rem;
    margin-top: 4px;
  }
  
  #shuffleCenter {
    width: 70px;
    height: auto;
  }
  
  .ring {
    width: min(calc(100vw - 88px), 85vh);
    max-width: 100%;
  }
  
  .ring-wrap {
    padding: 12px 0;
    width: 100%;
  }
  
  .footer {
    margin-top: 12px;
    font-size: 0.85rem;
  }
}

/* Buy Me a Coffee widget wrapper */
.bmc-wrapper {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
}

@media (max-width: 640px) {
  .bmc-wrapper {
    right: auto;
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    bottom: 8px;
  }
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-top: 15px;
}

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

.theme-toggle:active {
  transform: scale(0.95);
}

/* Tooltip for theme toggle */
.theme-toggle::after {
  content: 'Toggle light/dark theme';
  position: absolute;
  bottom: -40px;
  right: 0;
  background: rgba(0,0,0,0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  font-weight: 500;
}

.theme-toggle:hover::after {
  opacity: 1;
}

:root.light-theme .theme-toggle::after,
:root[data-theme="light"] .theme-toggle::after {
  background: rgba(0,0,0,0.85);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle::after {
    background: rgba(0,0,0,0.85);
  }
}

:root.light-theme .theme-toggle,
:root[data-theme="light"] .theme-toggle {
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.12);
}

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

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle {
    background: rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.12);
  }
  :root:not([data-theme="dark"]) .theme-toggle:hover {
    background: rgba(0,0,0,0.08);
  }
}

@media (max-width: 640px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    padding: 8px 10px;
    font-size: 18px;
    margin-right: 10px;
  }
  
  /* Hide tooltips on mobile */
  .theme-toggle::after,
  .install-button::after {
    display: none;
  }
}

/* Install Button */
.install-button {
  position: fixed;
  top: 20px;
  right: 74px;
  z-index: 10000;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-top: 15px;
  margin-left: 10px;
}

.install-button.show {
  display: flex;
}

.install-button:hover {
  background: rgba(255,255,255,0.12);
  transform: scale(1.05);
}

.install-button:active {
  transform: scale(0.95);
}

/* Tooltip for install button */
.install-button::after {
  content: 'Install as app';
  position: absolute;
  bottom: -40px;
  right: 0;
  background: rgba(0,0,0,0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  font-weight: 500;
}

.install-button:hover::after {
  opacity: 1;
}

:root.light-theme .install-button::after,
:root[data-theme="light"] .install-button::after {
  background: rgba(0,0,0,0.85);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .install-button::after {
    background: rgba(0,0,0,0.85);
  }
}

:root.light-theme .install-button,
:root[data-theme="light"] .install-button {
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.12);
}

:root.light-theme .install-button:hover,
:root[data-theme="light"] .install-button:hover {
  background: rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .install-button {
    background: rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.12);
  }
  :root:not([data-theme="dark"]) .install-button:hover {
    background: rgba(0,0,0,0.08);
  }
}

@media (max-width: 640px) {
  .install-button {
    top: 12px;
    left: 12px;
    right: auto;
    width: 40px;
    height: 40px;
    padding: 8px 10px;
    font-size: 18px;
  }
}

/* Mobile Install Banner */
.mobile-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, rgba(93, 212, 198, 0.95), rgba(74, 168, 159, 0.95));
  color: white;
  padding: 16px 20px;
  z-index: 10001;
  display: none;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  animation: slideUp 0.3s ease;
}

.mobile-install-banner.show {
  display: flex;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.mobile-install-banner-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-install-banner-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.mobile-install-banner-text {
  flex: 1;
}

.mobile-install-banner-title {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 2px;
}

.mobile-install-banner-subtitle {
  font-size: 13px;
  opacity: 0.9;
}

.mobile-install-banner-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.mobile-install-banner-btn {
  background: white;
  color: #00a896;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.mobile-install-banner-btn:active {
  transform: scale(0.95);
}

.mobile-install-banner-close {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.5);
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

:root.light-theme .mobile-install-banner,
:root[data-theme="light"] .mobile-install-banner {
  background: linear-gradient(180deg, rgba(0, 168, 150, 0.95), rgba(0, 138, 123, 0.95));
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .mobile-install-banner {
    background: linear-gradient(180deg, rgba(0, 168, 150, 0.95), rgba(0, 138, 123, 0.95));
  }
}

/* Page Footer */
.page-footer {
  width: 100%;
  padding: 2rem 1.5rem 1.5rem;
  margin-top: 3rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

:root.light-theme .page-footer,
:root[data-theme="light"] .page-footer {
  border-top: 1px solid rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .page-footer {
    border-top: 1px solid rgba(0,0,0,0.08);
  }
}

.footer-content {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}

.page-footer .copyright {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 0.75rem 0;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.footer-links a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

.footer-links .separator {
  color: var(--muted);
  opacity: 0.5;
}

@media (max-width: 640px) {
  .page-footer {
    padding: 1rem 1rem 4.5rem;
    margin-top: 1rem;
  }
  
  .footer-links {
    font-size: 0.75rem;
    gap: 0.4rem;
  }
  
  .page-footer .copyright {
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
  }
}