/* ========== Base ========== */
:root {
  --bg: #0f0f12;
  --bg-card: #18181d;
  --bg-step: #1e1e24;
  --border: #2d2d35;
  --text: #e8e8ed;
  --text-muted: #9898a6;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #eab308;
  --tip-bg: rgba(59, 130, 246, 0.12);
  --warning-bg: rgba(234, 179, 8, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: calc(100vh - env(safe-area-inset-bottom, 0));
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; }

/* ========== App & Header ========== */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.header {
  position: relative;
  padding: 0.9rem 1rem 0.75rem;
  padding-right: 4.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-inner { max-width: 900px; margin: 0 auto; }

.header-actions {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.title {
  margin: 0 0 0.1em;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.subtitle {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.main {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
  .header { padding: 1.5rem 2rem 1.25rem; padding-right: 6rem; }
  .title { font-size: 1.5rem; }
  .subtitle { margin: 0 0 1rem; font-size: 0.9rem; }
  .header-actions { top: 1.5rem; right: 2rem; gap: 0.75rem; }
  .main { padding: 2rem; }
}

/* ========== Progress ========== */
.progress { margin-top: 0.35rem; }
@media (min-width: 768px) { .progress { margin-top: 0.5rem; } }

.progress-list {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}

.progress-item { display: flex; align-items: center; }

.progress-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

@media (min-width: 480px) {
  .progress-dot { width: 36px; height: 36px; }
}

.progress-dot:hover { border-color: var(--accent); color: var(--text); }
.progress-dot.active { border-color: var(--accent); background: var(--accent); color: white; }
.progress-dot.done { border-color: var(--success); background: var(--success); color: white; }
.progress-line { width: 20px; height: 2px; background: var(--border); margin: 0 2px; }
@media (min-width: 600px) { .progress-line { width: 28px; } }

/* ========== Language switcher ========== */
.lang-switcher { display: flex; align-items: center; gap: 0.25rem; }

.lang-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0 0.4rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.lang-btn:hover { color: var(--text); background: var(--border); }
.lang-btn.active { color: var(--accent); background: rgba(59, 130, 246, 0.15); }
.lang-sep { color: var(--border); font-size: 0.85rem; user-select: none; }
@media (min-width: 480px) { .lang-btn { min-width: 40px; min-height: 40px; } }

/* ========== Step view ========== */
.step-view {
  max-width: 920px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.step-view-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  padding-bottom: 0;
}

@media (max-width: 767px) {
  .step-view-inner { padding-bottom: 5.5rem; }
}

.step-header {
  padding: 1rem 1.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.step-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.step-title { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.3; }

.step-instruction-short { display: flex; flex-direction: column; gap: 0.75rem; }
.step-instruction-line { margin: 0; font-size: 1.05rem; line-height: 1.5; color: var(--text); }

.step-box {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.step-box-title { margin: 0 0 0.4rem; font-size: 0.85rem; font-weight: 600; }
.step-requirements { background: rgba(34, 197, 94, 0.08); border-color: rgba(34, 197, 94, 0.3); }
.step-requirements-inline ul { margin: 0; padding-left: 1.2rem; font-size: 0.9rem; }
.step-requirements-inline li { margin-bottom: 0.2rem; }

.step-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1rem 1.1rem;
}

@media (max-width: 767px) {
  .step-content { gap: 1rem; padding: 1rem 1rem 1.25rem; }
  .step-instruction-line { font-size: 1rem; }
}

.step-image-section { margin-top: 0.25rem; min-height: 0; }

.annotated-image-frame {
  position: relative;
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
  background: var(--bg-step);
  border: 1px solid var(--border);
  box-shadow: 0 6px 28px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.2), 0 0 0 1px rgba(255,255,255,0.06) inset;
}

.annotated-image-frame img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  vertical-align: top;
  object-fit: contain;
  background: var(--bg-step);
}

.annotated-image-caption {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.step-image-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.6rem;
  background: var(--bg-step);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.step-image-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.step-image-btn:hover { background: var(--border); border-color: var(--text-muted); }
.step-image-counter { font-size: 0.85rem; color: var(--text-muted); font-family: var(--font-mono); }

.step-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--border);
  background: var(--bg-step);
}

@media (max-width: 767px) {
  .step-footer-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    border-radius: 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.3);
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 0.5rem;
  }
  .step-footer-nav .btn { min-width: 0; flex: 1; max-width: 140px; }
  .step-footer-nav .btn-help { flex: 0 0 48px; max-width: 48px; }
}

.step-footer-spacer { flex: 1; }

.btn {
  min-height: 48px;
  min-width: 120px;
  padding: 0.75rem 1.35rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--text-muted); border: 2px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-help {
  min-width: 48px;
  width: 48px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.btn-help:hover { border-color: var(--accent); color: var(--accent); background: var(--tip-bg); }

@media (min-width: 768px) {
  .step-view-inner { padding-bottom: 0; }
  .step-header { padding: 1.25rem 1.5rem 0.5rem; }
  .step-title { font-size: 1.4rem; }
  .step-content {
    display: grid;
    grid-template-columns: 0.9fr 1.4fr;
    grid-template-areas: "instruction image";
    gap: 1.75rem;
    padding: 1.5rem;
    align-items: start;
  }
  .step-instruction-short { grid-area: instruction; position: sticky; top: 1rem; }
  .step-instruction-line { font-size: 1.1rem; }
  .step-image-section { grid-area: image; position: sticky; top: 1rem; margin-top: 0; }
}

@media (min-width: 900px) {
  .step-view { max-width: 1000px; }
  .step-content { grid-template-columns: 0.85fr 1.5fr; gap: 2rem; padding: 2rem; }
}

/* ========== Help modal ========== */
.step-help-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: stepHelpFadeIn 0.2s ease;
}

.step-help-backdrop[hidden] { display: none; }

@keyframes stepHelpFadeIn { from { opacity: 0; } to { opacity: 1; } }

.step-help-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: stepHelpSlideUp 0.25s ease;
}

@keyframes stepHelpSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.step-help-content .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.step-help-content .modal-title { margin: 0; font-size: 1.1rem; font-weight: 700; }

.step-help-content .modal-close {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.step-help-content .modal-close:hover { background: var(--border); color: var(--text); }

.step-help-body { padding: 1.25rem 1.5rem; overflow-y: auto; }
.step-help-block { margin-bottom: 1.25rem; }
.step-help-block:last-child { margin-bottom: 0; }
.step-help-label { margin: 0 0 0.5rem; font-size: 0.9rem; font-weight: 700; color: var(--text); }
.step-help-text { margin: 0; font-size: 0.9rem; line-height: 1.5; color: var(--text-muted); }
.step-help-list { margin: 0; padding-left: 1.25rem; font-size: 0.9rem; line-height: 1.5; color: var(--text-muted); }
.step-help-list li { margin-bottom: 0.35rem; }
.step-help-list-ol { list-style-type: decimal; }
.step-help-tips .step-help-label { color: var(--accent); }
.step-help-warning .step-help-label { color: var(--warning); }
