/* MyWorkout — OLED dark / energy orange design system */
:root {
  --bg: #050506;
  --surface: #131318;
  --surface-2: #1B1C23;
  --border: #26272F;
  --primary: #F97316;
  --primary-soft: rgba(249, 115, 22, 0.14);
  --secondary: #FB923C;
  --accent: #22C55E;
  --danger: #EF4444;
  --fg: #F8FAFC;
  --muted: #8B93A1;
  --radius: 14px;
  --font-display: "Barlow Condensed", "Microsoft JhengHei", sans-serif;
  --font-body: "Barlow", -apple-system, "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(5, 5, 6, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.top-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-accent {
  flex: 0 0 auto;
  width: 26px;
  height: 5px;
  margin-left: auto;
  background: var(--primary);
  border-radius: 3px;
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.55);
}

/* ---------- layout ---------- */
.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px 110px;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 26px 2px 10px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
}
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.section-label .sec-action {
  margin-left: auto;
}

/* ---------- cards / lists ---------- */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}
.card:active { transform: scale(0.985); }
.card:hover { border-color: rgba(249, 115, 22, 0.45); }
.card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.drag-handle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  color: var(--muted);
  cursor: grab;
  padding: 6px 2px;
  touch-action: none;
}
.drag-handle svg { width: 16px; height: 16px; }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { border-color: var(--primary); }

.card-main { flex: 1; min-width: 0; }
.card-title {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.card-sub {
  font-size: 13.5px;
  color: var(--muted);
  margin-top: 2px;
}
.card-sub .num {
  font-variant-numeric: tabular-nums;
  color: var(--secondary);
  font-weight: 600;
}

.chev { flex: 0 0 auto; color: var(--muted); }
.chev svg { width: 18px; height: 18px; }

/* ---------- buttons ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small { width: 38px; height: 38px; }
.icon-btn.small svg { width: 17px; height: 17px; }
.icon-btn.danger:hover { background: rgba(239, 68, 68, 0.12); color: var(--danger); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 22px;
  border: none;
  border-radius: 12px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.btn-primary {
  background: var(--primary);
  color: #100801;
  box-shadow: 0 4px 18px rgba(249, 115, 22, 0.35);
}
.btn-primary:hover { background: var(--secondary); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost {
  background: var(--surface-2);
  color: var(--fg);
}
.btn-ghost:hover { background: #23242c; }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.btn-block { width: 100%; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 45;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 18px;
  background: var(--primary);
  color: #100801;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(249, 115, 22, 0.45);
  transition: transform 0.15s ease, background 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { background: var(--secondary); }
.fab:active { transform: scale(0.92); }
.fab:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.fab svg { width: 24px; height: 24px; }

.hidden { display: none !important; }

/* ---------- quick log (signature) ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
}

.weight-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 4px 0 2px;
}
.weight-display .w-num {
  font-family: var(--font-display);
  font-size: 76px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  text-shadow: 0 0 24px rgba(249, 115, 22, 0.35);
}
.weight-display .w-unit {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 1px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 4px;
}
.slider-row .range-min, .slider-row .range-max {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: center;
}

input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 34px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--primary) var(--fill, 50%), var(--surface-2) var(--fill, 50%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--fg);
  border: 4px solid var(--primary);
  box-shadow: 0 0 14px rgba(249, 115, 22, 0.6);
}
input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
}
input[type="range"]::-moz-range-progress {
  height: 8px;
  border-radius: 4px;
  background: var(--primary);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--fg);
  border: 4px solid var(--primary);
  box-shadow: 0 0 14px rgba(249, 115, 22, 0.6);
}
input[type="range"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 6px; }

.stepper-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.stepper {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: center;
}
.stepper .st-label {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
}
.stepper .st-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
}
.stepper .st-value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 54px;
}
.st-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.st-btn:hover { background: var(--primary-soft); color: var(--primary); }
.st-btn:active { background: var(--primary); color: #100801; }
.st-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.fine-btns {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}
.fine-btn {
  min-width: 62px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.fine-btn:hover { border-color: var(--primary); color: var(--primary); }
.fine-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.log-meta-row { display: flex; gap: 12px; margin-top: 14px; }
.log-meta-row > * { flex: 1; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.field input[type="text"], .field input[type="url"], .field input[type="date"],
.field input[type="number"], .field select, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  transition: border-color 0.2s ease;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.field input[type="date"] { color-scheme: dark; }
.field .err { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* ---------- tabs (trend) ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  min-height: 42px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.tab.active {
  background: var(--primary);
  color: #100801;
}

.chart-wrap { position: relative; height: 240px; }

/* ---------- detail lists ---------- */
.row-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.row-item + .row-item { margin-top: 8px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; overflow-wrap: anywhere; }
.row-sub { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.step-no {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
}
.step-img { max-width: 100%; border-radius: 10px; margin-top: 8px; display: block; }

.setting-kv { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.setting-kv .k { color: var(--muted); font-size: 14px; }
.setting-kv .v {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--secondary);
}

.link-item { color: inherit; text-decoration: none; }
.link-item .row-title { color: var(--secondary); }
.link-item:hover { border-color: rgba(249, 115, 22, 0.45); }

.log-history .row-title { font-variant-numeric: tabular-nums; }
.log-history .w { color: var(--primary); font-weight: 600; }

/* ---------- empty state ---------- */
.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty .empty-title {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 1px;
  color: var(--fg);
  margin-bottom: 4px;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.18s ease;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  animation: slideUp 0.22s ease-out;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(28px); opacity: 0.6; } }

/* ---------- toast ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 11px 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.22s ease-out;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.5); color: #86EFAC; }
.toast.err { border-color: rgba(239, 68, 68, 0.5); color: #FCA5A5; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }

/* ---------- misc ---------- */
.note-text { font-size: 13.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
