/* Dark theme (default) + font stacks */
:root {
  --font-content: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg: #1a1a1a;
  --text: #8FBF8F;
  --ui: #888;
  --ui-dim: #555;
  --ui-bg: #242424;
  --ui-border: #333;
  --swatch-ring: #fff;
  --accent: #8FBF8F;
  --accent-hover: #A5D5A5;
}

/* Light theme — bg updated from #F5F0E8 to #FDFCF9 (style guide warm snow) */
[data-theme="light"] {
  --bg: #FDFCF9;
  --ui: #6B6560;
  --ui-dim: #B5A99A;
  --ui-bg: #F7F5F0;
  --ui-border: #E6E2DC;
  --swatch-ring: #333;
  --accent: #4A6B4A;
  --accent-hover: #3A5A3A;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 16px env(safe-area-inset-bottom, 16px);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* Main container - card on all screen sizes */
.container {
  max-width: 500px;
  width: 100%;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 12px;
  padding: 24px;
}

/* Desktop: larger card, centered higher */
@media (min-width: 600px) {
  body {
    justify-content: flex-start;
    padding-top: 12vh;
  }
  .container {
    flex: none;
    padding: 48px;
  }
}

/* Header */
.header {
  margin-bottom: 48px;
}
.sonnet-title {
  font-family: var(--font-content);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--ui);
  font-style: italic;
  margin-bottom: 4px;
}
.progress {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--ui-dim);
  letter-spacing: 0.02em;
}

/* Poetry display */
.poetry {
  position: relative;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.line {
  font-family: var(--font-content);
  font-size: 1.8rem;
  line-height: 1.5;
  transition: opacity 0.6s ease;
}
.line.fade-out { opacity: 0; }
.line-number {
  position: absolute;
  bottom: 8px;
  right: 16px;
  font-size: 0.8rem;
  color: var(--ui-dim);
}

/* Buttons (shared base) */
.btn, .btn-small {
  background: none;
  border: 1.5px solid var(--ui);
  color: var(--ui);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.btn:hover, .btn-small:hover {
  background: var(--ui);
  color: var(--bg);
  border-color: var(--ui);
}
.btn.active {
  background: var(--ui);
  color: var(--bg);
  border-color: var(--ui);
}
.btn:focus, .btn-small:focus { outline: none; }
.btn:focus-visible, .btn-small:focus-visible {
  outline: 2px solid var(--ui);
  outline-offset: 3px;
}

/* Controls */
.controls {
  margin-top: auto;
  padding-top: 48px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
}
.btn {
  font-size: 1rem;
  padding: 10px 24px;
}

/* Settings panel */
.settings {
  display: none;
  flex-basis: 100%;
  margin-top: 24px;
  text-align: left;
}
.settings.open { display: block; }

/* iOS-style grouped sections */
.settings-section {
  background: var(--bg);
  border-radius: 10px;
  margin-bottom: 16px;
  overflow: hidden;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  min-height: 48px;
}
.setting-row:not(:last-child) {
  border-bottom: 1px solid var(--ui-border);
}
.setting-label {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--text);
}
.setting-row select,
.setting-row input[type="date"] {
  background: none;
  border: none;
  color: var(--ui);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  text-align: right;
  cursor: pointer;
}
.setting-row select:focus,
.setting-row input[type="date"]:focus {
  outline: none;
}

/* Color swatches */
.color-swatches {
  display: flex;
  gap: 8px;
}
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(128,128,128,0.3);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}
.swatch:hover { transform: scale(1.15); }
.swatch:focus-visible { outline: 2px solid var(--ui); outline-offset: 2px; }
.swatch.selected { border-color: var(--swatch-ring); }

/* Theme selector (segmented control) */
/* iOS-style segmented control */
.theme-options {
  display: flex;
  background: var(--ui-bg);
  border-radius: 8px;
  padding: 2px;
}
.theme-btn {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ui);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.theme-btn.active {
  background: var(--bg);
  color: var(--text);
}
.theme-btn:hover:not(.active) {
  color: var(--text);
}
.theme-btn:focus { outline: none; }
.theme-btn:focus-visible {
  outline: 2px solid var(--ui);
  outline-offset: 1px;
}

/* iOS-style toggle switch */
.toggle {
  position: relative;
  width: 50px;
  height: 30px;
  background: var(--ui-border);
  border-radius: 15px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle:focus-visible { outline: 2px solid var(--ui); outline-offset: 2px; }
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.on::after { transform: translateX(20px); }

.btn-small {
  font-size: 0.8rem;
  padding: 6px 12px;
}

/* Share button - full width, hidden on desktop */
.btn-share {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  background: none;
  border: 1.5px solid var(--ui-border);
  color: var(--ui);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.btn-share:hover {
  border-color: var(--ui);
  color: var(--text);
}
@media (min-width: 600px) {
  .btn-share { display: none; }
}

/* Review mode indicator */
.review-indicator {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--ui-dim);
  font-style: italic;
  margin-top: 8px;
  letter-spacing: 0.02em;
}

.review-progress {
  width: 120px;
  height: 3px;
  background: var(--ui-border);
  border-radius: 2px;
  margin: 12px auto 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s;
}

.review-progress.active {
  opacity: 1;
}

.review-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--text);
  transform-origin: left;
}

.review-progress.active .review-progress-bar {
  animation: countdown 5s linear forwards;
}

@keyframes countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Dot marker for line 1 in review */
.dot-marker {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text);
  margin-right: 8px;
  vertical-align: middle;
}

/* SEO sonnets (hidden when JS runs, visible in source for crawlers) */
.seo-sonnets { display: none; }

/* Responsive: small phones */
@media (max-width: 480px) {
  body { padding: 16px 16px env(safe-area-inset-bottom, 16px); }
  .line { font-size: 1.5rem; }
  .header { margin-bottom: 32px; }
  .controls { padding-top: 32px; }
  .settings { padding: 16px; width: calc(100vw - 32px); }
  .setting-row { flex-wrap: wrap; gap: 8px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .btn, .btn-small, .theme-btn, .toggle, .swatch, .line {
    transition: none;
  }
}
