:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #6366f1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --emerald: #059669;
  --emerald-hover: #047857;
  --emerald-light: #ecfdf5;
  --amber: #d97706;
  --amber-light: #fffbeb;
  --radius: 14px;
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  padding-bottom: 110px;
}

/* Sticky Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(79, 70, 229, 0.2);
}

.brand-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

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

.autosave-pill {
  font-size: 0.78rem;
  color: var(--emerald);
  background: var(--emerald-light);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-bar {
  width: 110px;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #10b981);
  width: 0%;
  transition: width 0.25s ease;
}

/* Main Container */
.container {
  max-width: 960px;
  margin: 1.75rem auto;
  padding: 0 1.25rem;
}

/* Hero Card */
.hero {
  background: linear-gradient(135deg, #ffffff 0%, #f5f7ff 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.hero-meta {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.hero h1 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.65rem;
}

.hero-lead {
  font-size: 1.02rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.rules-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.65rem;
}

.rule-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.rule-pill strong {
  color: var(--text);
}

/* Step Cards */
.step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.65rem 1.85rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  scroll-margin-top: 80px;
}

.step-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.step-title-group h2 {
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Step Timer */
.timer-box {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.timer-box.running {
  background: var(--amber-light);
  border-color: #fde68a;
  color: var(--amber);
}

.timer-box.done {
  background: var(--emerald-light);
  border-color: #a7f3d0;
  color: var(--emerald);
}

.timer-display {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 44px;
  text-align: center;
}

.timer-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.timer-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Form Elements */
.field-grid {
  display: grid;
  gap: 1rem;
}

.field-row {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0.85rem;
  align-items: start;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--surface-alt);
}

.field-row:last-child {
  border-bottom: none;
}

.field-label {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  padding-top: 0.45rem;
}

.field-label small {
  display: block;
  font-weight: 400;
  color: var(--text-subtle);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.input-with-helper {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-line {
  display: flex;
  gap: 0.45rem;
  align-items: flex-start;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.93rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.14);
}

textarea {
  resize: vertical;
  min-height: 62px;
}

.idk-btn {
  border: 1px dashed #cbd5e1;
  background: var(--surface-alt);
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.idk-btn:hover {
  background: #e2e8f0;
  color: var(--text);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 0.28rem 0.68rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.chip-btn:hover,
.chip-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Example & Live Preview Box */
.example-box {
  background: var(--surface-alt);
  border-left: 3px solid var(--primary);
  padding: 0.75rem 1rem;
  border-radius: 0 9px 9px 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.85rem;
}

.live-sentence-box {
  background: var(--primary-light);
  border: 1px solid rgba(79, 70, 229, 0.25);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin-top: 0.9rem;
  font-size: 0.95rem;
  color: var(--text);
}

.live-sentence-box strong {
  color: var(--primary);
}

/* Content Table (Stap 3 & Stap 5) */
.table-scroll {
  overflow-x: auto;
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.spec-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 660px;
}

.spec-table th,
.spec-table td {
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 0.86rem;
}

.spec-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
}

.spec-table tr.example-row td {
  background: #f8fafc;
  color: var(--text-subtle);
  font-style: italic;
}

.spec-table input {
  padding: 0.45rem 0.6rem;
  font-size: 0.86rem;
}

/* Flow Visual (Stap 4) */
.journey-banner {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.45rem;
  margin: 0.85rem 0 1.2rem;
}

.journey-node {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.55rem 0.5rem;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.journey-node.gate {
  background: var(--amber-light);
  border-color: #fcd34d;
  color: #b45309;
}

/* Checkboxes */
.checkbox-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.55rem;
  margin-top: 0.65rem;
}

.check-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
}

.check-card:hover {
  border-color: var(--primary);
  background: #fafaff;
}

.check-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Sketch Upload Box */
.sketch-upload-area {
  margin-top: 1rem;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 1rem 1.2rem;
  background: #f8fafc;
}

.sketch-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.sketch-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  font-size: 0.82rem;
}

.sketch-item img {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 5px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.15rem;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-success {
  background: var(--emerald);
  color: #fff;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.28);
}

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

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-alt);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

/* Sticky Bottom Action Bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 95;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
}

.bottom-bar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.bottom-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: #fff;
  border-radius: 16px;
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}

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

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
}

.md-preview {
  background: #0f172a;
  color: #f8fafc;
  padding: 1rem 1.15rem;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  max-height: 360px;
  overflow-y: auto;
  margin-top: 0.85rem;
}

.sync-banner {
  background: var(--emerald-light);
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
}

/* Responsive & Print */
@media (max-width: 720px) {
  .field-row {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .journey-banner {
    grid-template-columns: repeat(2, 1fr);
  }
  .step-card {
    padding: 1.2rem;
  }
}

@media print {
  .topbar,
  .bottom-bar,
  .timer-box,
  .idk-btn,
  .chip-row,
  .modal-backdrop {
    display: none !important;
  }
  body {
    background: #fff;
    padding-bottom: 0;
  }
  .step-card,
  .hero {
    box-shadow: none;
    border: 1px solid #cbd5e1;
    break-inside: avoid;
  }
}
