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

/* iOS safe area support */
html {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

:root {
  --bg: #0d0d0d;
  --text: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.5);
  --line: rgba(255, 255, 255, 0.3);
  --ball: #00E876;
  --ball-glow: rgba(0, 232, 118, 0.4);
  --panel-bg: #1a1a1a;
  --panel-border: rgba(255, 255, 255, 0.1);
  --btn-bg: rgba(255, 255, 255, 0.1);
  --btn-hover: rgba(255, 255, 255, 0.15);
  --btn-active: rgba(255, 255, 255, 0.2);

  --font-serif: "Iowan Old Style", "New York", "Sitka Text", Palatino, "Book Antiqua", "Noto Serif", "Roboto Serif", 'Georgia Pro', Georgia, 'Times New Roman', 'DejaVu Serif', 'Merriweather', serif;
  --font-sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --text: #1a1a1a;
  --text-muted: rgba(0, 0, 0, 0.5);
  --line: rgba(0, 0, 0, 0.2);
  --ball: #00E876;
  --ball-glow: rgba(0, 232, 118, 0.4);
  --panel-bg: #ffffff;
  --panel-border: rgba(0, 0, 0, 0.1);
  --btn-bg: rgba(0, 0, 0, 0.05);
  --btn-hover: rgba(0, 0, 0, 0.1);
  --btn-active: rgba(0, 0, 0, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100vw;
  transform: translateY(-5vh);
}

.instruction {
  font-size: 2.1rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  letter-spacing: 0.03em;
  margin-bottom: 1.0rem;
  opacity: 0;
  text-transform: lowercase;
  transition: opacity 0.5s ease;
  font-family: var(--font-sans);
}

.instruction.ready {
  opacity: 0.7;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.canvas-wrap.ready {
  opacity: 1;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  will-change: contents;
}

.ball {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  background: var(--ball);
  border-radius: 50%;
  box-shadow: 0 0 30px var(--ball-glow), 0 0 60px var(--ball-glow);
  z-index: 10;
  transition: background 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
  will-change: transform, top;
  opacity: 0;
}

.ball.ready {
  opacity: 1;
}

.pattern-label {
  display: none;
}

/* Play/Pause Button */
.play-pause-btn {
  position: fixed;
  top: calc(15px + env(safe-area-inset-top));
  right: calc(65px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.2s ease;
  z-index: 100;
  touch-action: manipulation;
}


.play-pause-btn svg {
  width: 26px;
  height: 26px;
}

.play-pause-btn .icon-play {
  display: none;
  margin-left: 11px; /* Optical adjustment - triangles look left-shifted */
}

.play-pause-btn.paused .icon-pause {
  display: none;
}

.play-pause-btn.paused .icon-play {
  display: block;
}

/* Settings Toggle */
.settings-toggle {
  position: fixed;
  top: calc(15px + env(safe-area-inset-top));
  right: calc(15px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.2s ease;
  z-index: 100;
  touch-action: manipulation;
}


.settings-toggle svg {
  width: 22px;
  height: 22px;
}

/* Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 200;
}

.overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: calc(5px + env(safe-area-inset-top));
  right: 0;
  bottom: calc(5px + env(safe-area-inset-bottom));
  width: 400px;
  max-width: 90vw;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 300;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.5rem 1.2rem;
  border-radius: 12px 0 0 12px;
}

.settings-panel.active {
  transform: translateX(0);
}

.settings-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--panel-border);
}

.settings-tab {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.2s ease, border-color 0.2s ease;
  touch-action: manipulation;
}

.settings-tab.active {
  color: var(--text);
  border-bottom-color: var(--ball);
}

.tab-content {
  display: block;
}

.tab-content.hidden {
  display: none;
}

.settings-close {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top));
  right: calc(1rem + env(safe-area-inset-right));
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--btn-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, background 0.2s ease, visibility 0.3s ease;
  z-index: 310;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.settings-close.active {
  opacity: 0.9;
  visibility: visible;
}


.settings-close svg {
  width: 18px;
  height: 18px;
}

.settings-section {
  margin-bottom: 2rem;
}

.settings-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  margin-bottom: 1rem;
}

/* Pattern List */
.pattern-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.pattern-cat {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  margin-top: 0.75rem;
  margin-bottom: 0.2rem;
  padding-left: 0.2rem;
}

.pattern-cat:first-child {
  margin-top: 0;
}

.pattern-btn {
  display: block;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  text-align: left;
  touch-action: manipulation;
}

.pattern-btn:hover {
  background: var(--btn-hover);
}

.pattern-btn.active {
  background: var(--btn-active);
  border-color: var(--ball);
}

.pattern-btn .pattern-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
}

.pattern-btn .pattern-name {
  font-size: 1rem;
  font-weight: 600;
}

.pattern-btn .pattern-timing {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  font-family: ui-monospace, monospace;
}

.pattern-btn .pattern-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Setting rows */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.setting-row label {
  font-size: 0.9rem;
}

.range-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.range-value {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 24px;
  text-align: right;
}

.setting-row input[type="range"] {
  width: 140px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--btn-bg);
  border-radius: 3px;
  cursor: pointer;
}

.setting-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
}

.setting-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.setting-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 40px;
  height: 32px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

.setting-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.setting-row input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}

.setting-row input[type="color"]::-moz-color-swatch {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}

.color-pair {
  display: flex;
  gap: 1rem;
}

.color-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.color-label {
  font-size: 0.75rem;
  opacity: 0.6;
}

/* Toggle Button */
.toggle-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.toggle-track {
  display: block;
  width: 44px;
  height: 26px;
  background: var(--btn-bg);
  border-radius: 13px;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s ease;
  opacity: 0.6;
}

.toggle-btn[aria-pressed="true"] .toggle-track {
  background: var(--ball);
}

.toggle-btn[aria-pressed="true"] .toggle-thumb {
  transform: translateX(18px);
  opacity: 1;
}

/* Select Dropdown */
.setting-row select {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  min-width: 120px;
}

.setting-row select:focus {
  outline: none;
  border-color: var(--ball);
}

/* Theme Switch */
.theme-switch {
  display: flex;
  background: var(--btn-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  gap: 0;
}

.theme-option {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  line-height: 1;
}

.theme-option:hover {
  background: var(--btn-hover);
  color: var(--text);
}

.theme-option.active {
  background: var(--btn-active);
  color: var(--text);
}

.theme-option svg {
  display: block;
  stroke: rgba(255, 255, 255, 0.5) !important;
}

.theme-option:hover svg,
.theme-option.active svg {
  stroke: #ffffff !important;
}

[data-theme="light"] .theme-option svg {
  stroke: rgba(0, 0, 0, 0.5) !important;
}

[data-theme="light"] .theme-option:hover svg,
[data-theme="light"] .theme-option.active svg {
  stroke: #1a1a1a !important;
}

/* Reset Button */
.settings-reset {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--panel-border);
}

.reset-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  touch-action: manipulation;
}

.reset-btn:active {
  background: var(--btn-hover);
  color: var(--text);
}

/* Quotes */
.quote-container {
  position: fixed;
  bottom: calc(30px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  padding: 0px 0px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.quote-container.ready {
  opacity: 1;
}

.quote {
  max-width: 600px;
  margin: 0 auto;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
  will-change: opacity, transform;
  cursor: pointer;
  pointer-events: auto;
}

.quote.fade-out {
  opacity: 0;
  transform: translateY(-8px);
}

.quote.fade-in {
  opacity: 0;
  transform: translateY(8px);
}

.quote-text {
  font-size: 1.1rem;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.42;
  margin-bottom: 0.7rem;
  font-family: var(--font-serif);
  font-family: var(--font-sans);
}

.quote-text::before {
  content: '"';
}

.quote-text::after {
  content: '"';
}

.quote-author {
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.quote-author::before {
  content: '— ';
}

@media (max-width: 600px) {
  .instruction {
    font-size: 2.3rem;
  }
  
  .ball {
    width: 32px;
    height: 32px;
  }
  
  .canvas-wrap {
    height: 250px;
  }
  
  .settings-panel {
    width: 100vw;
    max-width: 100vw;
  }
  
  .quote-container {
    bottom: calc(25px + env(safe-area-inset-bottom));
    padding: 0px 2rem;
  }
  
  .quote-text {
    font-size: 1.0rem;
    font-size: 0.93rem;
  }
  
  .quote-author {
    font-size: 0.75rem;
  }
}
