:root {
  --color-text-primary: #1a1a1a;
  --color-text-secondary: #4a4a4a;
  --color-text-tertiary: #8a8a8a;
  --color-border-tertiary: #d8d8d8;
  --color-background-primary: #ffffff;
  --color-background-secondary: #f1f1f1;
  --border-radius-md: 6px;
  --border-radius-lg: 10px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

:root[data-theme="dark"] {
  --color-text-primary: #e8e8e8;
  --color-text-secondary: #b4b4b4;
  --color-text-tertiary: #808080;
  --color-border-tertiary: #3a3a3a;
  --color-background-primary: #242424;
  --color-background-secondary: #161616;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

/* ---- Script / checklist page ---- */

.script {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 5rem;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text-primary);
  cursor: grab;
}

.page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.back-link {
  font-size: 12px;
  color: var(--color-text-tertiary);
  text-decoration: none;
}

.back-link:hover { color: var(--color-text-secondary); }

.theme-toggle {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border-tertiary);
  background: var(--color-background-primary);
  color: var(--color-text-secondary);
  border-radius: var(--border-radius-md);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.theme-toggle:hover { border-color: #2563EB; }

.script-heading {
  margin: 0 0 1rem;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-text-primary);
}

.section {
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-lg);
  margin-bottom: 0.6rem;
  background: var(--color-background-primary);
  overflow: hidden;
  transition: opacity 0.3s ease;
}

.section.done {
  opacity: 0.5;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: #2563EB;
  padding: 12px 12px;
}

.section-title {
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.font-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.font-btn {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: transparent;
  color: #ffffff;
  border-radius: var(--border-radius-md);
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
}

.font-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.font-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 1rem 0.85rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--color-border-tertiary);
}

.check-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: #1D9E75;
  flex-shrink: 0;
}

.check-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
}

.check-label.done {
  color: #1D9E75;
  text-decoration: line-through;
}

.script-body {
  font-size: var(--script-font-size, 14px);
  color: var(--color-text-primary);
  padding: 0.85rem 1rem 0.6rem;
}

.script-body p {
  margin: 0.35rem 0;
}

.beat {
  display: inline-block;
  background: #E3EBFF;
  border-radius: var(--border-radius-md);
  font-size: 0.95em;
  font-weight: 700;
  color: #1E40AF;
  padding: 1px 8px;
}

.coupon {
  display: inline-block;
  background: #EAF3DE;
  color: #3B6D11;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: var(--border-radius-md);
  border: 1px solid #C0DD97;
}

.cmd {
  display: block;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--color-text-primary);
  padding: 7px 10px;
  margin: 0.5rem 0;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}

.inline-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: 4px;
  padding: 0 4px;
  user-select: text;
}

.pending {
  display: inline-block;
  background: #FBEBC8;
  color: #8A5A00;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: var(--border-radius-md);
  border: 1px solid #E6C77A;
}

/* ---- Bullet lists ---- */

.script-body ul {
  margin: 0.7rem 0;
  padding: 0;
  list-style: none;
}

.bullets li {
  position: relative;
  padding-left: 1.25rem;
  margin: 0.7rem 0;
  line-height: 1.65;
}

.bullets li::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 0.55em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2563EB;
}

/* ---- Numbered steps ---- */

.steps li {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 0.55rem 0;
  padding-left: 0;
}

.step-tag {
  flex-shrink: 0;
  display: inline-block;
  background: #2563EB;
  color: #ffffff;
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---- Sticky bottom progress bar ---- */

.progress-sticky {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-background-primary);
  border-top: 1px solid var(--color-border-tertiary);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
  z-index: 50;
}

.progress-sticky-inner {
  max-width: 640px;
  margin: 0 auto;
}

.progress-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin: 0 0 0.4rem;
}

.progress-bar-wrap {
  background: var(--color-background-secondary);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 6px;
  background: #1D9E75;
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ---- Index page ---- */

.index {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.index-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.index-sub {
  font-size: 13px;
  color: var(--color-text-tertiary);
  margin: 0 0 1.25rem;
}

.card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-lg);
  background: var(--color-background-primary);
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  border-color: #1D9E75;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.card-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: var(--border-radius-md);
}

.card-body { flex: 1; min-width: 0; }

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 2px;
}

.card-desc {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin: 0;
}

.card-arrow {
  font-size: 18px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
}

/* ---- Mobile ---- */

@media (max-width: 600px) {
  .script { padding: 0.75rem 0.75rem 5rem; }
  .script-body { padding: 0.8rem 0.85rem 0.6rem; }
  .check-row { margin: 0 0.85rem 0.8rem; }
  .index { padding: 1.5rem 0.875rem; }
}
