:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #ccfbf1;
  --danger: #dc2626;
  --warn: #b45309;
  --radius: 14px;
  --appbar-h: 52px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 17px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

/* ---- App bar ---- */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; gap: 8px;
  padding-left: 10px; padding-right: 14px;
  background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.appbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.appbar .spacer { flex: 1; }
.iconbtn {
  border: none; background: transparent; color: var(--brand-ink);
  font-size: 30px; line-height: 1; width: 40px; height: 40px;
  border-radius: 10px; cursor: pointer;
}
.iconbtn:active { background: rgba(255,255,255,.18); }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,.2); }
.badge.off { background: var(--warn); }

/* ---- View ---- */
.view {
  padding: calc(var(--appbar-h) + var(--safe-top) + 12px) 14px calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  max-width: 820px; margin: 0 auto;
}

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab .ic { font-size: 22px; }
.tab.active { color: var(--brand); }

/* ---- Cards & lists ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.list { list-style: none; margin: 0; padding: 0; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.row:active { background: #f0fdfa; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; font-size: 17px; }
.row .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row .chev { color: #c7cdd4; font-size: 26px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto;
}

.section-title { font-size: 13px; color: var(--muted); font-weight: 700; margin: 18px 2px 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .big { font-size: 40px; }

/* ---- Forms ---- */
label.field { display: block; margin-bottom: 14px; }
label.field .lab { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
input[type=text], input[type=date], input[type=number], select, textarea {
  width: 100%; font-size: 17px; font-family: inherit; color: var(--ink);
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; font-weight: 600; font-family: inherit;
  padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.block { display: flex; width: 100%; }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.small { padding: 7px 10px; font-size: 14px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); z-index: 15;
  background: var(--brand); color: #fff; border: none; border-radius: 999px;
  height: 56px; padding: 0 22px; font-size: 16px; font-weight: 700; box-shadow: 0 4px 14px rgba(15,118,110,.4);
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; }
.btnrow .btn { flex: 1; }

/* ---- Search ---- */
.search { position: relative; margin-bottom: 14px; }
.search input { padding-left: 40px; }
.search::before { content: "🔍"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); opacity: .5; }

/* ---- Exercise editor ---- */
.exercise { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; background: #fff; }
.exercise .exhead { display: flex; gap: 8px; align-items: flex-end; }
.exercise .exhead .field { flex: 1; margin-bottom: 8px; }
.sets { margin-top: 6px; }
.setrow { display: grid; grid-template-columns: 34px 1fr 1fr 1fr 34px; gap: 6px; align-items: center; margin-bottom: 6px; }
.setrow .no { text-align: center; color: var(--muted); font-weight: 700; font-size: 14px; }
.setrow input { padding: 8px; font-size: 15px; text-align: center; }
.setrow .del { color: var(--danger); background: transparent; border: none; font-size: 20px; cursor: pointer; }
.setlabels { display: grid; grid-template-columns: 34px 1fr 1fr 1fr 34px; gap: 6px; font-size: 11px; color: var(--muted); margin-bottom: 2px; padding: 0 2px; text-align: center; }

/* ---- Voice ---- */
.voicewrap { position: relative; }
.micbtn {
  position: absolute; right: 8px; bottom: 8px; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.micbtn.rec { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(220,38,38,.5);} 50%{ box-shadow: 0 0 0 8px rgba(220,38,38,0);} }

/* ---- Pills / tags ---- */
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.pill.gray { background: #eef0f2; color: var(--muted); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px); z-index: 50;
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); max-width: 90%;
}

.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.muted { color: var(--muted); }
.mini { font-size: 12px; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
