:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1a1d29;
  --text-sub: #6b7280;
  --text-mute: #9ca3af;
  --primary: #6366f1;
  --primary-light: #eef0ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --border: #e5e7eb;
  --warmup: #fef3c7;
  --warmup-text: #92400e;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 80px;
  min-height: 100vh;
}

.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}

.header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header .date {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 4px;
}

.header-btn {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.header-btn:active { transform: scale(0.96); }

/* ===== Tab/badge ===== */
.tab-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 16px;
}
.tab-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
}

/* ===== Volume card ===== */
.volume-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.volume-card .label { font-size: 12px; color: var(--text-sub); margin-bottom: 4px; }
.volume-card .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.volume-card .value .unit { font-size: 14px; font-weight: 500; color: var(--text-sub); margin-left: 4px; }
.volume-card .compare { font-size: 12px; color: var(--text-mute); text-align: right; }
.volume-card .compare.positive { color: var(--success); font-weight: 600; }
.volume-card .compare.negative { color: #ef4444; font-weight: 600; }

/* ===== Exercise card ===== */
.exercise-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 12px;
}

.exercise-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.exercise-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.exercise-volume {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.exercise-volume .unit { font-size: 10px; color: var(--text-sub); margin-left: 2px; font-weight: 500; }
.exercise-volume.zero { color: var(--text-mute); }

.exercise-compare {
  font-size: 10px;
  color: var(--text-mute);
}
.exercise-compare.positive { color: var(--success); font-weight: 600; }
.exercise-compare.negative { color: #ef4444; font-weight: 600; }

.step-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}

/* ===== Set row ===== */
.set-row {
  margin-bottom: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #fafbfc;
  transition: all 0.2s;
}
.set-row.warmup { background: var(--warmup); }
.set-row.warmup .set-label { color: var(--warmup-text); }
.set-row.completed { background: var(--success-light); }
.set-row.completed .set-label { color: var(--success); }

.set-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.set-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}

.input-group { display: flex; flex-direction: column; gap: 4px; }
.input-group .input-label { font-size: 10px; color: var(--text-mute); padding-left: 4px; }

.stepper {
  display: flex;
  align-items: stretch;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.stepper button {
  background: transparent;
  border: none;
  width: 30px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  transition: background 0.1s;
}
.stepper button:active { background: var(--primary-light); }
.stepper input {
  flex: 1;
  border: none;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  background: transparent;
  width: 100%;
  min-width: 0;
  -moz-appearance: textfield;
  font-family: inherit;
  color: var(--text);
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; }

.complete-btn {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 0 14px;
  height: 38px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.complete-btn:active { transform: scale(0.96); }
.set-row.completed .complete-btn {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.add-set-btn {
  width: 100%;
  background: transparent;
  border: none;
  padding: 10px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  font-family: inherit;
}
.add-set-btn:active { background: var(--primary-light); border-radius: 8px; }

/* ===== Memo & condition ===== */
.bottom-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.bottom-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}
.condition-row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
  margin-bottom: 14px;
}
.condition-btn {
  flex: 1;
  padding: 10px 0;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.condition-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

textarea.memo {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  background: var(--card);
  color: var(--text);
}
textarea.memo:focus { outline: none; border-color: var(--primary); }

/* ===== Save bar ===== */
.save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  z-index: 100;
}
.save-bar .container { padding: 0; display: flex; gap: 8px; width: 100%; }
.save-btn {
  flex: 1;
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-md);
}
.save-btn:active { transform: scale(0.98); }
.save-btn.saved { background: var(--success); }

/* ===== History modal ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  overflow-y: auto;
}
.modal.open { display: block; }
.modal-content {
  background: var(--bg);
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 20px 16px 100px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-header h2 { font-size: 22px; font-weight: 700; }
.close-btn {
  background: var(--card);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  font-family: inherit;
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.history-actions button {
  flex: 1;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}
.history-actions button.danger { color: #ef4444; }

.history-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.history-item .date { font-size: 14px; font-weight: 700; }
.history-item .total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.history-item .total-volume {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}
.history-item .total-volume .unit { font-size: 11px; color: var(--text-sub); margin-left: 2px; font-weight: 500; }
.history-item .meta {
  font-size: 11px;
  color: var(--text-mute);
  display: flex;
  gap: 10px;
}
.history-item .meta strong { color: var(--text); font-weight: 600; }
.history-item .breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 12px;
}
.history-item .breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.history-item .breakdown-name { color: var(--text-sub); }
.history-item .breakdown-val { font-weight: 600; color: var(--text); }
.history-item .breakdown-val .unit { font-size: 10px; color: var(--text-mute); margin-left: 1px; font-weight: 400; }
.history-item .summary { font-size: 12px; color: var(--text-sub); margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

.empty {
  text-align: center;
  color: var(--text-mute);
  padding: 40px 20px;
  font-size: 14px;
}

/* ===== Chart ===== */
.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.chart-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.chart-tab {
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-sub);
}
.chart-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
canvas { max-width: 100%; height: 200px !important; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 29, 41, 0.95);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; }

/* ===== Editing banner ===== */
.editing-banner {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.editing-banner .text {
  font-size: 13px;
  color: #92400e;
  font-weight: 600;
}
.editing-banner .text .sub {
  font-size: 11px;
  font-weight: 400;
  color: #b45309;
  margin-top: 2px;
  display: block;
}
.editing-banner button {
  background: #f59e0b;
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.editing-banner button:active { transform: scale(0.96); }

/* ===== History item clickable ===== */
.history-item {
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.history-item:active {
  transform: scale(0.99);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* ===== app-workout で追加 ===== */
[hidden] { display: none !important; }

.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  font-family: inherit;
}
.login-error { color: #ef4444; font-size: 13px; }

.save-btn:disabled { opacity: 0.6; }

.set-label { justify-content: space-between; }
.remove-set-btn {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}

.pr-badge {
  display: inline-block;
  margin: 6px 0 0 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f59e0b;
  color: white;
  font-size: 10px;
  font-weight: 700;
}
.pr-tag {
  padding: 1px 5px;
  border-radius: 999px;
  background: #f59e0b;
  color: white;
  font-size: 9px;
  font-weight: 700;
}
.pr-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  font-size: 13px;
}
.pr-date { font-size: 10px; color: var(--text-mute); }

.delete-record-btn {
  width: 100%;
  background: transparent;
  border: none;
  padding: 10px;
  color: #ef4444;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.date-picker {
  display: block;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

/* ===== カレンダー ===== */
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.calendar-header h3 { margin: 0; }
.calendar-nav {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.calendar-nav:disabled { opacity: 0.35; cursor: default; }
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.calendar-head {
  text-align: center;
  font-size: 11px;
  color: var(--text-mute);
  padding: 2px 0;
}
.calendar-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 2px 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.calendar-day.has-record { background: var(--primary-light); color: var(--primary); }
.calendar-day.today { border-color: var(--primary); }
.calendar-day:disabled { color: var(--text-mute); opacity: 0.5; cursor: default; }
.calendar-mark { min-height: 13px; font-size: 10px; line-height: 13px; }
.calendar-legend { margin-top: 10px; font-size: 11px; color: var(--text-mute); }
.history-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; }

/* ===== 体の写真 ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.photo-grid:not(:empty) { margin-bottom: 8px; }
.photo-item { position: relative; aspect-ratio: 3 / 4; }
.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}
.photo-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.photo-status { font-size: 12px; color: var(--text-sub); }
.photo-status:empty { display: none; }
.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.9);
}
.photo-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
